farizrahman4u / seq2seq

Sequence to Sequence Learning with Keras
GNU General Public License v2.0
3.17k stars 845 forks source link

A Error running example. #208

Open bughunter99 opened 7 years ago

bughunter99 commented 7 years ago

Hi, I wanted to run the sample script, so I download the sample source and ran it. But it didn't work and showed error like below.

May I know why this happened? Thanks

from seq2seq import SimpleSeq2Seq, Seq2Seq, AttentionSeq2Seq
import numpy as np
from keras.utils.test_utils import keras_test

input_length = 5
input_dim = 3

output_length = 3
output_dim = 4

samples = 100
hidden_dim = 24

x = np.random.random((samples, input_length, input_dim))
y = np.random.random((samples, output_length, output_dim))

models = []
models += [Seq2Seq(output_dim=output_dim, hidden_dim=hidden_dim, output_length=output_length, input_shape=(input_length, input_dim))]
models += [Seq2Seq(output_dim=output_dim, hidden_dim=hidden_dim, output_length=output_length, input_shape=(input_length, input_dim), peek=True)]
models += [Seq2Seq(output_dim=output_dim, hidden_dim=hidden_dim, output_length=output_length, input_shape=(input_length, input_dim), depth=2)]
models += [Seq2Seq(output_dim=output_dim, hidden_dim=hidden_dim, output_length=output_length, input_shape=(input_length, input_dim), peek=True, depth=2)]

for model in models:
    model.compile(loss='mse', optimizer='sgd')
    model.fit(x, y, epochs=1)

model = Seq2Seq(output_dim=output_dim, hidden_dim=hidden_dim, output_length=output_length, input_shape=(input_length, input_dim), peek=True, depth=2, teacher_force=True)
model.compile(loss='mse', optimizer='sgd')
model.fit([x, y], y, epochs=1)

Using TensorFlow backend. Epoch 1/1 2017-08-02 17:02:37.324921: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.1 instructions, but these are available on your machine and could speed up CPU computations. 2017-08-02 17:02:37.324961: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.2 instructions, but these are available on your machine and could speed up CPU computations. 2017-08-02 17:02:37.324969: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use AVX instructions, but these are available on your machine and could speed up CPU computations.

32/100 [========>.....................] - ETA: 1s - loss: 0.3257 100/100 [==============================] - 0s - loss: 0.3392
Epoch 1/1

32/100 [========>.....................] - ETA: 0s - loss: 0.3615 100/100 [==============================] - 0s - loss: 0.3489
Epoch 1/1

32/100 [========>.....................] - ETA: 1s - loss: 0.3357 100/100 [==============================] - 0s - loss: 0.3457
Epoch 1/1

32/100 [========>.....................] - ETA: 1s - loss: 0.3303 100/100 [==============================] - 0s - loss: 0.3447
Epoch 1/1 Traceback (most recent call last): File "/home/a/workspace/test/nmt/nmt4_seq2seq/test01.py", line 67, in test_Seq2Seq() File "/home/a/download/src/keras/keras/utils/test_utils.py", line 157, in wrapper output = func(*args, kwargs) File "/home/a/workspace/test/nmt/nmt4_seq2seq/test01.py", line 47, in test_Seq2Seq model.fit([x, y], y, epochs=1) File "/home/a/download/src/keras/keras/engine/training.py", line 1457, in fit initial_epoch=initial_epoch) File "/home/a/download/src/keras/keras/engine/training.py", line 1106, in _fit_loop outs = f(ins_batch) File "/home/a/download/src/keras/keras/backend/tensorflow_backend.py", line 2265, in call session = get_session() File "/home/a/download/src/keras/keras/backend/tensorflow_backend.py", line 168, in get_session _initialize_variables() File "/home/a/download/src/keras/keras/backend/tensorflow_backend.py", line 341, in _initialize_variables sess.run(tf.variables_initializer(uninitialized_variables)) File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/client/session.py", line 789, in run run_metadata_ptr) File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/client/session.py", line 997, in _run feed_dict_string, options, run_metadata) File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/client/session.py", line 1132, in _do_run target_list, options, run_metadata) File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/client/session.py", line 1152, in _do_call raise type(e)(node_def, op, message) tensorflow.python.framework.errors_impl.InvalidArgumentError: The node 'recurrent_sequential_10/while_1/Variable_1/Assign' has inputs from different frames. The input 'recurrent_sequential_10/while_1/Const_1' is in frame 'recurrent_sequential_10/while_1/recurrent_sequential_10/while_1/'. The input 'recurrent_sequential_10/while_1/Variable_1' is in frame ''.**