【问题标题】:TypeError when accessing RNN results访问 RNN 结果时出现 TypeError
【发布时间】:2017-05-15 22:19:43
【问题描述】:

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

任何帮助将不胜感激!

代码:

# 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'>

【问题讨论】:

    标签: theano theano.scan


    【解决方案1】:

    在那之后你对“all_tokens_output_vector”做了什么?你直接打印?

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

    【讨论】:

    • 我有一个只编译第一个扫描函数的函数。有没有办法连接函数,如果 F1 编译一个扫描操作,那么在完成后,第二个函数 F2 使用输出来编译第二个扫描操作?
    • 您可以通过向函数添加一个输出来获得此行为。喜欢:result_function = theano.function([required inputs], [hidden_vector, all_tokens_output_vector])
    猜你喜欢
    • 1970-01-01
    • 2016-05-25
    • 1970-01-01
    • 1970-01-01
    • 2016-07-23
    • 2013-06-05
    • 2015-11-20
    • 1970-01-01
    • 2014-05-31
    相关资源
    最近更新 更多