访问 RNN 结果时出现 TypeError

TypeError when accessing RNN results

我正在尝试为序列中的所有标记提取 RNN 的决策,但收到 post 末尾提到的错误。

任何帮助将不胜感激!

代码:

# gated recurrent unit
def gru_step(x, h_prev, W_xm, W_hm, W_xh, W_hh):
    m = theano.tensor.nnet.sigmoid(theano.tensor.dot(x, W_xm) + theano.tensor.dot(h_prev, W_hm))
    r = _slice(m, 0, 2)
    z = _slice(m, 1, 2)
_h = theano.tensor.tanh(theano.tensor.dot(x, W_xh) + theano.tensor.dot(r * h_prev, W_hh))
    h = z * h_prev + (1.0 - z) * _h
    return h
    # return h, theano.scan_module.until(previous_power*2 > max_value)

W_xm = self.create_parameter_matrix('W_xm', (word_embedding_size, recurrent_size*2))
W_hm = self.create_parameter_matrix('W_hm', (recurrent_size, recurrent_size*2))
W_xh = self.create_parameter_matrix('W_xh', (word_embedding_size, recurrent_size))
W_hh = self.create_parameter_matrix('W_hh', (recurrent_size, recurrent_size))
initial_hidden_vector = theano.tensor.alloc(numpy.array(0, dtype=floatX), recurrent_size)
initial_process_vector = theano.tensor.alloc(recurrent_size, n_classes)

hidden_vector, _ = theano.scan(
gru_step,
sequences = input_vectors,
outputs_info = initial_hidden_vector,
non_sequences = [W_xm, W_hm, W_xh, W_hh]
)

W_output = self.create_parameter_matrix('W_output', (n_classes,recurrent_size))

rnn_output = theano.tensor.nnet.softmax([theano.tensor.dot(W_output, hidden_vector[-1])])[0]
rnn+predicted_class = theano.tensor.argmax(output)

# Process hidden_vector to decision vectors
def process_hidden_vector(x, W_dot):
    return theano.tensor.dot(W_dot, x)

all_tokens_output_vector = theano.scan(process_hidden_vector, sequences=hidden_vector, non_sequences=W_output)

结果应该是 "all_tokens_output_vector",但我在尝试输出时遇到以下错误:

TypeError: Outputs must be theano Variable or Out instances. Received (for{cpu,scan_fn}.0, OrderedUpdates()) of type <type 'tuple'>

在那之后你用 "all_tokens_output_vector" 做什么?你直接打印出来?

应该有一个theano.function来编译图