https://github.com/StanleyLsx/entity_extractor_by_binary_tagging
README.md
Entity Extractor By Binary Tagging
“半指针-半标注”方法实体的抽取器,基于苏神的三元组抽取方法改造,这里取消了三元组抽取模型中对s的抽取,直接抽取实体并做分类(相当于直接抽取p和o)。改造后的实体抽取方法不仅可以运用于短实体的抽取,也可以运用到长句实体的抽取。
环境
python 3.6.7
transformers3.0.2
torch1.6.0
其他环境见requirements.txt
更新历史
日期 版本 描述
2020-08-23 v1.0.0 初始仓库
2020-12-05 v1.1.0 代码结构调整
原理
模型原理图
运行
按照data中的格式整理好数据
[
{
“text”: “XAAAXXXBBXXCCCCCCCCCCCXX”,
“a”: “AAA”,
“b”: “BB”,
“c”: “CCCCCCCCCCC”
},
]
在system.config文件中配置好参数,其中class_name必须和json文件中的类别的key一致
class_name=[a,b,c]
选择训练模式
################ Status ################
mode=train
string: train/test/interactive_predict
根据结果调高或调低decision_threshold这个超参数(sigmoid的输出大于这个参数会被判定为实体的首/尾)
decision_threshold=0.5
运行main.py
结果
example_datasets1
example_datasets1
这里的数据模式比较简单,比较容易达到验证集拟合状态
example_datasets2
example_datasets2
当前模型这个人民日报的ner数据集效果不佳,需要近一步调参炼丹
测试
选择测试模式,程序会读取训练过程中最好的模型
################ Status ################
mode=interactive_predict
string: train/test/interactive_predict
交互测试结果如下
example_datasets1
img04
example_datasets2
img05
参考
用bert4keras做三元组抽取
A Novel Cascade Binary Tagging Framework for Relational Triple Extraction
公众号
相关问题欢迎在公众号反馈:
小贤算法屋
实验结果
本机报错:
RuntimeError: version_ <= kMaxSupportedFileFormatVersion INTERNAL ASSERT FAILED at …\caffe2\serialize\inline_container.cc:132, please report a bug to PyTorch. Attempted to read a PyTorch file with version 3, but the maximum supported version for reading is 2. Your PyTorch installation may be too old. (init at …\caffe2\serialize\inline_container.cc:132)
(no backtrace available)
大致是说 我的pytorch版本低,但是我的是1.8比作者要求的环境1.6要高
在实验室的机器上跑,成功
please input a sentence (enter [exit] to exit.)
上海中奥丽人投资有限公司 2006.02-2016.04 初高中物理老师 工作内容:1、根据公司价格制度对所负责区域内直销客户进行业务洽谈
please input a sentence (enter [exit] to exit.)
{‘company’: [‘上海中奥丽人投资有限公司’], ‘position’: [‘初高中物理老师’], ‘detail’: [‘工作内容:1、根据公司价格制度对所负责区域内直销客户进行业务洽谈’]}
直接可以使用作者训练的模型,进行实体的预测。
输入一句话,预测出相应的实体结果。