seq2seq icon indicating copy to clipboard operation
seq2seq copied to clipboard

AttentionSeq2Seq error

Open xpertasks opened this issue 8 years ago • 6 comments

The example given in the readme is not working. Any ideas?

model = AttentionSeq2Seq(input_dim=5, input_length=7, hidden_dim=10, output_length=8, output_dim=20, depth=4)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/user1/src/seq2seq/seq2seq/models.py", line 283, in AttentionSeq2Seq
    decoded = decoder(encoded)
  File "/home/user1/src/recurrentshop/recurrentshop/engine.py", line 566, in __call__
    self.add_inbound_node(inbound_layers, node_indices, tensor_indices)
  File "/home/user1/src/keras/keras/engine/topology.py", line 635, in add_inbound_node
    Node.create_node(self, inbound_layers, node_indices, tensor_indices)
  File "/home/user1/src/keras/keras/engine/topology.py", line 166, in create_node
    output_tensors = to_list(outbound_layer.call(input_tensors[0], mask=input_masks[0]))
  File "/home/user1/src/recurrentshop/recurrentshop/engine.py", line 320, in call
    initial_states = self.get_initial_states(x)
  File "/home/user1/src/recurrentshop/recurrentshop/engine.py", line 388, in get_initial_states
    input = layer._step(input, layer_initial_states)[0]
  File "/home/user1/src/recurrentshop/recurrentshop/engine.py", line 116, in _step
    return self.step(*args)
  File "/home/user1/src/seq2seq/seq2seq/cells.py", line 85, in step
    x = K.batch_dot(energy, H, axes=(1, 1))
  File "/home/user1/src/keras/keras/backend/tensorflow_backend.py", line 874, in batch_dot
    raise ValueError('Invalid dimensions for batch_dot: ', ndim(x), ndim(y))
ValueError: ('Invalid dimensions for batch_dot: ', 2, 3)

xpertasks avatar Feb 03 '17 14:02 xpertasks

I also find this problem.

hhjjxx1989 avatar Feb 07 '17 06:02 hhjjxx1989

same problem. I add an embedding layer before the AttentionSeq2seq layer. Here is my code: model = Sequential() model.add(Embedding(max_features, embedding_vector_dim, input_length=max_doc_length)) model.add(AttentionSeq2Seq(input_length=max_doc_length, input_dim=embedding_vector_dim, hidden_dim=hidden_dim, output_length=max_doc_length, output_dim=embedding_vector_dim)) model.compile(loss='mse', optimizer='adam')

yangqinj avatar Feb 17 '17 03:02 yangqinj

Same problem... Here is the code. from seq2seq.models import AttentionSeq2Seq

samples = 30 input_length = 30 input_dim = 30 output_length = 30 output_dim = 30

x = np.random.random((samples, input_length, input_dim))

y = np.random.random((samples, output_length, output_dim)) models = AttentionSeq2Seq(output_dim=output_dim, output_length=output_length, input_shape=(input_length, input_dim))

fighting41love avatar Feb 23 '17 15:02 fighting41love

For me attentionSeq2Seq works with theano Backend but not with tensorflow backend. Reason is that batch_dot in tensorflow must be used with at least 3d Tensors https://github.com/fchollet/keras/issues/4588. You can change backend in ~/.keras/keras.json. Maybe someone can provide a fix for tensorflow backend.

smodlich avatar Mar 05 '17 17:03 smodlich

@smodlich Thanks! Theano backend works. Problem solved.

fighting41love avatar Mar 05 '17 17:03 fighting41love

Is this able to be fixed?

jjery2243542 avatar Mar 24 '17 18:03 jjery2243542