models icon indicating copy to clipboard operation
models copied to clipboard

Seq2Seq Tutorial does not work

Open jmoney4769 opened this issue 9 years ago • 9 comments

System information

  • What is the top-level directory of the model you are using: I am using the models from models/tutorials/rnn/translate
  • Have I written custom code (as opposed to using a stock example script provided in TensorFlow): No changes to the code but I did change the file name (added a "_tf" to the end).
  • OS Platform and Distribution (e.g., Linux Ubuntu 16.04): Mac OSX 10.12.5
  • TensorFlow installed from (source or binary): I have tried both
  • TensorFlow version (use command below): PIP package: ('v1.2.0-rc2-21-g12f033d', '1.2.0') Built from source: ('v1.2.0-rc0-735-gf48673b', '1.2.0-rc1')
  • Bazel version (if compiling from source): 0.5.1-homebrew
  • Exact command to reproduce: python translate.py

Describe the problem

Hello,

This issue echoes the SO question at https://stackoverflow.com/questions/44685461/tensorflow-seq2seq-tutorial-nonetype-object-has-no-attribute-update

Basically I am trying to run the tutorial from https://www.tensorflow.org/tutorials/seq2seq which looks like documentation for the current version of tensorflow.

Running python translate.py produces the following error:


Traceback (most recent call last):
  File "/Users/<username>/PycharmProjects/tensorflow_chatbot/execute.py", line 334, in <module>
    train()
  File "/Users/<username>/PycharmProjects/tensorflow_chatbot/execute.py", line 151, in train
    model = create_model(sess, False)
  File "/Users/<username>/PycharmProjects/tensorflow_chatbot/execute.py", line 113, in create_model
    forward_only=forward_only)
  File "/Users/<username>/PycharmProjects/tensorflow_chatbot/seq2seq_model_tf.py", line 181, in __init__
    softmax_loss_function=softmax_loss_function)
  File "/Users/<username>/anaconda/envs/tensorflow_source_gpu/lib/python2.7/site-packages/tensorflow/contrib/legacy_seq2seq/python/ops/seq2seq.py", line 1206, in model_with_buckets
    decoder_inputs[:bucket[1]])
  File "/Users/<username>/PycharmProjects/tensorflow_chatbot/seq2seq_model_tf.py", line 180, in <lambda>
    lambda x, y: seq2seq_f(x, y, False),
  File "/Users/<username>/PycharmProjects/tensorflow_chatbot/seq2seq_model_tf.py", line 144, in seq2seq_f
    dtype=dtype)
  File "/Users/<username>/anaconda/envs/tensorflow_source_gpu/lib/python2.7/site-packages/tensorflow/contrib/legacy_seq2seq/python/ops/seq2seq.py", line 848, in embedding_attention_seq2seq
    encoder_cell = copy.deepcopy(cell)
  File "/Users/<username>/anaconda/envs/tensorflow_source_gpu/lib/python2.7/copy.py", line 174, in deepcopy
    y = copier(memo)
  File "/Users/<username>/anaconda/envs/tensorflow_source_gpu/lib/python2.7/site-packages/tensorflow/python/layers/base.py", line 476, in __deepcopy__
    setattr(result, k, copy.deepcopy(v, memo))
  File "/Users/<username>/anaconda/envs/tensorflow_source_gpu/lib/python2.7/copy.py", line 163, in deepcopy
    y = copier(x, memo)
  File "/Users/<username>/anaconda/envs/tensorflow_source_gpu/lib/python2.7/copy.py", line 230, in _deepcopy_list
    y.append(deepcopy(a, memo))
  File "/Users/<username>/anaconda/envs/tensorflow_source_gpu/lib/python2.7/copy.py", line 190, in deepcopy
    y = _reconstruct(x, rv, 1, memo)
  File "/Users/<username>/anaconda/envs/tensorflow_source_gpu/lib/python2.7/copy.py", line 334, in _reconstruct
    state = deepcopy(state, memo)
  File "/Users/<username>/anaconda/envs/tensorflow_source_gpu/lib/python2.7/copy.py", line 163, in deepcopy
    y = copier(x, memo)
  File "/Users/<username>/anaconda/envs/tensorflow_source_gpu/lib/python2.7/copy.py", line 257, in _deepcopy_dict
    y[deepcopy(key, memo)] = deepcopy(value, memo)
  File "/Users/<username>/anaconda/envs/tensorflow_source_gpu/lib/python2.7/copy.py", line 190, in deepcopy
    y = _reconstruct(x, rv, 1, memo)
  File "/Users/<username>/anaconda/envs/tensorflow_source_gpu/lib/python2.7/copy.py", line 334, in _reconstruct
    state = deepcopy(state, memo)
  File "/Users/<username>/anaconda/envs/tensorflow_source_gpu/lib/python2.7/copy.py", line 163, in deepcopy
    y = copier(x, memo)
  File "/Users/<username>/anaconda/envs/tensorflow_source_gpu/lib/python2.7/copy.py", line 257, in _deepcopy_dict
    y[deepcopy(key, memo)] = deepcopy(value, memo)
  File "/Users/<username>/anaconda/envs/tensorflow_source_gpu/lib/python2.7/copy.py", line 190, in deepcopy
    y = _reconstruct(x, rv, 1, memo)
  File "/Users/<username>/anaconda/envs/tensorflow_source_gpu/lib/python2.7/copy.py", line 334, in _reconstruct
    state = deepcopy(state, memo)
  File "/Users/<username>/anaconda/envs/tensorflow_source_gpu/lib/python2.7/copy.py", line 163, in deepcopy
    y = copier(x, memo)
  File "/Users/<username>/anaconda/envs/tensorflow_source_gpu/lib/python2.7/copy.py", line 257, in _deepcopy_dict
    y[deepcopy(key, memo)] = deepcopy(value, memo)
  File "/Users/<username>/anaconda/envs/tensorflow_source_gpu/lib/python2.7/copy.py", line 190, in deepcopy
    y = _reconstruct(x, rv, 1, memo)
  File "/Users/<username>/anaconda/envs/tensorflow_source_gpu/lib/python2.7/copy.py", line 334, in _reconstruct
    state = deepcopy(state, memo)
  File "/Users/<username>/anaconda/envs/tensorflow_source_gpu/lib/python2.7/copy.py", line 163, in deepcopy
    y = copier(x, memo)
  File "/Users/<username>/anaconda/envs/tensorflow_source_gpu/lib/python2.7/copy.py", line 257, in _deepcopy_dict
    y[deepcopy(key, memo)] = deepcopy(value, memo)
  File "/Users/<username>/anaconda/envs/tensorflow_source_gpu/lib/python2.7/copy.py", line 163, in deepcopy
    y = copier(x, memo)
  File "/Users/<username>/anaconda/envs/tensorflow_source_gpu/lib/python2.7/copy.py", line 257, in _deepcopy_dict
    y[deepcopy(key, memo)] = deepcopy(value, memo)
  File "/Users/<username>/anaconda/envs/tensorflow_source_gpu/lib/python2.7/copy.py", line 163, in deepcopy
    y = copier(x, memo)
  File "/Users/<username>/anaconda/envs/tensorflow_source_gpu/lib/python2.7/copy.py", line 230, in _deepcopy_list
    y.append(deepcopy(a, memo))
  File "/Users/<username>/anaconda/envs/tensorflow_source_gpu/lib/python2.7/copy.py", line 190, in deepcopy
    y = _reconstruct(x, rv, 1, memo)
  File "/Users/<username>/anaconda/envs/tensorflow_source_gpu/lib/python2.7/copy.py", line 334, in _reconstruct
    state = deepcopy(state, memo)
  File "/Users/<username>/anaconda/envs/tensorflow_source_gpu/lib/python2.7/copy.py", line 163, in deepcopy
    y = copier(x, memo)
  File "/Users/<username>/anaconda/envs/tensorflow_source_gpu/lib/python2.7/copy.py", line 257, in _deepcopy_dict
    y[deepcopy(key, memo)] = deepcopy(value, memo)
  File "/Users/<username>/anaconda/envs/tensorflow_source_gpu/lib/python2.7/copy.py", line 190, in deepcopy
    y = _reconstruct(x, rv, 1, memo)
  File "/Users/<username>/anaconda/envs/tensorflow_source_gpu/lib/python2.7/copy.py", line 334, in _reconstruct
    state = deepcopy(state, memo)
  File "/Users/<username>/anaconda/envs/tensorflow_source_gpu/lib/python2.7/copy.py", line 163, in deepcopy
    y = copier(x, memo)
  File "/Users/<username>/anaconda/envs/tensorflow_source_gpu/lib/python2.7/copy.py", line 257, in _deepcopy_dict
    y[deepcopy(key, memo)] = deepcopy(value, memo)
  File "/Users/<username>/anaconda/envs/tensorflow_source_gpu/lib/python2.7/copy.py", line 190, in deepcopy
    y = _reconstruct(x, rv, 1, memo)
  File "/Users/<username>/anaconda/envs/tensorflow_source_gpu/lib/python2.7/copy.py", line 334, in _reconstruct
    state = deepcopy(state, memo)
  File "/Users/<username>/anaconda/envs/tensorflow_source_gpu/lib/python2.7/copy.py", line 163, in deepcopy
    y = copier(x, memo)
  File "/Users/<username>/anaconda/envs/tensorflow_source_gpu/lib/python2.7/copy.py", line 257, in _deepcopy_dict
    y[deepcopy(key, memo)] = deepcopy(value, memo)
  File "/Users/<username>/anaconda/envs/tensorflow_source_gpu/lib/python2.7/copy.py", line 163, in deepcopy
    y = copier(x, memo)
  File "/Users/<username>/anaconda/envs/tensorflow_source_gpu/lib/python2.7/copy.py", line 230, in _deepcopy_list
    y.append(deepcopy(a, memo))
  File "/Users/<username>/anaconda/envs/tensorflow_source_gpu/lib/python2.7/copy.py", line 163, in deepcopy
    y = copier(x, memo)
  File "/Users/<username>/anaconda/envs/tensorflow_source_gpu/lib/python2.7/copy.py", line 237, in _deepcopy_tuple
    y.append(deepcopy(a, memo))
  File "/Users/<username>/anaconda/envs/tensorflow_source_gpu/lib/python2.7/copy.py", line 163, in deepcopy
    y = copier(x, memo)
  File "/Users/<username>/anaconda/envs/tensorflow_source_gpu/lib/python2.7/copy.py", line 257, in _deepcopy_dict
    y[deepcopy(key, memo)] = deepcopy(value, memo)
  File "/Users/<username>/anaconda/envs/tensorflow_source_gpu/lib/python2.7/copy.py", line 190, in deepcopy
    y = _reconstruct(x, rv, 1, memo)
  File "/Users/<username>/anaconda/envs/tensorflow_source_gpu/lib/python2.7/copy.py", line 334, in _reconstruct
    state = deepcopy(state, memo)
  File "/Users/<username>/anaconda/envs/tensorflow_source_gpu/lib/python2.7/copy.py", line 163, in deepcopy
    y = copier(x, memo)
  File "/Users/<username>/anaconda/envs/tensorflow_source_gpu/lib/python2.7/copy.py", line 257, in _deepcopy_dict
    y[deepcopy(key, memo)] = deepcopy(value, memo)
  File "/Users/<username>/anaconda/envs/tensorflow_source_gpu/lib/python2.7/copy.py", line 190, in deepcopy
    y = _reconstruct(x, rv, 1, memo)
  File "/Users/<username>/anaconda/envs/tensorflow_source_gpu/lib/python2.7/copy.py", line 343, in _reconstruct
    y.__dict__.update(state)
AttributeError: 'NoneType' object has no attribute 'update'

Source code / logs

All of the source code is exactly as it is on https://github.com/tensorflow/models/tree/master/tutorials/rnn/translate

That being said, I have noticed that if I change line 81 of translate.py to only have 1 tuple (it doesn't matter which one) the code works but it does not train very well.

jmoney4769 avatar Jun 22 '17 14:06 jmoney4769

I also has this error 'NoneType' object has no attribute 'update'.

StephenLee2016 avatar Jun 23 '17 06:06 StephenLee2016

@ebrevdo Can you take a look? Thanks!

tatatodd avatar Jun 23 '17 20:06 tatatodd

I also has this error,so sad

adableau avatar Jun 24 '17 07:06 adableau

From the Stack Overflow answer (https://stackoverflow.com/a/44767407/6061661):

Use the function posted by @fabiofumarola in https://github.com/tensorflow/tensorflow/issues/8191#issuecomment-311003867 for the embedding_attention_seq2seq function. Note that this new function takes an additional argument (from cell to enc_cell and dec_cell), but I just passed cell to both of those parameters and it worked.

jmoney4769 avatar Jun 27 '17 16:06 jmoney4769

@jmoney4769 can you please mention where do I need to put the dec_cell argument? I'm facing this error TypeError: embedding_attention_seq2seq() missing 1 required positional argument: 'dec_cell'

in the function

return tf.contrib.legacy_seq2seq.embedding_attention_seq2seq(
        encoder_inputs,
        decoder_inputs,
        cell,
        num_encoder_symbols=source_vocab_size,
        num_decoder_symbols=target_vocab_size,
        embedding_size=size,
        output_projection=output_projection,
        feed_previous=do_decode,
        dtype=dtype) 

The error says I need to put 'dec_cell' too. How did you fix this?

toseef-ahmd avatar Aug 18 '17 19:08 toseef-ahmd

@comsian106 I think you change the line in seq2seq_model.py. In that file, there are function call which we change to @fabiofumarola 's code. In the function call, there is one parameter cell in the line. You need to change that to cell, cell to avoid error. like this.

      return tf.contrib.legacy_seq2seq.embedding_attention_seq2seq(
          encoder_inputs,
          decoder_inputs,
          cell,
          cell,
          num_encoder_symbols=source_vocab_size,
          num_decoder_symbols=target_vocab_size,
          embedding_size=size,
          output_projection=output_projection,
          feed_previous=do_decode,
          dtype=dtype)

Thanks.

sh0416 avatar Sep 27 '17 15:09 sh0416

I tried the change suggested above and now have a new : Traceback (most recent call last): File "C:/Users/schwe_000/PycharmProjects/TweetSentiment10/TensorFlowModel/execute.py", line 298, in train() File "C:/Users/schwe_000/PycharmProjects/TweetSentiment10/TensorFlowModel/execute.py", line 121, in train model = create_model(sess, False) File "C:/Users/schwe_000/PycharmProjects/TweetSentiment10/TensorFlowModel/execute.py", line 93, in create_model model = seq2seq_model.Seq2SeqModel( gConfig['enc_vocab_size'], gConfig['dec_vocab_size'], _buckets, gConfig['layer_size'], gConfig['num_layers'], gConfig['max_gradient_norm'], gConfig['batch_size'], gConfig['learning_rate'], gConfig['learning_rate_decay_factor'], forward_only=forward_only) File "C:\Users\schwe_000\PycharmProjects\TweetSentiment10\TensorFlowModel\seq2seq_model.py", line 182, in init softmax_loss_function=softmax_loss_function) File "C:\Users\schwe_000\python35\lib\site-packages\tensorflow\contrib\legacy_seq2seq\python\ops\seq2seq.py", line 1209, in model_with_buckets decoder_inputs[:bucket[1]]) File "C:\Users\schwe_000\PycharmProjects\TweetSentiment10\TensorFlowModel\seq2seq_model.py", line 181, in lambda x, y: seq2seq_f(x, y, False), File "C:\Users\schwe_000\PycharmProjects\TweetSentiment10\TensorFlowModel\seq2seq_model.py", line 145, in seq2seq_f dtype=dtype) TypeError: embedding_attention_seq2seq() got multiple values for argument 'num_encoder_symbols'

I am using Python 3.5 and TensorFlow 1.3.

Schweboo avatar Oct 04 '17 14:10 Schweboo

if passsing same cell to enc_cell and dec_cell arguments, then encoder and decoder will share variable. It's right?

raytroop avatar Nov 21 '17 09:11 raytroop

Yup

On Tue, Nov 21, 2017, 1:20 AM raytroop [email protected] wrote:

if passsing same cell to enc_cell and dec_cell arguments, then encoder and decoder will share variable. It's right?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/tensorflow/models/issues/1733#issuecomment-345964759, or mute the thread https://github.com/notifications/unsubscribe-auth/ABtimx8DZJkysvZIBTwvqV48jtajVbPsks5s4pXdgaJpZM4OCYff .

ebrevdo avatar Nov 21 '17 15:11 ebrevdo