easy_seq2seq icon indicating copy to clipboard operation
easy_seq2seq copied to clipboard

ValueError: Shape must be rank 2 but is rank 1

Open kingdeewang opened this issue 7 years ago • 3 comments

when i use python 3.6 ,and tensorflow 1.0. execute python execute.py, i encounter the bellow prolem. can you help me to find out the reason?

File "/home/wel/deeplearning/easybot/seq2seq_model.py", line 93, in sampled_loss self.target_vocab_size) File "/home/wel/.pyenv/versions/3.6.0/lib/python3.6/site-packages/tensorflow/python/ops/nn_impl.py", line 1191, in sampled_softmax_loss name=name) File "/home/wel/.pyenv/versions/3.6.0/lib/python3.6/site-packages/tensorflow/python/ops/nn_impl.py", line 947, in _compute_sampled_logits range_max=num_classes) File "/home/wel/.pyenv/versions/3.6.0/lib/python3.6/site-packages/tensorflow/python/ops/candidate_sampling_ops.py", line 134, in log_uniform_candidate_sampler seed2=seed2, name=name) File "/home/wel/.pyenv/versions/3.6.0/lib/python3.6/site-packages/tensorflow/python/ops/gen_candidate_sampling_ops.py", line 357, in _log_uniform_candidate_sampler name=name) File "/home/wel/.pyenv/versions/3.6.0/lib/python3.6/site-packages/tensorflow/python/framework/op_def_library.py", line 763, in apply_op op_def=op_def) File "/home/wel/.pyenv/versions/3.6.0/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 2397, in create_op set_shapes_for_outputs(ret) File "/home/wel/.pyenv/versions/3.6.0/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 1757, in set_shapes_for_outputs shapes = shape_func(op) File "/home/wel/.pyenv/versions/3.6.0/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 1707, in call_with_requiring return call_cpp_shape_fn(op, require_shape_fn=True) File "/home/wel/.pyenv/versions/3.6.0/lib/python3.6/site-packages/tensorflow/python/framework/common_shapes.py", line 610, in call_cpp_shape_fn debug_python_shape_fn, require_shape_fn) File "/home/wel/.pyenv/versions/3.6.0/lib/python3.6/site-packages/tensorflow/python/framework/common_shapes.py", line 675, in _call_cpp_shape_fn_impl raise ValueError(err.message) ValueError: Shape must be rank 2 but is rank 1 for 'model_with_buckets/sequence_loss/sequence_loss_by_example/sampled_softmax_loss/LogUniformCandidateSampler' (op: 'LogUniformCandidateSampler') with input shapes: [?].

kingdeewang avatar Mar 22 '17 08:03 kingdeewang

The tensorflow people switched out the order of labels and inputs

change this line to look like this: return tf.nn.sampled_softmax_loss(w_t, b, labels, inputs, num_samples, self.target_vocab_size) in seq2seq_model.py

krzysztofjordan avatar Mar 31 '17 05:03 krzysztofjordan

Hi, I am using python 2.7 and tensorflow=1.3.0 I tried the above approach but I couldn't solve the problem. I got another error

ValueError: Shape must be rank 2 but is rank 1 for 'model_with_buckets/sequence_loss/sequence_loss_by_example/sampled_softmax_loss/MatMul_1' (op: 'MatMul') with input shapes: [?], [?,512]

Could you please let me know how you solved this problem.

ellurunaresh avatar Jun 20 '18 05:06 ellurunaresh

I met this error too, when i used labels=tf.reshape(labels, [-1,1]) It fixed.

mgqixu avatar Aug 19 '19 08:08 mgqixu