2017-01-01 4 views
0

シーケンスのすべてのトークンに対してRNNの決定を抽出しようとしていますが、投稿の最後に記載されているエラーが表示されます。RNN結果にアクセスするときのTypeError

ご協力いただければ幸いです!

コード:

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

答えて

1

あなたは後に「all_tokens_output_vector」で何をしていますそれ?あなたはそれを直接印刷しますか?

グラフをコンパイルするには、theano.functionが必要です。

+0

私は最初のスキャン機能だけをコンパイルする機能を持っています。 F1が1回のスキャン操作をコンパイルすると、完了すると2回目の関数F2が出力を使用して2回目のスキャン操作をコンパイルするような関数を連結する方法はありますか? – ginge

+1

この動作を得るには、関数に出力を1つ追加します。同様に: 'result_function = theano.function([必須入力]、[hidden_​​vector、all_tokens_output_vector])' – gntoni

関連する問題