SiameseAOE通用信息抽取模型,基于提示(Prompt)+文本(Text)的构建思路,利用指针网络(Pointer Network)实现片段抽取(Span Extraction),从而实现各类属性情感抽取(ABSA)任务的抽取。该模型基于SiameseUIE框架,在500w条ABSA标注数据集进行预训练。
模型基于structbert-base-chinese在500w条ABSA标注数据集训练得到,模型框架如下图:
你可以使用该模型,实现各类属性情感抽取(ABSA)任务。
依据ModelScope的介绍,实验环境可分为两种情况。在此推荐使用第2种方式,点开就能用,省去本地安装环境的麻烦,直接体验ModelScope。
可参考ModelScope环境安装。
ModelScope直接集成了线上开发环境,用户可以直接在线训练、调用模型。
打开模型页面,点击右上角“在Notebook中打开”,选择机器型号后,即可进入线上开发环境。
import os
import json
from modelscope.trainers import build_trainer
from modelscope.msdatasets import MsDataset
from modelscope.utils.hub import read_config
from modelscope.metainfo import Metrics
from modelscope.utils.constant import DownloadMode
model_id = 'damo/nlp_structbert_siamese-aoe_chinese-base'
WORK_DIR = '/tmp'
train_dataset = MsDataset.load('absa_aoe', namespace='damo', split='train', download_mode=DownloadMode.FORCE_REDOWNLOAD)
eval_dataset = MsDataset.load('absa_aoe', namespace='damo', split='validation', download_mode=DownloadMode.FORCE_REDOWNLOAD)
max_epochs=3
kwargs = dict(
model=model_id,
train_dataset=train_dataset,
eval_dataset=eval_dataset,
max_epochs=max_epochs,
work_dir=WORK_DIR)
trainer = build_trainer('siamese-uie-trainer', default_args=kwargs)
print('===============================================================')
print('pre-trained model loaded, training started:')
print('===============================================================')
trainer.train()
print('===============================================================')
print('train success.')
print('===============================================================')
for i in range(max_epochs):
eval_results = trainer.evaluate(f'{WORK_DIR}/epoch_{i+1}.pth')
print(f'epoch {i} evaluation result:')
print(eval_results)
print('===============================================================')
print('evaluate success')
print('===============================================================')
from modelscope.pipelines import pipeline
from modelscope.utils.constant import Tasks
semantic_cls = pipeline(Tasks.siamese_uie, 'damo/nlp_structbert_siamese-aoe_chinese-base', model_revision='v1.0')
# AOE模型仅支持以下这几种Schema
# 属性情感抽取 {属性词: {情感词: None}}
semantic_cls(
input='很满意,音质很好,发货速度快,值得购买',
schema={
'属性词': {
'情感词': None,
}
}
)
# 允许属性词缺省,#表示缺省
semantic_cls(
input='#很满意,音质很好,发货速度快,值得购买',
schema={
'属性词': {
'情感词': None,
}
}
)
# 支持情感分类
semantic_cls(
input='很满意,音质很好,发货速度快,值得购买',
schema={
'属性词': {
"正向情感(情感词)": None,
"负向情感(情感词)": None,
"中性情感(情感词)": None
}
}
)
模型训练数据有限,在特定行业数据上,效果可能存在一定偏差。
@article{wang2019structbert,
title={Structbert: Incorporating language structures into pre-training for deep language understanding},
author={Wang, Wei and Bi, Bin and Yan, Ming and Wu, Chen and Bao, Zuyi and Xia, Jiangnan and Peng, Liwei and Si, Luo},
journal={arXiv preprint arXiv:1908.04577},
year={2019}
}
@inproceedings{Zhao2021AdjacencyLO,
title={Adjacency List Oriented Relational Fact Extraction via Adaptive Multi-task Learning},
author={Fubang Zhao and Zhuoren Jiang and Yangyang Kang and Changlong Sun and Xiaozhong Liu},
booktitle={FINDINGS},
year={2021}
}