PaddleNLP icon indicating copy to clipboard operation
PaddleNLP copied to clipboard

参照快递单信息抽取,自己训练ernie_crf 导出静态图异常

Open yaleimeng opened this issue 1 year ago • 7 comments

我参考waybill_ie快递单信息抽取示例项目构建数据集,按ernie+crf方案训练了序列标注模型,训练过程正常,输出的 ernie_crf_results.txt 文件预测也大部分都是准确的。

但是接下来不知道怎样加载checkpoint模型进行预测。。按readme指引经过export model导出之后,运行部署的predict.py,打印输出的预测结果很多都是错误的,比 ernie_crf_results.txt 里面预测效果差很多。————【经指点,似乎脚本是针对ernie+fc的,所以CRF层没有导出】

补充:尝试使用第二种方案ERNIE + FC训练,整个过程都符合预期了。但偶尔有些标签顺序不合逻辑,例如 xxx-B 后面跟着 yyy-I 。 我想直接加载checkpoint动态图进行一条或多条文本的预测,不知道如何操作?还是希望解决ernie_crf模型的实际预测问题。(麻烦提供导出静态模型代码,或者直接用checkpoint预测的代码)

yaleimeng avatar Jul 15 '22 07:07 yaleimeng

想问一下export_model的时候是不是没有改动代码了? 因为原始export_model.py主要是导出ernie系列的模型,但是没有导出crf的部分,所以可能是结果不一致的原因 image

run_ernie_crf.py模型里面是结构是ERNIE + CRF image

wawltor avatar Jul 15 '22 08:07 wawltor

哦,是的。用的原版export代码。。

yaleimeng avatar Jul 15 '22 08:07 yaleimeng

哦,是的。用的原版export代码。。 可以把构建模型的地方做一下替换

# Define the model netword and its loss
    ernie = AutoModelForTokenClassification.from_pretrained(
        "ernie-3.0-medium-zh", num_classes=len(label_vocab))
    model = ErnieCrfForTokenClassification(ernie)

wawltor avatar Jul 15 '22 08:07 wawltor

好的,非常感谢!

yaleimeng avatar Jul 15 '22 08:07 yaleimeng

@wawltor ernie+fc确实是可以正常导出,预测正常的。因为ernie+fc的checkpoint是目录结构,而另外两种则是单个文件。 经过模型定义代码的简单替换,bigru+crf和ernie+crf导出时都报错,依次如下图所示。。 建议为3个方案分别提供exportmodel.py 或者把三种结构的导出逻辑都写进去,执行时将对应关键词作为参数传递进去。 这样能降低小白探索的门槛。 image image

yaleimeng avatar Jul 15 '22 09:07 yaleimeng

请问题主,现在解决了嘛?遇到了同样的问题

shiwei0412 avatar Jul 22 '22 07:07 shiwei0412

没法解决。。唯一能用的就是ernie+fc。。但没有CRF又有标签异常的现象。 也不知道是什么风气,官方写的案例经常都有各种问题。。

yaleimeng avatar Jul 24 '22 02:07 yaleimeng

This issue is stale because it has been open for 60 days with no activity. 当前issue 60天内无活动,被标记为stale。

github-actions[bot] avatar Dec 08 '22 06:12 github-actions[bot]