Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pre-loaded glove char vectors have mismatched tensor shapes #17

Closed
alphamupsiomega opened this issue Apr 29, 2018 · 3 comments
Closed

Comments

@alphamupsiomega
Copy link

When trying to set the "pretrained_char" as True, the is a tensor reshape size conflict.

glove_char_file = os.path.join('data/glove', "glove.840B.300d-char.txt")
flags.DEFINE_string("glove_char_file", glove_char_file, "Glove character embedding source file")
flags.DEFINE_boolean("pretrained_char", True, "Whether to use pretrained character embedding")

Error is from model.py line 76, below. How can the reshape dimensions be adjusted?

Error:

Traceback (most recent call last):
  File "config.py", line 152, in <module>
    tf.app.run()
  File "/home/my/anaconda3/lib/python3.6/site-packages/tensorflow/python/platform/app.py", line 126, in run
    _sys.exit(main(argv))
  File "config.py", line 133, in main
    train(config)
  File "QANet/main.py", line 95, in train
    handle: train_handle, model.dropout: config.dropout})
  File "/home/my/anaconda3/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 905, in run
    run_metadata_ptr)
  File "/home/my/anaconda3/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 1140, in _run
    feed_dict_tensor, options, run_metadata)
  File "/home/my/anaconda3/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 1321, in _do_run
    run_metadata)
  File "/home/my/anaconda3/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 1340, in _do_call
    raise type(e)(node_def, op, message)
tensorflow.python.framework.errors_impl.InvalidArgumentError: Input to reshape is a tensor with 2445312 values, but the requested shape has 11462400
	 [[Node: Input_Embedding_Layer/Reshape = Reshape[T=DT_FLOAT, Tshape=DT_INT32, _device="/job:localhost/replica:0/task:0/device:GPU:0"](Input_Embedding_Layer/embedding_lookup, Input_Embedding_Layer/Reshape/shape)]]
	 [[Node: Identity/_4743 = _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_52979_Identity", tensor_type=DT_FLOAT, _device="/job:localhost/replica:0/task:0/device:CPU:0"]()]]

Caused by op 'Input_Embedding_Layer/Reshape', defined at:
  File "config.py", line 152, in <module>
    tf.app.run()
  File "/home/my/anaconda3/lib/python3.6/site-packages/tensorflow/python/platform/app.py", line 126, in run
    _sys.exit(main(argv))
  File "config.py", line 133, in main
    train(config)
  File "QANet/main.py", line 72, in train
    model = Model(config, iterator, word_mat, char_mat, graph = g)
  File "QANet/model.py", line 60, in __init__
    self.forward()
  File "QANet/model.py", line 76, in forward
    ch_emb = tf.reshape(tf.nn.embedding_lookup(self.char_mat, self.ch), [N * PL, CL, dc]) # 32*1000?, 16, 64 = 32768000.  Input to reshape is a tensor with 34099200 values, but the requested shape has 7274496.
  File "/home/my/anaconda3/lib/python3.6/site-packages/tensorflow/python/ops/gen_array_ops.py", line 5782, in reshape
    "Reshape", tensor=tensor, shape=shape, name=name)
  File "/home/my/anaconda3/lib/python3.6/site-packages/tensorflow/python/framework/op_def_library.py", line 787, in _apply_op_helper
    op_def=op_def)
  File "/home/my/anaconda3/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 3290, in create_op
    op_def=op_def)
  File "/home/my/anaconda3/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 1654, in __init__
    self._traceback = self._graph._extract_stack()  # pylint: disable=protected-access

InvalidArgumentError (see above for traceback): Input to reshape is a tensor with 2445312 values, but the requested shape has 11462400
	 [[Node: Input_Embedding_Layer/Reshape = Reshape[T=DT_FLOAT, Tshape=DT_INT32, _device="/job:localhost/replica:0/task:0/device:GPU:0"](Input_Embedding_Layer/embedding_lookup, Input_Embedding_Layer/Reshape/shape)]]
	 [[Node: Identity/_4743 = _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_52979_Identity", tensor_type=DT_FLOAT, _device="/job:localhost/replica:0/task:0/device:CPU:0"]()]]
@alphamupsiomega
Copy link
Author

alphamupsiomega commented Apr 29, 2018

The same issue also arises just when modifying char_dim.

@ghost
Copy link

ghost commented Apr 29, 2018

If you want to use your own char embeddings you should change the dimension of the mebeddings here https://github.com/minsangkim142/QANet/blob/f0c79cc93dc1dfdad2bc8abb712a53d078814a56/config.py#L82
And you have to re-run python config.py --mode prepro

@alphamupsiomega
Copy link
Author

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

0 participants