语义角色标注分析的模型加载后,使用出问题

在使用语义角色标注分析功能的时候,使用如下python代码:

print(’===HanLP 语义角色标注分析=====================’)
tok = hanlp.load(hanlp.pretrained.tok.FINE_ELECTRA_SMALL_ZH)
tokResult = tok(sentence4)
sdp = hanlp.load(hanlp.pretrained.sdp.SEMEVAL16_NEWS_BIAFFINE_ZH)
print(‘模型载入成功:SEMEVAL16_NEWS_BIAFFINE_ZH’)
sdpResult = sdp(tokResult)
print(sdpResult)

=======================================
运行之后,系统出错,错误日志如下:

===HanLP 语义角色标注分析=====================
2022-04-07 11:59:10.041830: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library ‘cudart64_110.dll’; dlerror: cudart64_110.dll not found
2022-04-07 11:59:10.042593: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set up on your machine.
2022-04-07 11:59:14.804092: E tensorflow/stream_executor/cuda/cuda_driver.cc:271] failed call to cuInit: CUDA_ERROR_NO_DEVICE: no CUDA-capable device is detected
2022-04-07 11:59:14.810581: I tensorflow/stream_executor/cuda/cuda_diagnostics.cc:169] retrieving CUDA diagnostic information for host: ChengXiaobin
2022-04-07 11:59:14.810801: I tensorflow/stream_executor/cuda/cuda_diagnostics.cc:176] hostname: ChengXiaobin
2022-04-07 11:59:14.851886: I tensorflow/core/platform/cpu_feature_guard.cc:142] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations: AVX AVX2
To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.
模型载入成功:SEMEVAL16_NEWS_BIAFFINE_ZH
2022-04-07 11:59:19.098615: I tensorflow/compiler/mlir/mlir_graph_optimization_pass.cc:185] None of the MLIR Optimization Passes are enabled (registered 2)
2022-04-07 11:59:19.137981: W tensorflow/core/framework/op_kernel.cc:1680] Invalid argument: ValueError: not enough values to unpack (expected 4, got 3)
Traceback (most recent call last):

File “D:\py_proj_53git\kfai_nlp\venv\lib\site-packages\tensorflow\python\ops\script_ops.py”, line 249, in call
ret = func(*args)

File “D:\py_proj_53git\kfai_nlp\venv\lib\site-packages\tensorflow\python\autograph\impl\api.py”, line 645, in wrapper
return func(*args, **kwargs)

File “D:\py_proj_53git\kfai_nlp\venv\lib\site-packages\tensorflow\python\data\ops\dataset_ops.py”, line 892, in generator_py_func
values = next(generator_state.get_iterator(iterator_id))

File “D:\py_proj_53git\kfai_nlp\venv\lib\site-packages\hanlp\transform\conll_tf.py”, line 149, in generator
corpus = list(x for x in (samples() if callable(samples) else samples))

File “D:\py_proj_53git\kfai_nlp\venv\lib\site-packages\hanlp\transform\conll_tf.py”, line 149, in
corpus = list(x for x in (samples() if callable(samples) else samples))

File “D:\py_proj_53git\kfai_nlp\venv\lib\site-packages\hanlp\common\transform_tf.py”, line 157, in generator
yield from samples

File “D:\py_proj_53git\kfai_nlp\venv\lib\site-packages\hanlp\transform\conll_tf.py”, line 727, in inputs_to_samples
form, cpos, head, deprel = sample[0]

ValueError: not enough values to unpack (expected 4, got 3)

Traceback (most recent call last):
File “D:/py_proj_53git/kfai_nlp/scripts/research/rs_hanlp.py”, line 147, in
sdpResult = sdp(tokResult)
File “D:\py_proj_53git\kfai_nlp\venv\lib\site-packages\hanlp\common\component.py”, line 36, in call
return self.predict(*args, **kwargs)
File “D:\py_proj_53git\kfai_nlp\venv\lib\site-packages\hanlp\common\keras_component.py”, line 432, in predict
for idx, batch in enumerate(dataset):
File “D:\py_proj_53git\kfai_nlp\venv\lib\site-packages\tensorflow\python\data\ops\iterator_ops.py”, line 761, in next
return self._next_internal()
File “D:\py_proj_53git\kfai_nlp\venv\lib\site-packages\tensorflow\python\data\ops\iterator_ops.py”, line 747, in _next_internal
output_shapes=self._flat_output_shapes)
File “D:\py_proj_53git\kfai_nlp\venv\lib\site-packages\tensorflow\python\ops\gen_dataset_ops.py”, line 2727, in iterator_get_next
_ops.raise_from_not_ok_status(e, name)
File “D:\py_proj_53git\kfai_nlp\venv\lib\site-packages\tensorflow\python\framework\ops.py”, line 6941, in raise_from_not_ok_status
six.raise_from(core._status_to_exception(e.code, message), None)
File “”, line 3, in raise_from
tensorflow.python.framework.errors_impl.InvalidArgumentError: ValueError: not enough values to unpack (expected 4, got 3)
Traceback (most recent call last):

File “D:\py_proj_53git\kfai_nlp\venv\lib\site-packages\tensorflow\python\ops\script_ops.py”, line 249, in call
ret = func(*args)

File “D:\py_proj_53git\kfai_nlp\venv\lib\site-packages\tensorflow\python\autograph\impl\api.py”, line 645, in wrapper
return func(*args, **kwargs)

File “D:\py_proj_53git\kfai_nlp\venv\lib\site-packages\tensorflow\python\data\ops\dataset_ops.py”, line 892, in generator_py_func
values = next(generator_state.get_iterator(iterator_id))

File “D:\py_proj_53git\kfai_nlp\venv\lib\site-packages\hanlp\transform\conll_tf.py”, line 149, in generator
corpus = list(x for x in (samples() if callable(samples) else samples))

File “D:\py_proj_53git\kfai_nlp\venv\lib\site-packages\hanlp\transform\conll_tf.py”, line 149, in
corpus = list(x for x in (samples() if callable(samples) else samples))

File “D:\py_proj_53git\kfai_nlp\venv\lib\site-packages\hanlp\common\transform_tf.py”, line 157, in generator
yield from samples

File “D:\py_proj_53git\kfai_nlp\venv\lib\site-packages\hanlp\transform\conll_tf.py”, line 727, in inputs_to_samples
form, cpos, head, deprel = sample[0]

ValueError: not enough values to unpack (expected 4, got 3)

 [[{{node PyFunc}}]] [Op:IteratorGetNext]

Process finished with exit code 1

这个错误同样出现在SEMEVAL16_TEXT_BIAFFINE_ZH这个模型上。目前只有SEMEVAL16_ALL_ELECTRA_SMALL_ZH模型是可以使用的(_EN的没有去测)

请问这个问题是什么原因,看错误是参数缺失了。

1赞
  1. 《提问的智慧》 - Site Feedback - Butterfly Effect
  2. 无法复现:https://colab.research.google.com/drive/12um0-75yzwhCj2VMBt_Ise0oONRYK06o#scrollTo=FABZ2UWdr95s
  3. 猜测是你的tf版本问题,不要装其他版本
  4. https://github.com/hankcs/HanLP/blob/doc-zh/plugins/hanlp_demo/hanlp_demo/zh/sdp_stl.ipynb
2赞

1, 已阅读,明白
2. 应该是我本机环境,但是不知道具体哪个地方出问题
3. 在安装的时候,已经注意到论坛里面相关帖子提示,说是不要随便安装其他版本的,所以除了pip install hanlp[full], 没有做过其他的install。目前我的这个项目用的是单独的虚拟环境, python3.6 , tensorflow版本是2.6.0,不知道这个版本是否合适?


4、我看得就是这个文档

tf SDP模型的输入跟PyTorch的不一样,必须带词性:

1赞

好的,明白了,非常感谢,我之前可能忽略了demo目录下的源码,之后我会仔细参考的。