cd ./model_files
# 以ERNIE 1.0 large(中文)作为初始化,训练的SKEP中文情感预训练模型(简写为SKEP-ERNIE1.0)
sh download_ernie_1.0_skep_large_ch.sh
# 以ERNIE 2.0 large(英文)作为初始化,训练的SKEP英文情感预训练模型(简写为SKEP-ERNIE2.0)
sh download_ernie_2.0_skep_large_en.sh
# 以RoBERTa large(英文)作为初始化,训练的SKEP英文情感预训练模型(简写为SKEP-RoBERTa)
sh download_roberta_skep_large_en.sh
demo数据下载
下载demo数据用作SKEP训练和情感分析任务训练
cd ./data/
sh download_ch_data.sh # 中文测试数据
sh download_en_data.sh # 英文测试数据
# 在SKEP-ERNIE1.0中文模型的基础上,继续pre-train
sh ./script/run_pretrain_ernie_1.0_skep_large_ch.sh
# 在SKEP-ERNIE2.0英文模型的基础上,继续pre-train
sh ./script/run_pretrain_ernie_2.0_skep_large_en.sh
# 在SKEP-RoBERTa英文模型的基础上,继续pre-train
sh ./script/run_pretrain_roberta_skep_large_en.sh
Finetune训练和预测句子级情感分类任务
# 基于SEKP-ERNIE1.0模型finetune训练和预测中文句子级情感分类任务,示例数据:ChnSentiCorp
sh ./script/run_train.sh ./config/ernie_1.0_skep_large_ch.Chnsenticorp.cls.json # finetune训练
sh ./script/run_infer.sh ./config/ernie_1.0_skep_large_ch.Chnsenticorp.infer.json # 预测
# 基于SKEP-ERNIE2.0模型finetune训练和预测英文句子级情感分类任务,示例数据:SST-2
sh ./script/run_train.sh ./config/ernie_2.0_skep_large_en.SST-2.cls.json # finetune训练
sh ./script/run_infer.sh ./config/ernie_2.0_skep_large_en.SST-2.infer.json # 预测
# 基于SKEP-RoBERTa模型finetune训练和预测英文句子级情感分类任务,示例数据:SST-2
sh ./script/run_train.sh ./config/roberta_skep_large_en.SST-2.cls.json # finetune训练
sh ./script/run_infer.sh ./config/roberta_skep_large_en.SST-2.infer.json # 预测
Finetune训练和预测评价对象级的情感分类任务
# 基于SKEP-ERNIE1.0模型finetune训练和预测中文评价对象级的情感分类任务,示例数据:SE-ABSA 16_PHNS
sh ./script/run_train.sh ./config/ernie_1.0_skep_large_ch.SE-ABSA16_PHNS.cls.json # finetune训练
sh ./script/run_infer.sh ./config/ernie_1.0_skep_large_ch.SE-ABSA16_PHNS.infer.json # 预测
# 基于SEKP-ERNIE2.0模型finetune训练和预测英文评价对象级的情感分类任务,示例数据:Sem-L
sh ./script/run_train.sh ./config/ernie_2.0_skep_large_en.absa_laptops.cls.json # finetune训练
sh ./script/run_infer.sh ./config/ernie_2.0_skep_large_en.absa_laptops.infer.json # 预测
# 基于SKEP-RoBERTa模型finetune训练和预测英文评价对象级的情感分类任务,示例数据:Sem-L
sh ./script/run_train.sh ./config/roberta_skep_large_en.absa_laptops.cls.json # finetune训练
sh ./script/run_infer.sh ./config/roberta_skep_large_en.absa_laptops.infer.json # 预测
Finetune训练和预测观点抽取或标注任务
# 基于SKEP-ERNIE1.0模型finetune训练和预测中文观点抽取任务,示例数据:COTE_BD
sh ./script/run_train.sh ./config/ernie_1.0_skep_large_ch.COTE_BD.oe.json # finetune训练
sh ./script/run_infer.sh ./config/ernie_1.0_skep_large_ch.COTE_BD.infer.json # 预测
# 基于SKEP-ERNIE2.0模型finetune训练和预测英文观点抽取任务,示例数据:MPQA
sh ./script/run_train.sh ./config/ernie_2.0_skep_large_en.MPQA.orl.json # finetune训练
sh ./script/run_infer.sh ./config/ernie_2.0_skep_large_en.MPQA.infer.json # 预测
# 基于SKEP-RoBERTa模型finetune训练和预测英文观点抽取任务,示例数据:MPQA
sh ./script/run_train.sh ./config/roberta_skep_large_en.MPQA.orl.json # finetune训练
sh ./script/run_infer.sh ./config/roberta_skep_large_en.MPQA.infer.json # 预测
qid label text_a
0 1 it 's a charming and often affecting journey .
1 0 unflinchingly bleak and desperate
2 1 allows us to hope that nolan is poised to embark a major career as a commercial yet inventive filmmaker .
...
qid text_a text_b label
0 Boot time Boot time is super fast, around anywhere from 35 seconds to 1 minute. 0
1 tech support tech support would not fix the problem unless I bought your plan for $150 plus. 1
2 Set up Set up was easy. 0
3 Windows 8 Did not enjoy the new Windows 8 and touchscreen functions. 1
...
...
B I O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O 张 莉 , 女 , 祖 籍 四 川 , 1982 年 考 入 西 安 美 术 学 院 工 艺 系 , 1986 留 校 任 教 至 今 。
O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B I O O O O O O O O O O O O O O O O O O 可 能 本 片 确 实 应 该 在 电 影 院 看 3d , 才 能 体 会 到 奥 斯 卡 对 其 那 么 多 技 术 的 表 扬 , 也 才 能 体 会 到 马 丁 想 用 技 术 的 进 步 对 老 电 影 致 敬 的 用 意 [UNK] 最 近 听 说 《 雨 果 》 五 月 国 内 排 片 , 想 说 : 广 电 搞 毛 啊 ! 。
O B I I O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O 《 笑 忘 书 》 是 由 林 夕 作 词 , c . y . kong 作 曲 , 王 菲 演 唱 的 一 首 歌 , 收 录 于 专 辑 《 寓 言 》 中 。
B I I O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O 龙 泉 寺 中 精 致 的 壁 画 , 近 前 观 看 每 位 人 物 面 部 表 情 都 表 现 得 栩 栩 如 生 , 文 革 中 部 分 被 损 坏 后 来 修 复 。
...
...
O O O B_H B_DS B_T I_T I_T I_T I_T I_T I_T I_T I_T I_T I_T I_T I_T I_T I_T I_T I_T I_T I_T I_T I_T I_T I_T I_T O O O O O In most cases he described the legal punishments like floggings and executions of murderers and major drug traffickers that are applied based on the Shria , or Islamic law as human rights violations .
O O O O B_H B_DS I_DS I_DS I_DS I_DS B_T O O O O O O O In other cases , he made unfounded charges by accusing Iran of discrimination against women and minorities .
B_H B_DS I_DS I_DS O O O O O O O O O O O O O O O O O O O O He made such charges despite the fact that women 's political , social and cultural participation is not less than that of men .
O O O B_H B_DS O O O O O B_T I_T I_T I_T I_T I_T I_T I_T I_T O O O O O O O O O O O O O For instance , he denounced as a human rights violation the banning and seizure of satellite dishes in Iran , while the measure has been taken in line with the law .
...
论文效果复现
基于该项目可以实现对于论文 Sentiment Knowledge Enhanced Pre-training for Sentiment Analysis 效果的复现。下面给出论文效果的复现方法示例:
#下载以Roberta作为初始化,训练的SKEP英文情感预训练模型(简写为SKEP-RoBERTa)
sh download_roberta_skep_large_en.sh
#基于SKEP-RoBERTa模型finetune训练和预测英文句子级情感分类任务(示例数据:SST-2)
sh ./script/run_train.sh ./config/roberta_skep_large_en.SST-2.cls.json # finetune训练
sh ./script/run_infer.sh ./config/roberta_skep_large_en.SST-2.infer.json # 预测
#基于SKEP-RoBERTa模型finetune训练和预测英文评价对象级的情感分类任务(示例数据:Sem-L)
sh ./script/run_train.sh ./config/roberta_skep_large_en.absa_laptops.cls.json # finetune训练
sh ./script/run_infer.sh ./config/roberta_skep_large_en.absa_laptops.infer.json # 预测
#基于SKEP-RoBERTa模型finetune训练和预测英文观点抽取任务(示例数据:MPQA)
sh ./script/run_train.sh ./config/roberta_skep_large_en.MPQA.orl.json # finetune训练
sh ./script/run_infer.sh ./config/roberta_skep_large_en.MPQA.infer.json # 预测
注:如需要复现论文数据集结果,请参考论文修改对应任务的参数设置。
文献引用
如需使用该项目中的代码、模型或是方法,请在相关文档、论文中引用我们的工作。
@inproceedings{tian-etal-2020-skep,
title = "{SKEP}: Sentiment Knowledge Enhanced Pre-training for Sentiment Analysis",
author = "Tian, Hao and
Gao, Can and
Xiao, Xinyan and
Liu, Hao and
He, Bolei and
Wu, Hua and
Wang, Haifeng and
wu, feng",
booktitle = "Proceedings of the 58th Annual Meeting of the Association for Computational Linguistics",
month = jul,
year = "2020",
address = "Online",
publisher = "Association for Computational Linguistics",
url = "https://www.aclweb.org/anthology/2020.acl-main.374",
pages = "4067--4076",
abstract = "Recently, sentiment analysis has seen remarkable advance with the help of pre-training approaches. However, sentiment knowledge, such as sentiment words and aspect-sentiment pairs, is ignored in the process of pre-training, despite the fact that they are widely used in traditional sentiment analysis approaches. In this paper, we introduce Sentiment Knowledge Enhanced Pre-training (SKEP) in order to learn a unified sentiment representation for multiple sentiment analysis tasks. With the help of automatically-mined knowledge, SKEP conducts sentiment masking and constructs three sentiment knowledge prediction objectives, so as to embed sentiment information at the word, polarity and aspect level into pre-trained sentiment representation. In particular, the prediction of aspect-sentiment pairs is converted into multi-label classification, aiming to capture the dependency between words in a pair. Experiments on three kinds of sentiment tasks show that SKEP significantly outperforms strong pre-training baseline, and achieves new state-of-the-art results on most of the test datasets. We release our code at https://github.com/baidu/Senta.",
}
English|简体中文
Senta目录
简介
情感分析旨在自动识别和提取文本中的倾向、立场、评价、观点等主观信息。它包含各式各样的任务,比如句子级情感分类、评价对象级情感分类、观点抽取、情绪分类等。情感分析是人工智能的重要研究方向,具有很高的学术价值。同时,情感分析在消费决策、舆情分析、个性化推荐等领域均有重要的应用,具有很高的商业价值。
近日,百度正式发布情感预训练模型SKEP(Sentiment Knowledge Enhanced Pre-training for Sentiment Analysis)。SKEP利用情感知识增强预训练模型, 在14项中英情感分析典型任务上全面超越SOTA,此工作已经被ACL 2020录用。
论文地址:https://arxiv.org/abs/2005.05635
为了方便研发人员和商业合作伙伴共享效果领先的情感分析技术,本次百度在Senta中开源了基于SKEP的情感预训练代码和中英情感预训练模型。而且,为了进一步降低用户的使用门槛,百度在SKEP开源项目中集成了面向产业化的一键式情感分析预测工具。用户只需要几行代码即可实现基于SKEP的情感预训练以及模型预测功能。
SKEP
SKEP是百度研究团队提出的基于情感知识增强的情感预训练算法,此算法采用无监督方法自动挖掘情感知识,然后利用情感知识构建预训练目标,从而让机器学会理解情感语义。SKEP为各类情感分析任务提供统一且强大的情感语义表示。
百度研究团队在三个典型情感分析任务,句子级情感分类(Sentence-level Sentiment Classification),评价对象级情感分类(Aspect-level Sentiment Classification)、观点抽取(Opinion Role Labeling),共计14个中英文数据上进一步验证了情感预训练模型SKEP的效果。实验表明,以通用预训练模型ERNIE(内部版本)作为初始化,SKEP相比ERNIE平均提升约1.2%,并且较原SOTA平均提升约2%,具体效果如下表:
代码结构
一键化工具
为了降低用户的使用门槛,百度在SKEP开源项目中集成了面向产业化的一键式情感分析预测工具。具体安装和使用方法如下:
安装方法
本仓库支持pip安装和源码安装两种方式,使用pip或者源码安装时需要先安装PaddlePaddle,PaddlePaddle安装请参考安装文档。
pip安装
源码安装
使用方法
详细使用说明
项目下载
代码下载
下载代码库到本地
模型下载
下载情感分析预训练SKEP的中文模型和英文模型(本项目中开放了以ERNIE 1.0 large(中文)、ERNIE 2.0 large(英文)和RoBERTa large(英文)作为初始化,训练的中英文情感预训练模型)
demo数据下载
下载demo数据用作SKEP训练和情感分析任务训练
环境安装
PaddlePaddle 安装
本项目依赖于 PaddlePaddle 1.6.3,PaddlePaddle安装后,需要及时的将 CUDA、cuDNN、NCCL2 等动态库路径加入到环境变量 LD_LIBRARY_PATH 之中,否则训练过程中会报相关的库错误。具体的paddlepaddle配置细节请查阅这里 安装文档。
推荐使用pip安装方式
senta项目python包依赖
支持Python 3 的版本要求 3.7; 项目中其他python包依赖列在根目录下的requirements.txt文件中,使用以下命令安装:
环境变量添加
在./env.sh中修改环境变量,包括python、CUDA、cuDNN、NCCL2、PaddlePaddle相关环境变量,PaddlePaddle环境变量说明请参考 PaddlePaddle环境变量说明
模型训练和预测
Pre-train训练
Finetune训练和预测句子级情感分类任务
Finetune训练和预测评价对象级的情感分类任务
Finetune训练和预测观点抽取或标注任务
该代码同时支持用户进一步开发使用,可以根据配置文件中设置相关数据、模型、优化器,以及修改模型的超参数进行二次开发训练。
本代码库目前仅支持基于SKEP情感预训练模型进行训练和预测,如果用户希望使用Bow、CNN、LSTM等轻量级模型,请移步至Senta v1使用。
Demo数据集说明
该项目中使用的各数据集的说明、下载方法及使用样例如下:
句子级情感分类数据集
ChnSentiCorp是中文句子级情感分类数据集,包含酒店、笔记本电脑和书籍的网购评论。为方便使用demo数据中提供了完整数据,数据示例:
SST-2是英文句子情感分类数据集,主要由电影评论构成。为方便使用demo数据中提供了完整数据,数据集下载地址,数据示例:
评价对象级情感分类数据集
SE-ABSA16_PHNS是中文评价对象级情感分类数据集,主要由描述手机类别某个属性的商品用户评论构成。为方便使用demo数据中提供了完整数据,数据集下载地址,数据集示例如下:
Sem-L数据集是英文评价对象级情感分类数据集,主要由描述笔记本电脑类别某个属性的商品用户评论构成。为方便使用demo数据中提供了完整数据,数据集下载地址,数据集示例如下:
观点抽取抽取数据集
COTE-BD数据集是中文互联网评论数据集。为方便使用demo数据中提供了完整数据,数据集下载地址,数据集使用例子如下,其中为了方便模型使用,下面数据是将文本进行分词处理后结果,标签用BIO标记评论实体或者事件。
MPQA数据集是英文互联网评论数据集。为方便使用demo数据中提供了完整数据,数据集下载地址,数据集使用例子如下,其中为了方便模型使用需要将文本进行分词处理,标签用BIO标记评论内容、评论实体和实体内容表达主体。
论文效果复现
基于该项目可以实现对于论文 Sentiment Knowledge Enhanced Pre-training for Sentiment Analysis 效果的复现。下面给出论文效果的复现方法示例:
注:如需要复现论文数据集结果,请参考论文修改对应任务的参数设置。
文献引用
如需使用该项目中的代码、模型或是方法,请在相关文档、论文中引用我们的工作。