chiphuyen / stanford-tensorflow-tutorials

This repository contains code examples for the Stanford's course: TensorFlow for Deep Learning Research.
http://cs20.stanford.edu
MIT License
10.33k stars 4.31k forks source link

Multiple errors trying to run chatbot in python 3.6 with tensorflow 1.3 #70

Closed cubeworkshop closed 7 years ago

cubeworkshop commented 7 years ago

Hello,

I'm trying to run the chatbot, but I'm receiving many errors that I'd appreciate if you could help me solve. The last error that has appeared is one in the middle of the section "Loading parameters for the Chatbot".

Before getting to this point, I received an error that fixed by editing lines around 848 in the seq2seq.py file:

    #encoder_cell = copy.deepcopy(cell)
    cell = copy.deepcopy(cell)
    encoder_cell = core_rnn_cell.EmbeddingWrapper(
        #encoder_cell,
        cell,

This is the result of the execution:

# python3.6 chatbot.py 
Data ready!
Bucketing conversation number 9999
Bucketing conversation number 19999
Bucketing conversation number 9999
Bucketing conversation number 19999
Bucketing conversation number 29999
Bucketing conversation number 39999
Bucketing conversation number 49999
Bucketing conversation number 59999
Bucketing conversation number 69999
Bucketing conversation number 79999
Bucketing conversation number 89999
Bucketing conversation number 99999
Bucketing conversation number 109999
Bucketing conversation number 119999
Bucketing conversation number 129999
Bucketing conversation number 139999
Bucketing conversation number 149999
Bucketing conversation number 159999
Bucketing conversation number 169999
Bucketing conversation number 179999
Bucketing conversation number 189999
Number of samples in each bucket:
 [38095, 34447, 30931]
Bucket scale:
 [0.36816367554821067, 0.7010717771785876, 1.0]
Initialize new model
Create placeholders
Create inference
Creating loss... 
It might take a couple of minutes depending on how many buckets you have.
Time: 14.253957271575928
Create optimizer... 
It might take a couple of minutes depending on how many buckets you have.
Creating opt for bucket 0 took 5.574482440948486 seconds
Creating opt for bucket 1 took 8.757641077041626 seconds
Creating opt for bucket 2 took 11.90887451171875 seconds
2017-10-15 17:22:01.217183: 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-10-15 17:22:01.217281: 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-10-15 17:22:01.217307: 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.
Running session
Loading parameters for the Chatbot
Iter 400: loss 4.7150276041030885, time 5.993304967880249
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/client/session.py", line 1327, in _do_call
    return fn(*args)
  File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/client/session.py", line 1306, in _run_fn
    status, run_metadata)
  File "/usr/lib/python3.6/contextlib.py", line 88, in __exit__
    next(self.gen)
  File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/framework/errors_impl.py", line 466, in raise_exception_on_not_ok_status
    pywrap_tensorflow.TF_GetCode(status))
tensorflow.python.framework.errors_impl.InvalidArgumentError: indices[2] = 24675 is not in [0, 24671)
     [[Node: model_with_buckets/sequence_loss_2/sequence_loss_by_example/sampled_softmax_loss_14/embedding_lookup_1 = Gather[Tindices=DT_INT64, Tparams=DT_FLOAT, _class=["loc:@proj_b"], validate_indices=true, _device="/job:localhost/replica:0/task:0/cpu:0"](proj_b/read, model_with_buckets/sequence_loss_2/sequence_loss_by_example/sampled_softmax_loss_14/concat)]]

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "chatbot.py", line 261, in <module>
    main()
  File "chatbot.py", line 256, in main
    train()
  File "chatbot.py", line 155, in train
    _, step_loss, _ = run_step(sess, model, encoder_inputs, decoder_inputs, decoder_masks, bucket_id, False)
  File "chatbot.py", line 81, in run_step
    outputs = sess.run(output_feed, input_feed)
  File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/client/session.py", line 895, in run
    run_metadata_ptr)
  File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/client/session.py", line 1124, in _run
    feed_dict_tensor, options, run_metadata)
  File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/client/session.py", line 1321, in _do_run
    options, run_metadata)
  File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/client/session.py", line 1340, in _do_call
    raise type(e)(node_def, op, message)
tensorflow.python.framework.errors_impl.InvalidArgumentError: indices[2] = 24675 is not in [0, 24671)
     [[Node: model_with_buckets/sequence_loss_2/sequence_loss_by_example/sampled_softmax_loss_14/embedding_lookup_1 = Gather[Tindices=DT_INT64, Tparams=DT_FLOAT, _class=["loc:@proj_b"], validate_indices=true, _device="/job:localhost/replica:0/task:0/cpu:0"](proj_b/read, model_with_buckets/sequence_loss_2/sequence_loss_by_example/sampled_softmax_loss_14/concat)]]

Caused by op 'model_with_buckets/sequence_loss_2/sequence_loss_by_example/sampled_softmax_loss_14/embedding_lookup_1', defined at:
  File "chatbot.py", line 261, in <module>
    main()
  File "chatbot.py", line 256, in main
    train()
  File "chatbot.py", line 137, in train
    model.build_graph()
  File "/root/Desktop/chatbot/model.py", line 132, in build_graph
    self._create_loss()
  File "/root/Desktop/chatbot/model.py", line 100, in _create_loss
    softmax_loss_function=self.softmax_loss_function)
  File "/usr/local/lib/python3.6/dist-packages/tensorflow/contrib/legacy_seq2seq/python/ops/seq2seq.py", line 1223, in model_with_buckets
    softmax_loss_function=softmax_loss_function))
  File "/usr/local/lib/python3.6/dist-packages/tensorflow/contrib/legacy_seq2seq/python/ops/seq2seq.py", line 1136, in sequence_loss
    softmax_loss_function=softmax_loss_function))
  File "/usr/local/lib/python3.6/dist-packages/tensorflow/contrib/legacy_seq2seq/python/ops/seq2seq.py", line 1091, in sequence_loss_by_example
    crossent = softmax_loss_function(labels=target, logits=logit)
  File "/root/Desktop/chatbot/model.py", line 59, in sampled_loss
    config.NUM_SAMPLES, config.DEC_VOCAB)
  File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/ops/nn_impl.py", line 1247, in sampled_softmax_loss
    name=name)
  File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/ops/nn_impl.py", line 986, in _compute_sampled_logits
    biases, all_ids, partition_strategy=partition_strategy)
  File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/ops/embedding_ops.py", line 294, in embedding_lookup
    transform_fn=None)
  File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/ops/embedding_ops.py", line 123, in _embedding_lookup_and_transform
    result = _gather_and_clip(params[0], ids, max_norm, name=name)
  File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/ops/embedding_ops.py", line 57, in _gather_and_clip
    embs = array_ops.gather(params, ids, name=name)
  File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/ops/array_ops.py", line 2409, in gather
    validate_indices=validate_indices, name=name)
  File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/ops/gen_array_ops.py", line 1219, in gather
    validate_indices=validate_indices, name=name)
  File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/framework/op_def_library.py", line 767, in apply_op
    op_def=op_def)
  File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/framework/ops.py", line 2630, in create_op
    original_op=self._default_original_op, op_def=op_def)
  File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/framework/ops.py", line 1204, in __init__
    self._traceback = self._graph._extract_stack()  # pylint: disable=protected-access

InvalidArgumentError (see above for traceback): indices[2] = 24675 is not in [0, 24671)
     [[Node: model_with_buckets/sequence_loss_2/sequence_loss_by_example/sampled_softmax_loss_14/embedding_lookup_1 = Gather[Tindices=DT_INT64, Tparams=DT_FLOAT, _class=["loc:@proj_b"], validate_indices=true, _device="/job:localhost/replica:0/task:0/cpu:0"](proj_b/read, model_with_buckets/sequence_loss_2/sequence_loss_by_example/sampled_softmax_loss_14/concat)]]
cubeworkshop commented 7 years ago

After a lot of hours of debugging, discovered that the problem was in the config.py file. The ENC_VOCAB and DEC_VOCAB parameters were wrong.

To get the right values for these parameters, check how many lines you have in the vocab.enc and vocab.dec files.