Marsan-Ma-zz / tf_chatbot_seq2seq_antilm

Seq2seq chatbot with attention and anti-language model to suppress generic response, option for further improve by deep reinforcement learning.
362 stars 162 forks source link

Error while running --mode chat #6

Closed gidim closed 7 years ago

gidim commented 7 years ago

Model was training fine. This is what happens when i launch: python3 main.py --mode chat

Reading model parameters from works/___/nn_models/model.ckpt-23000
> Hello. How are you?
Traceback (most recent call last):
  File "main.py", line 28, in <module>
    tf.app.run()
  File "/homes/someone/anaconda3/lib/python3.5/site-packages/tensorflow/python/platform/app.py", line 30, in run
    sys.exit(main(sys.argv[:1] + flags_passthrough))
  File "main.py", line 22, in main
    chat(args)
  File "/homes/someone/dev/seq2seq/lib/chat.py", line 26, in chat
    predicted_sentence = get_predicted_sentence(args, sentence, vocab, rev_vocab, model, sess)
  File "/homes/someone/dev/seq2seq/lib/seq2seq_model_utils.py", line 122, in get_predicted_sentence
    all_prob_ts = model_step(encoder_inputs, cand['dec_inp'], dptr, target_weights, bucket_id)
  File "/homes/someone/dev/seq2seq/lib/seq2seq_model_utils.py", line 75, in model_step
    _, _, logits = model.step(sess, enc_inp, dec_inp, target_weights, bucket_id, force_dec_input=True)
  File "/homes/someone/dev/seq2seq/lib/seq2seq_model.py", line 260, in step
    outputs = session.run(output_feed, input_feed)
  File "/homes/someone/anaconda3/lib/python3.5/site-packages/tensorflow/python/client/session.py", line 717, in run
    run_metadata_ptr)
  File "/homes/someone/anaconda3/lib/python3.5/site-packages/tensorflow/python/client/session.py", line 894, in _run
    % (np_val.shape, subfeed_t.name, str(subfeed_t.get_shape())))
ValueError: Cannot feed value of shape (1,) for Tensor 'seq2seq/decoder0:0', which has shape '(128,)'
joa23 commented 7 years ago

Same here.

sanghyunyi commented 7 years ago

Set the batch size as 1, then it works.

joa23 commented 7 years ago

I had no success with that. The code in chat.py has it already set: model = create_model(sess, args) model.batch_size = 1 # We decode one sentence at a time. When passing batch_size as command line parameter --batch_size 1 I'm getting the prompt ">" but as soon I submit something I'm getting the following error:

Traceback (most recent call last): File "main.py", line 28, in tf.app.run() File "/Users/joa23/projects/dl/lib/python3.5/site-packages/tensorflow/python/platform/app.py", line 43, in run sys.exit(main(sys.argv[:1] + flags_passthrough)) File "main.py", line 22, in main chat(args) File "/Users/joa23/PycharmProjects/tf_chatbot_seq2seq_antilm/lib/chat.py", line 27, in chat predicted_sentence = get_predicted_sentence(args, sentence, vocab, rev_vocab, model, sess) File "/Users/joa23/PycharmProjects/tf_chatbot_seq2seq_antilm/lib/seq2seq_model_utils.py", line 160, in get_predicted_sentence cand['dec_inp'] = " ".join([dict_lookup(rev_vocab, w) for w in cand['dec_inp']]) File "/Users/joa23/PycharmProjects/tf_chatbot_seq2seq_antilm/lib/seq2seq_model_utils.py", line 160, in cand['dec_inp'] = " ".join([dict_lookup(rev_vocab, w) for w in cand['dec_inp']]) File "/Users/joa23/PycharmProjects/tf_chatbot_seq2seq_antilm/lib/seq2seq_model_utils.py", line 48, in dict_lookup return rev_vocab[out]
TypeError: only integer scalar arrays can be converted to a scalar index

ajaymaity commented 7 years ago

change the line to: return rev_vocab[out[0]]

gidim commented 7 years ago

That worked for me. Will submit a pull request.

joa23 commented 7 years ago

I'm now getting some output but even though I trained until perplexity was below 40 it looks like there is an issue with the output. (twitter corpus)

are you kidding me? [{'prob': 2.5728970049210626e-62, 'dec_inp': '_GO levee 34-year 34-year 34-year 34-year 34-year 34-year 34-year [holds [holds [holds [holds [holds [holds', 'eos': False, 'prob_t': 0, 'prob_ts': 2.5728970049210626e-62}, {'prob': 2.5720786921651683e-62, 'dec_inp': '_GO levee 34-year 34-year 34-year 34-year 34-year 34-year 34-year 34-year [holds [holds [holds [holds [holds', 'eos': False, 'prob_t': 0, 'prob_ts': 2.5720786921651683e-62}, {'prob': 2.5607476792239287e-62, 'dec_inp': '_GO levee 34-year too‼️ 34-year 34-year 34-year 34-year 34-year [holds [holds [holds [holds [holds [holds', 'eos': False, 'prob_t': 0, 'prob_ts': 2.5607476792239287e-62}, {'prob': 2.5607317645238776e-62, 'dec_inp': '_GO levee 34-year 34-year 34-year 34-year 34-year 34-year [holds [holds [holds [holds [holds [holds [holds', 'eos': False, 'prob_t': 0, 'prob_ts': 2.5607317645238776e-62}, {'prob': 2.5599072436347957e-62, 'dec_inp': '_GO levee 34-year 34-year 34-year 34-year 34-year 34-year [holds 34-year [holds [holds [holds [holds [holds', 'eos': False, 'prob_t': 0, 'prob_ts': 2.5599072436347957e-62}, {'prob': 2.559747353973062e-62, 'dec_inp': '_GO levee 34-year 34-year 34-year 34-year 34-year 34-year 34-year [holds 34-year [holds [holds [holds [holds', 'eos': False, 'prob_t': 0, 'prob_ts': 2.559747353973062e-62}, {'prob': 2.5597117609238067e-62, 'dec_inp': '_GO levee 34-year too‼️ 34-year 34-year 34-year 34-year 34-year 34-year [holds [holds [holds [holds [holds', 'eos': False, 'prob_t': 0, 'prob_ts': 2.5597117609238067e-62}, {'prob': 2.5589409628891065e-62, 'dec_inp': '_GO levee 34-year 34-year 34-year 34-year 34-year 34-year 34-year 34-year 34-year [holds [holds [holds [holds', 'eos': False, 'prob_t': 0, 'prob_ts': 2.5589409628891065e-62}, {'prob': 2.5589247934087181e-62, 'dec_inp': '_GO levee too‼️ 34-year 34-year 34-year 34-year 34-year 34-year [holds [holds [holds [holds [holds [holds', 'eos': False, 'prob_t': 0, 'prob_ts': 2.5589247934087181e-62}, {'prob': 2.557861740562856e-62, 'dec_inp': '_GO levee too‼️ 34-year 34-year 34-year 34-year 34-year 34-year 34-year [holds [holds [holds [holds [holds', 'eos': False, 'prob_t': 0, 'prob_ts': 2.557861740562856e-62}]

Do you have any recommendation what the issue could be?

ajaymaity commented 7 years ago

@joa23, I believe the issue is that when you run main.py with chat mode, it creates a fresh model with default parameters. It should take the trained model, but that doesn't happen here it seems. The reason might be the way the checkpoint is fetched (it doesn't find the latest checkpoint in folder, and so it creates a fresh model). I was facing the same issue, and narrowed down the problem to the one I mentioned. But couldn't really had any time to fix. Will post the solution here once done. Meanwhile check if you can fix.

joa23 commented 7 years ago

@ajaymaity Thanks for the hint. I will try to investigate as well.

Marsan-Ma-zz commented 7 years ago

@ajaymaity is right, whatever parameter you appended in main.py command while in training, you have to append exactly the same while you do testing. Will add this to the readme.