R-net: Weird error message when run `python model.py`.

I tried to run this project in a totally new environment. (Ubuntu 16.04 64 bit, Python 2.7) I strictly followed the instructions. However, I always end with an error message (see below) when I run python model.py.

Traceback (most recent call last):
  File "model.py", line 258, in <module>
    main()
  File "model.py", line 231, in main
    sess.run(model.train_op)
  File "/root/nlp/venv/local/lib/python2.7/site-packages/tensorflow/python/client/session.py", line 789, in run
    run_metadata_ptr)
  File "/root/nlp/venv/local/lib/python2.7/site-packages/tensorflow/python/client/session.py", line 997, in _run
    feed_dict_string, options, run_metadata)
  File "/root/nlp/venv/local/lib/python2.7/site-packages/tensorflow/python/client/session.py", line 1132, in _do_run
    target_list, options, run_metadata)
  File "/root/nlp/venv/local/lib/python2.7/site-packages/tensorflow/python/client/session.py", line 1152, in _do_call
    raise type(e)(node_def, op, message)
tensorflow.python.framework.errors_impl.InvalidArgumentError: seq_lens(8218) > input.dims(1)
         [[Node: passage_char_encoding/bidirectional_rnn/bw/ReverseSequence = ReverseSequence[T=DT_FLOAT, Tlen=DT_INT32, batch_dim=0, seq_dim=1, _device="/job:localhost/replica:0/task:0/cpu:0"](passage_char_encoding/Reshape, passage_char_encoding/Reshape_1)]]

Caused by op u'passage_char_encoding/bidirectional_rnn/bw/ReverseSequence', defined at:
  File "model.py", line 258, in <module>
    main()
  File "model.py", line 209, in main
    model = Model(is_training = True); print("Built model")
  File "model.py", line 43, in __init__
    self.encode_ids()
  File "model.py", line 81, in encode_ids
    is_training = self.is_training)
  File "/root/nlp/R-net/layers.py", line 98, in bidirectional_GRU
    dtype=tf.float32)
  File "/root/nlp/venv/local/lib/python2.7/site-packages/tensorflow/python/ops/rnn.py", line 396, in bidirectional_dynamic_rnn
    seq_dim=time_dim, batch_dim=batch_dim)
  File "/root/nlp/venv/local/lib/python2.7/site-packages/tensorflow/python/ops/rnn.py", line 389, in _reverse
    seq_dim=seq_dim, batch_dim=batch_dim)
  File "/root/nlp/venv/local/lib/python2.7/site-packages/tensorflow/python/ops/array_ops.py", line 2355, in reverse_sequence
    name=name)
  File "/root/nlp/venv/local/lib/python2.7/site-packages/tensorflow/python/ops/gen_array_ops.py", line 2633, in reverse_sequence
    batch_dim=batch_dim, name=name)
  File "/root/nlp/venv/local/lib/python2.7/site-packages/tensorflow/python/framework/op_def_library.py", line 767, in apply_op
    op_def=op_def)
  File "/root/nlp/venv/local/lib/python2.7/site-packages/tensorflow/python/framework/ops.py", line 2506, in create_op
    original_op=self._default_original_op, op_def=op_def)
  File "/root/nlp/venv/local/lib/python2.7/site-packages/tensorflow/python/framework/ops.py", line 1269, in __init__
    self._traceback = _extract_stack()

InvalidArgumentError (see above for traceback): seq_lens(8218) > input.dims(1)
         [[Node: passage_char_encoding/bidirectional_rnn/bw/ReverseSequence = ReverseSequence[T=DT_FLOAT, Tlen=DT_INT32, batch_dim=0, seq_dim=1, _device="/job:localhost/replica:0/task:0/cpu:0"](passage_char_encoding/Reshape, passage_char_encoding/Reshape_1)]]

Any idea about this problem?

I’m using the current code without any modification.

This this the pip packages I installed. nltk==3.2.4 numpy==1.13.1 scikit-learn==0.19.0 scipy==0.19.1 spacy==1.9.0 tensorflow==1.2.0 tensorflow-tensorboard==0.1.8 tqdm==4.15.0

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 16

Most upvoted comments

@minsangkim142 , I have 2 modification:

  1. define a new function in ‘process.py’:
def pad_char_len(data, max_word, max_char):
    padded_data = np.zeros((len(data), max_word), dtype=np.int32)
    for i, line in enumerate(data):
        for j, word in enumerate(line):
            if j >= max_word:
                break
            padded_data[i, j] = word if word <= max_char else max_char
    return padded_data
  1. File ‘data_load.py’ in line 143~147 change to the following:
# to numpy
    indices = np.reshape(np.asarray(indices, np.int32), (-1, 2))
    p_word_len = np.reshape(np.asarray(p_word_len, np.int32), (-1, 1))
    q_word_len = np.reshape(np.asarray(q_word_len, np.int32), (-1, 1))
    # p_char_len = pad_data(p_char_len, p_max_word)
    # q_char_len = pad_data(q_char_len, q_max_word)
    p_char_len = pad_char_len(p_char_len, p_max_word, p_max_char)
    q_char_len = pad_char_len(q_char_len, q_max_word, q_max_char)
    # fix p(q)_word_len
    for i in range(p_word_len.shape[0]):
        if p_word_len[i,0] > p_max_word:
            p_word_len[i,0] = p_max_word
    for i in range(q_word_len.shape[0]):
        if q_word_len[i,0] > q_max_word:
            q_word_len[i,0] = q_max_word

@thisum I have not figured out how the point network works! So i do not know how to fix it! I need more time to figure out the shape of every tensor!.

I ran into the same error. Did anyone come up with a solution? I used virtual environment to install packages and run the code