我正在使用https://github.com/thushv89/attention_keras/blob/master/layers/attention.py中的关注层,并且正在使用我的代码
encoder_input = Input(shape=(max_length,), dtype='int32', name='e_input')
x1=Embedding(vocab_size, 300, weights=[input_matrix],trainable=False)(encoder_input)
e_lstm_out, e_hidden_out, e_cell_out = LSTM(32,return_sequences=True,return_state=True,dropout=0.4,recurrent_dropout=0.4)(x1)
decoder_input = Input(shape=(None,))
x2 = Embedding(y_vocab_size, 300,trainable=False)(decoder_input)
d_lstm_out,d_hidden_out,d_cell_out = LSTM(32, return_sequences=True, return_state=True)(x2,initial_state=[hidden_out, cell_out])
attn_out, attn_states = AttentionLayer(name='attention_layer')([e_lstm_out, d_lstm_out])
我遇到一个错误。
TypeError Traceback (most recent call last)
/usr/local/lib/python3.6/dist-packages/tensorflow/python/framework/tensor_util.py in make_tensor_proto(values, dtype, shape, verify_shape)
526 try:
--> 527 str_values = [compat.as_bytes(x) for x in proto_values]
528 except TypeError:
13 frames
TypeError: Expected binary or unicode string, got 1
During handling of the above exception, another exception occurred:
TypeError Traceback (most recent call last)
/usr/local/lib/python3.6/dist-packages/tensorflow/python/framework /tensor_util.py in make_tensor_proto(values, dtype, shape, verify_shape)
529 raise TypeError("Failed to convert object of type %s to Tensor. "
530 "Contents: %s. Consider casting elements to a "
--> 531 "supported type." % (type(values), values))
532 tensor_proto.string_val.extend(str_values)
533 return tensor_proto
TypeError: Failed to convert object of type <class 'list'> to Tensor. Contents: [1, Dimension(None)]. Consider casting elements to a supported type.