freesunshine0316 / MPQG

Code corresponding to our paper "Leveraging Context Information for Natural Question Generation"
47 stars 10 forks source link

Error while decoding #2

Closed yanghoonkim closed 5 years ago

yanghoonkim commented 6 years ago

With command:

python NP2P_beam_decoder.py --model_prefix ~/MPQG/src/logs/NP2P.mpqg_1 --in_path ~/MPQG/src/data/test_sent_pre.json --out-path ~/MPQG/predictions.txt --mode beam

I got an error message:

tensorflow.python.framework.errors_impl.InvalidArgumentError: ConcatOp : Dimensions of inputs should match: shape[0] = [1,100] vs. shape[1] = [50,100]
         [[Node: Valid/Model/generator/attention_decoder_1/attention_decoder/lstm_cell/concat = ConcatV2[N=2, T=DT_FLOAT, Tidx=DT_INT32, _device="/job:localhost/replica:0/task:0/device:GPU:0"](Valid/Model/generator/attention_decoder_1/Linear/add, _arg_Valid/Model/initial_state_for_decoder/Tanh_1_0_7/_313, Valid/Model/generator/attention_decoder_1/attention_decoder/lstm_cell/concat/axis)]]
         [[Node: Valid/Model/generator/attention_decoder_1/Attention/add_2/_345 = _Recv[client_terminated=false, recv_device="/job:localhost/replica:0/task:0/device:CPU:0", send_device="/job:localhost/replica:0/task:0/device:GPU:0", send_device_incarnation=1, tensor_name="edge_257_Valid/Model/generator/attention_decoder_1/Attention/add_2", tensor_type=DT_FLOAT, _device="/job:localhost/replica:0/task:0/device:CPU:0"]()]]

Caused by op u'Valid/Model/generator/attention_decoder_1/attention_decoder/lstm_cell/concat', defined at:
  File "NP2P_beam_decoder.py", line 320, in <module>
    NER_vocab=NER_vocab, options=FLAGS, mode="decode")
  File "/home/ad26kr/work/git/MPQG/src/NP2P_model_graph.py", line 91, in __init__
    self.phrase_representations, self.encoder_features, self.phrase_idx, self.phrase_mask)
  File "/home/ad26kr/work/git/MPQG/src/generator_utils.py", line 273, in decode_mode
    passage_word_idx, passage_mask, v, w_c, word_vocab)
  File "/home/ad26kr/work/git/MPQG/src/generator_utils.py", line 111, in one_step_decoder
    cell_output, state_t = self.cell(x, state_t_1)
  File "/home/ad26kr/miniconda2/lib/python2.7/site-packages/tensorflow/python/ops/rnn_cell_impl.py", line 183, in __call__
    return super(RNNCell, self).__call__(inputs, state)
  File "/home/ad26kr/miniconda2/lib/python2.7/site-packages/tensorflow/python/layers/base.py", line 575, in __call__
    outputs = self.call(inputs, *args, **kwargs)
  File "/home/ad26kr/miniconda2/lib/python2.7/site-packages/tensorflow/python/ops/rnn_cell_impl.py", line 611, in call
    lstm_matrix = self._linear1([inputs, m_prev])
  File "/home/ad26kr/miniconda2/lib/python2.7/site-packages/tensorflow/python/ops/rnn_cell_impl.py", line 1189, in __call__
    res = math_ops.matmul(array_ops.concat(args, 1), self._weights)
  File "/home/ad26kr/miniconda2/lib/python2.7/site-packages/tensorflow/python/ops/array_ops.py", line 1099, in concat
    return gen_array_ops._concat_v2(values=values, axis=axis, name=name)
  File "/home/ad26kr/miniconda2/lib/python2.7/site-packages/tensorflow/python/ops/gen_array_ops.py", line 706, in _concat_v2
    "ConcatV2", values=values, axis=axis, name=name)
  File "/home/ad26kr/miniconda2/lib/python2.7/site-packages/tensorflow/python/framework/op_def_library.py", line 787, in _apply_op_helper
    op_def=op_def)
  File "/home/ad26kr/miniconda2/lib/python2.7/site-packages/tensorflow/python/framework/ops.py", line 2956, in create_op
    op_def=op_def)
  File "/home/ad26kr/miniconda2/lib/python2.7/site-packages/tensorflow/python/framework/ops.py", line 1470, in __init__
    self._traceback = self._graph._extract_stack()  # pylint: disable=protected-access

InvalidArgumentError (see above for traceback): ConcatOp : Dimensions of inputs should match: shape[0] = [1,100] vs. shape[1] = [50,100]
         [[Node: Valid/Model/generator/attention_decoder_1/attention_decoder/lstm_cell/concat = ConcatV2[N=2, T=DT_FLOAT, Tidx=DT_INT32, _device="/job:localhost/replica:0/task:0/device:GPU:0"](Valid/Model/generator/attention_decoder_1/Linear/add, _arg_Valid/Model/initial_state_for_decoder/Tanh_1_0_7/_313, Valid/Model/generator/attention_decoder_1/attention_decoder/lstm_cell/concat/axis)]]
         [[Node: Valid/Model/generator/attention_decoder_1/Attention/add_2/_345 = _Recv[client_terminated=false, recv_device="/job:localhost/replica:0/task:0/device:CPU:0", send_device="/job:localhost/replica:0/task:0/device:GPU:0", send_device_incarnation=1, tensor_name="edge_257_Valid/Model/generator/attention_decoder_1/Attention/add_2", tensor_type=DT_FLOAT, _device="/job:localhost/replica:0/task:0/device:CPU:0"]()]]

There may be some inconsistency related to batch size?

Or did I do something wrong?

I didn't change any of config.json

caozhen-alex commented 5 years ago

@yanghoonkim Have you solved decoder problem?

caozhen-alex commented 5 years ago

For me, I encountered another bug:

(tensorflow) jinyang@ubuntu1604:/data1/caozhen/MPQG/src$ python NP2P_beam_decoder.py --model_prefix /data1/caozhen/MPQG/src/logs/NP2P.mpqg_5 --in_path /data1/caozhen/MPQG/src/data/test_sent_pre.json --out-path /data1/caozhen/MPQG/logs/predictions.txt --mode beam CUDA_VISIBLE_DEVICES 0,1,2,3,4,5,6 Loading configurations from /data1/caozhen/MPQG/src/logs/NP2P.mpqg_5.config.json Loading vocabs. word_vocab: (69980, 300) POS_vocab: (46, 20) Loading test set. Number of samples: 11805 Build DataStream ... Number of instances in testDataStream: 11805 Number of batches in testDataStream: 237 2018-11-28 13:44:11.263634: I tensorflow/core/platform/cpu_feature_guard.cc:141] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA Traceback (most recent call last): File "NP2P_beam_decoder.py", line 342, in outfile = open(out_path, 'wt') TypeError: coercing to Unicode: need string or buffer, NoneType found

@freesunshine0316 and I find a solution here https://stackoverflow.com/questions/16169035/coercing-to-unicode-need-string-or-buffer-nonetype-found-when-rendering-in-dja but I don't know how to modify the code since I am sitll not familiar with your code. Can you take a look? Thx!

KJ-Lin commented 5 years ago

@yanghoonkim I met the same, Have you solved decoder problem?

yanghoonkim commented 5 years ago

@caozhen-alex @KJ-Lin I didn't, but you guys can try greedy decoding(it works). I think there are some error with related to beam search.

caozhen-alex commented 5 years ago

@yanghoonkim U mean using the file generator_utils.py to generate?

KJ-Lin commented 5 years ago

@yanghoonkim @caozhen-alex I have find the problem the code is "if mode in ['beam_search', 'beam_evaluate']: batch_size = 1 " so it can be work "python NP2P_beam_decoder.py --model_prefix ~/MPQG/src/logs/NP2P.mpqg_1 --in_path ~/MPQG/src/data/test_sent_pre.json --out-path ~/MPQG/predictions.txt --mode beam_search" change the run mode to "beam_search" or change the above code 'beam_search' to 'beam'

freesunshine0316 commented 5 years ago

--out-path

Hi, You used the wrong flag, it should be " --out_path"

freesunshine0316 commented 5 years ago

I updated the code to have the "required" restriction for input parameters. Previously, the code asks for "--out_path", while it was feed "--out-path". So it didn't get what it wants and the "out_path" variable is None.