shiyybua / NER

基于tensorflow深度学习的中文的命名实体识别
1.04k stars 400 forks source link

使用predict模式测试训练数据出现报错. #8

Open jasonsalex opened 6 years ago

jasonsalex commented 6 years ago

不知道什么意思. building word index... loading word embedding, it will take few minutes... WARNING:tensorflow:From /root/NER/utils.py:210: init (from tensorflow.contrib.data.python.ops.readers) is deprecated and will be removed in a future version. Instructions for updating: Use tf.data.TextLineDataset. Traceback (most recent call last): File "rnn.py", line 166, in net = NER_net("ner", iterator, embedding, BATCH_SIZE) File "rnn.py", line 26, in init self._build_net() File "rnn.py", line 66, in _build_net self.outputs, self.y, self.seq_length) File "/usr/lib/python2.7/site-packages/tensorflow/contrib/crf/python/ops/crf.py", line 201, in crf_log_likelihood transition_params) File "/usr/lib/python2.7/site-packages/tensorflow/contrib/crf/python/ops/crf.py", line 128, in crf_sequence_score fn2=_multi_seq_fn) File "/usr/lib/python2.7/site-packages/tensorflow/python/layers/utils.py", line 211, in smart_cond return control_flow_ops.cond(pred, true_fn=fn1, false_fn=fn2, name=name) File "/usr/lib/python2.7/site-packages/tensorflow/python/util/deprecation.py", line 316, in new_func return func(*args, **kwargs) File "/usr/lib/python2.7/site-packages/tensorflow/python/ops/control_flow_ops.py", line 1894, in cond orig_res_t, res_t = context_t.BuildCondBranch(true_fn) File "/usr/lib/python2.7/site-packages/tensorflow/python/ops/control_flow_ops.py", line 1752, in BuildCondBranch original_result = fn() File "/usr/lib/python2.7/site-packages/tensorflow/contrib/crf/python/ops/crf.py", line 114, in _single_seq_fn array_ops.concat([example_inds, tag_indices], axis=1)) File "/usr/lib/python2.7/site-packages/tensorflow/python/ops/gen_array_ops.py", line 2000, in gather_nd "GatherNd", params=params, indices=indices, name=name) File "/usr/lib/python2.7/site-packages/tensorflow/python/framework/op_def_library.py", line 787, in _apply_op_helper op_def=op_def) File "/usr/lib/python2.7/site-packages/tensorflow/python/framework/ops.py", line 3162, in create_op compute_device=compute_device) File "/usr/lib/python2.7/site-packages/tensorflow/python/framework/ops.py", line 3208, in _create_op_helper set_shapes_for_outputs(op) File "/usr/lib/python2.7/site-packages/tensorflow/python/framework/ops.py", line 2427, in set_shapes_for_outputs return _set_shapes_for_outputs(op) File "/usr/lib/python2.7/site-packages/tensorflow/python/framework/ops.py", line 2400, in _set_shapes_for_outputs shapes = shape_func(op) File "/usr/lib/python2.7/site-packages/tensorflow/python/framework/ops.py", line 2330, in call_with_requiring return call_cpp_shape_fn(op, require_shape_fn=True) File "/usr/lib/python2.7/site-packages/tensorflow/python/framework/common_shapes.py", line 627, in call_cpp_shape_fn require_shape_fn) File "/usr/lib/python2.7/site-packages/tensorflow/python/framework/common_shapes.py", line 691, in _call_cpp_shape_fn_impl raise ValueError(err.message) ValueError: indices.shape[-1] must be <= params.rank, but saw indices shape: [?,11] and params shape: [1,16] for 'ner/cond/GatherNd' (op: 'GatherNd') with input shapes: [1,16], [?,11].

gallupliu commented 6 years ago

这个情况应该是预测的时候数据张量和模型里保存的张量维度不一致导致的,另外,作者预测的时候,对label添加了placehoder

plb31949 commented 6 years ago

@jasonsalex 换成1.4版本试一下吧

wangqingbin commented 6 years ago

楼主,这个问题你解决了吗,我在运行预测的数据的时候也报了同样的错误

zeal4u commented 6 years ago

使用tf1.8.0及以上版本,可以修改util.py底下get_predict_iterator 函数中 fake_tag = tf.placeholder(tf.int32, [None, None])

guotong1988 commented 5 years ago

THX!