shiyybua / NER

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

训练后使用预测模型跑报参数错误 #16

Open chease3640 opened 6 years ago

chease3640 commented 6 years ago

请教下在同一套代码训练和预测的,为什么训练后去预测会保证错呢 WARNING:tensorflow:From D:\workspace\python_project\NER\package\utils.py:210: TextLineDataset.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 "D:\Python35\lib\site-packages\tensorflow\python\framework\common_shapes.py", line 686, in _call_cpp_shape_fn_impl input_tensors_as_shapes, status) File "D:\Python35\lib\site-packages\tensorflow\python\framework\errors_impl.py", line 473, in exit c_api.TF_GetCode(self.status.status)) tensorflow.python.framework.errors_impl.InvalidArgumentError: 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].

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "D:/workspace/python_project/NER/package/rnn.py", line 168, in net = NER_net("ner", iterator, embedding, BATCH_SIZE) File "D:/workspace/python_project/NER/package/rnn.py", line 28, in init self._build_net() File "D:/workspace/python_project/NER/package/rnn.py", line 68, in _build_net self.outputs, self.y, self.seq_length) File "D:\Python35\lib\site-packages\tensorflow\contrib\crf\python\ops\crf.py", line 201, in crf_log_likelihood transition_params) File "D:\Python35\lib\site-packages\tensorflow\contrib\crf\python\ops\crf.py", line 128, in crf_sequence_score fn2=_multi_seq_fn) File "D:\Python35\lib\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 "D:\Python35\lib\site-packages\tensorflow\python\util\deprecation.py", line 316, in new_func return func(*args, **kwargs) File "D:\Python35\lib\site-packages\tensorflow\python\ops\control_flow_ops.py", line 1894, in cond orig_res_t, res_t = context_t.BuildCondBranch(true_fn) File "D:\Python35\lib\site-packages\tensorflow\python\ops\control_flow_ops.py", line 1752, in BuildCondBranch original_result = fn() File "D:\Python35\lib\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 "D:\Python35\lib\site-packages\tensorflow\python\ops\gen_array_ops.py", line 2567, in gather_nd "GatherNd", params=params, indices=indices, name=name) File "D:\Python35\lib\site-packages\tensorflow\python\framework\op_def_library.py", line 787, in _apply_op_helper op_def=op_def) File "D:\Python35\lib\site-packages\tensorflow\python\framework\ops.py", line 3162, in create_op compute_device=compute_device) File "D:\Python35\lib\site-packages\tensorflow\python\framework\ops.py", line 3208, in _create_op_helper set_shapes_for_outputs(op) File "D:\Python35\lib\site-packages\tensorflow\python\framework\ops.py", line 2427, in set_shapes_for_outputs return _set_shapes_for_outputs(op) File "D:\Python35\lib\site-packages\tensorflow\python\framework\ops.py", line 2400, in _set_shapes_for_outputs shapes = shape_func(op) File "D:\Python35\lib\site-packages\tensorflow\python\framework\ops.py", line 2330, in call_with_requiring return call_cpp_shape_fn(op, require_shape_fn=True) File "D:\Python35\lib\site-packages\tensorflow\python\framework\common_shapes.py", line 627, in call_cpp_shape_fn require_shape_fn) File "D:\Python35\lib\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].

plb31949 commented 6 years ago

我遇到了同样的问题,我之前用的是最新的tenorflow1.6,换成1.4之后就好了

chease3640 commented 6 years ago

多谢你的提醒,我用的是tenorflow1.5,换个1.4的版本试试确实可以了,太感谢了!

MASTERPlECE commented 5 years ago

看看这个 https://github.com/shiyybua/NER/issues/8