Giter VIP home page Giter VIP logo

senta's Introduction

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%,具体效果如下表:

任务 数据集合 语言 指标 原SOTA SKEP 数据集地址
句子级情感
分类
SST-2 英文 ACC 97.50 97.60 下载地址
Amazon-2 英文 ACC 97.37 97.61 下载地址
ChnSentiCorp 中文 ACC 95.80 96.50 下载地址
NLPCC2014-SC 中文 ACC 78.72 83.53 下载地址
评价对象级的
情感分类
Sem-L 英文 ACC 81.35 81.62 下载地址
Sem-R 英文 ACC 87.89 88.36 下载地址
AI-challenge 中文 F1 72.87 72.90 暂未开放
SE-ABSA16_PHNS 中文 ACC 79.58 82.91 下载地址
SE-ABSA16_CAME 中文 ACC 87.11 90.06 下载地址
观点
抽取
MPQA-H 英文 b-F1/p-F1 83.67/77.12 86.32/81.11 下载地址
MPQA-T 英文 b-F1/p-F1 81.59/73.16 83.67/77.53 下载地址
COTE_BD 中文 F1 82.17 84.50 下载地址
COTE_MFW 中文 F1 86.18 87.90 下载地址
COTE_DP 中文 F1 84.33 86.30 下载地址

代码结构

.
├── README.md
├── requirements.txt
├── senta                    # senta核心代码,包括模型、输出reader、分词方法等
├── script                   # 情感分析各任务入口启动脚本,通过调用配置文件完成模型的训练和预测
├── config                   # 任务配置文件目录,在配置文件中设定模型的方法、超参数、数据等

一键化工具

为了降低用户的使用门槛,百度在SKEP开源项目中集成了面向产业化的一键式情感分析预测工具。具体安装和使用方法如下:

安装方法

本仓库支持pip安装和源码安装两种方式,使用pip或者源码安装时需要先安装PaddlePaddle,PaddlePaddle安装请参考安装文档

  1. pip安装
python -m pip install Senta
  1. 源码安装
git clone https://github.com/baidu/Senta.git
cd Senta
python -m pip install .

使用方法

from senta import Senta

my_senta = Senta()

# 获取目前支持的情感预训练模型, 我们开放了以ERNIE 1.0 large(中文)、ERNIE 2.0 large(英文)和RoBERTa large(英文)作为初始化的SKEP模型
print(my_senta.get_support_model()) # ["ernie_1.0_skep_large_ch", "ernie_2.0_skep_large_en", "roberta_skep_large_en"]

# 获取目前支持的预测任务
print(my_senta.get_support_task()) # ["sentiment_classify", "aspect_sentiment_classify", "extraction"]

# 选择是否使用gpu
use_cuda = True # 设置True or False

# 预测中文句子级情感分类任务
my_senta.init_model(model_class="ernie_1.0_skep_large_ch", task="sentiment_classify", use_cuda=use_cuda)
texts = ["中山大学是岭南第一学府"]
result = my_senta.predict(texts)
print(result)

# 预测中文评价对象级的情感分类任务
my_senta.init_model(model_class="ernie_1.0_skep_large_ch", task="aspect_sentiment_classify", use_cuda=use_cuda)
texts = ["百度是一家高科技公司"]
aspects = ["百度"]
result = my_senta.predict(texts, aspects)
print(result)

# 预测中文观点抽取任务
my_senta.init_model(model_class="ernie_1.0_skep_large_ch", task="extraction", use_cuda=use_cuda)
texts = ["唐 家 三 少 , 本 名 张 威 。"]
result = my_senta.predict(texts, aspects)
print(result)

# 预测英文句子级情感分类任务(基于SKEP-ERNIE2.0模型)
my_senta.init_model(model_class="ernie_2.0_skep_large_en", task="sentiment_classify", use_cuda=use_cuda)
texts = ["a sometimes tedious film ."]
result = my_senta.predict(texts)
print(result)

# 预测英文评价对象级的情感分类任务(基于SKEP-ERNIE2.0模型)
my_senta.init_model(model_class="ernie_2.0_skep_large_en", task="aspect_sentiment_classify", use_cuda=use_cuda)
texts = ["I love the operating system and the preloaded software."]
aspects = ["operating system"]
result = my_senta.predict(texts, aspects)
print(result)

# 预测英文观点抽取任务(基于SKEP-ERNIE2.0模型)
my_senta.init_model(model_class="ernie_2.0_skep_large_en", task="extraction", use_cuda=use_cuda)
texts = ["The JCC would be very pleased to welcome your organization as a corporate sponsor ."]
result = my_senta.predict(texts)
print(result)

# 预测英文句子级情感分类任务(基于SKEP-RoBERTa模型)
my_senta.init_model(model_class="roberta_skep_large_en", task="sentiment_classify", use_cuda=use_cuda)
texts = ["a sometimes tedious film ."]
result = my_senta.predict(texts)
print(result)

# 预测英文评价对象级的情感分类任务(基于SKEP-RoBERTa模型)
my_senta.init_model(model_class="roberta_skep_large_en", task="aspect_sentiment_classify", use_cuda=use_cuda)
texts = ["I love the operating system and the preloaded software."]
aspects = ["operating system"]
result = my_senta.predict(texts, aspects)
print(result)

# 预测英文观点抽取任务(基于SKEP-RoBERTa模型)
my_senta.init_model(model_class="roberta_skep_large_en", task="extraction", use_cuda=use_cuda)
texts = ["The JCC would be very pleased to welcome your organization as a corporate sponsor ."]
result = my_senta.predict(texts)
print(result)

详细使用说明

项目下载

  1. 代码下载

    下载代码库到本地

    git clone https://github.com/baidu/Senta.git
  2. 模型下载

    下载情感分析预训练SKEP的中文模型和英文模型(本项目中开放了以ERNIE 1.0 large(中文)ERNIE 2.0 large(英文)RoBERTa large(英文)作为初始化,训练的中英文情感预训练模型)

    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
  3. demo数据下载

    下载demo数据用作SKEP训练和情感分析任务训练

    cd ./data/
    sh download_ch_data.sh # 中文测试数据
    sh download_en_data.sh # 英文测试数据

环境安装

  1. PaddlePaddle 安装

    本项目依赖于 PaddlePaddle 1.6.3,PaddlePaddle安装后,需要及时的将 CUDA、cuDNN、NCCL2 等动态库路径加入到环境变量 LD_LIBRARY_PATH 之中,否则训练过程中会报相关的库错误。具体的paddlepaddle配置细节请查阅这里 安装文档

    推荐使用pip安装方式

    python -m pip install paddlepaddle-gpu==1.6.3.post107 -i https://mirror.baidu.com/pypi/simple
  2. senta项目python包依赖

    支持Python 3 的版本要求 3.7; 项目中其他python包依赖列在根目录下的requirements.txt文件中,使用以下命令安装:

    python -m pip install -r requirements.txt
  3. 环境变量添加

    在./env.sh中修改环境变量,包括python、CUDA、cuDNN、NCCL2、PaddlePaddle相关环境变量,PaddlePaddle环境变量说明请参考 PaddlePaddle环境变量说明

模型训练和预测

  1. Pre-train训练

    #  在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
  2. 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 # 预测
  3. 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 # 预测
  4. 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 # 预测
  5. 该代码同时支持用户进一步开发使用,可以根据配置文件中设置相关数据、模型、优化器,以及修改模型的超参数进行二次开发训练。

  6. 本代码库目前仅支持基于SKEP情感预训练模型进行训练和预测,如果用户希望使用Bow、CNN、LSTM等轻量级模型,请移步至Senta v1使用。

Demo数据集说明

该项目中使用的各数据集的说明、下载方法及使用样例如下:

  1. 句子级情感分类数据集

    ChnSentiCorp是中文句子级情感分类数据集,包含酒店、笔记本电脑和书籍的网购评论。为方便使用demo数据中提供了完整数据,数据示例:

     qid	label	text_a
     0	1	這間酒店環境和服務態度亦算不錯,但房間空間太小~~不宣容納太大件行李~~且房間格調還可以~~ 中餐廳的廣東點心不太好吃~~要改善之~~~~但算價錢平宜~~可接受~~ 西餐廳格調都很好~~但吃的味道一般且令人等得太耐了~~要改善之~~
     1	<荐书> 推荐所有喜欢<红楼>的红迷们一定要收藏这本书,要知道当年我听说这本书的时候花很长时间去图书馆找和借都没能如愿,所以这次一看到当当有,马上买了,红迷们也要记得备货哦!
     2	0	商品的不足暂时还没发现,京东的订单处理速度实在.......周二就打包完成,周五才发货...
     ...
    

    SST-2是英文句子情感分类数据集,主要由电影评论构成。为方便使用demo数据中提供了完整数据,数据集下载地址,数据示例:

    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 .
    ...
    
  2. 评价对象级情感分类数据集

    SE-ABSA16_PHNS是中文评价对象级情感分类数据集,主要由描述手机类别某个属性的商品用户评论构成。为方便使用demo数据中提供了完整数据,数据集下载地址,数据集示例如下:

    qid	label	text_a	text_b
    0	1	software#usability	刚刚入手8600,体会。刚刚从淘宝购买,1635元(包邮)。1、全新,应该是欧版机,配件也是正品全新。2、在三星官网下载了KIES,可用免费软件非常多,绝对够用。3、不到2000元能买到此种手机,知足了。
    1	1	display#quality	mk16i用后的体验感觉不错,就是有点厚,屏幕分辨率高,运行流畅,就是不知道能不能刷4.0的系统啊
    2	1	phone#operation_performance	mk16i用后的体验感觉不错,就是有点厚,屏幕分辨率高,运行流畅,就是不知道能不能刷4.0的系统啊
    ...
    

    Sem-L数据集是英文评价对象级情感分类数据集,主要由描述笔记本电脑类别某个属性的商品用户评论构成。为方便使用demo数据中提供了完整数据,数据集下载地址,数据集示例如下:

    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
    ...
    
  3. 观点抽取抽取数据集

    COTE-BD数据集是中文互联网评论数据集。为方便使用demo数据中提供了完整数据,数据集下载地址,数据集使用例子如下,其中为了方便模型使用,下面数据是将文本进行分词处理后结果,标签用BIO标记评论实体或者事件。

    ...
    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	龙 泉 寺 中 精 致 的 壁 画 , 近 前 观 看 每 位 人 物 面 部 表 情 都 表 现 得 栩 栩 如 生 , 文 革 中 部 分 被 损 坏 后 来 修 复 。
    ...
    

    MPQA数据集是英文互联网评论数据集。为方便使用demo数据中提供了完整数据,数据集下载地址,数据集使用例子如下,其中为了方便模型使用需要将文本进行分词处理,标签用BIO标记评论内容、评论实体和实体内容表达主体。

    ...
    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.",
}

senta's People

Contributors

chinaliuhao avatar dependabot[bot] avatar junjun315 avatar xfcygaocan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

senta's Issues

senta运行时,报错

FileNotFoundError: [Errno 2] No such file or directory: '/usr/local/Cellar/python/3.7.2_2/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/senta/model_files/ernie_1.0_skep_large_ch.Chnsenticorp.cls/save_inference_model/inference_step_601/infer_data_params.json'

Download ABSA Model Files

How can I download the model files for the trained aspect based sentiment classification? Following along with the quick tour in the README (link), I get the following error

Python 3.8.5 (default, Jul 28 2020, 12:59:40) 
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from senta import Senta
>>> my_senta = Senta()
>>> use_cuda=False
>>> my_senta.init_model(model_class="roberta_skep_large_en", task="aspect_sentiment_classify", use_cuda=use_cuda)
Traceback (most recent call last):
 File "<stdin>", line 1, in <module>
 File "/home/ryan/workspace/misc/senta/Senta/senta/train.py", line 205, in init_model
   param_dict = from_file(data_params_path)
 File "/home/ryan/workspace/misc/senta/Senta/senta/utils/params.py", line 47, in from_file
   file_dict = json.loads(evaluate_file(filename), strict=False)
 File "/home/ryan/workspace/misc/senta/Senta/senta/utils/params.py", line 42, in evaluate_file
   with open(filename, "r") as evaluation_file:
FileNotFoundError: [Errno 2] No such file or directory: '/home/ryan/workspace/misc/senta/Senta/senta/model_files/roberta_skep_large_en.absa_laptops.cls/save_inference_model/inference_step_74/infer_data_params.json'

I installed the package using the "From source" instructions here. My system is Ubuntu 20.04. Please let me know if you need any other info to help fix this.

train.py 195行 重复下载模型

train.py 第 195行,is_download_data = download_data(data_url, md5_url)
init_model 会反复下载模型,希望作者能解释一下为什么会有这样一个逻辑
我已经下载好所有模型,然后将该行注释掉,验证可以运行程序

发现了一个小bug,已修改

环境:windows下测试中文的ernie_1.0_skep_large_ch模型。
文件位置:senta/data/vocabulary.py
报错:UncodeDecodeError:'gbk' codec can't decode byte
行数: 30
代码:file_vocab = open(self.vocab_path)
改为:file_vocab = open(self.vocab_path, encoding='utf8')
即可修复。

Senta cannot find model when using `.py` scripts

Environment: Ubuntu 18.04 & PaddlePaddle 1.8.3.post107 & CUDA: 10.2

Initially, I install Senta and try it in the terminal.

It only works when the current folder is Senta (must run cd .../Senta), so if my python script is not in the folder Senta, the function model.init_model() will download model again. In addition, if the model has been downloaded when I tried it in the terminal, the Senta will fail to find the proper location of the model, and return a FileNotFoundError.

As a result, I rewrite the Senta/senta/train.py to fix this problem. Since GitHub doesn't support .py file type, I change the extension to .txt.

train.py.txt

Usage:

from package_fixed.train import Senta
model = Senta(installed_path="/home/cld/stockemo/Senta/senta")
model.init_model(model_class="ernie_1.0_skep_large_ch", task="sentiment_classify", use_cuda=True)

pip install问题

用pip install Senta安装,显示只有1.0.x版本,没有2.0版本

无法正常使用(Please compile with MKLDNN first to use MKLDNN)

OS:macOS catalina 10.15.6 (19G73)
Python:3.7.8

from senta import Senta
my_senta = Senta()
use_cuda =False
my_senta.init_model(model_class="ernie_1.0_skep_large_ch", task="sentiment_classify", use_cuda=use_cuda)

提示:E0910 08:57:15.549779 135937472 analysis_config.cc:190] Please compile with MKLDNN first to use MKLDNN

我用 brew install mkl-dnn 后还是提示这个错误。

安装错误

安装的过程报错,请问是咋回事
ERROR: Command errored out with exit status 1:
command: 'c:\python38\python.exe' -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\Users\xiaomililkx\AppData\Local\Temp\pip-install-0qhpg_2d\sentencepiece\setup.py'"'"'; file='"'"'C:\Users\xiaomililkx\AppData\Local\Temp\pip-install-0qhpg_2d\sentencepiece\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(file);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, file, '"'"'exec'"'"'))' egg_info --egg-base 'C:\Users\xiaomililkx\AppData\Local\Temp\pip-pip-egg-info-_cj1cx2r'
cwd: C:\Users\xiaomililkx\AppData\Local\Temp\pip-install-0qhpg_2d\sentencepiece
Complete output (7 lines):
Traceback (most recent call last):
File "", line 1, in
File "C:\Users\xiaomililkx\AppData\Local\Temp\pip-install-0qhpg_2d\sentencepiece\setup.py", line 29, in
with codecs.open(os.path.join('..', 'VERSION'), 'r', 'utf-8') as f:
File "c:\python38\lib\codecs.py", line 905, in open
file = builtins.open(filename, mode, buffering)
FileNotFoundError: [Errno 2] No such file or directory: '..\VERSION'
----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.

下载源码,运行模型报错

INFO: 07-22 21:55:27: lanch.py:77 * 140402907469632 nranks: 1
2020-07-22 21:55:34,702-INFO: proc 0 run failed
INFO: 07-22 21:55:34: lanch.py:112 * 140402907469632 proc 0 run failed
Traceback (most recent call last):
File "./lanch.py", line 130, in
main(lanch_args)
File "./lanch.py", line 123, in main
start_procs(args)
File "./lanch.py", line 114, in start_procs
cmd=cmds[i])
subprocess.CalledProcessError: Command '['/home/yangchen06/anaconda3/envs/paddle/bin/python', '-u', './train.py', '—param_path', './config/ernie_1.0_skep_large_ch.Chnsenticorp.cls.json', '—log_dir', './log']' returned non-zero exit status 1.

当数据量小于 batch_size 的时候,会出错

按照 README 中的脚本去进行 eval 的时候会出现

Traceback (most recent call last):
  File "sentiment_classify.py", line 288, in <module>
    main(args)
  File "sentiment_classify.py", line 273, in main
    args.model_path)
  File "sentiment_classify.py", line 210, in eval_net
    class2_acc = class2_acc / (total_count - neu_count)
ZeroDivisionError: float division by zero

经过分析发现是自带数据集中测试数据集只有 200 条, 而默认 batch_size 是 256, 而且因为代码使用的 batch 是 paddle.v2.batch 而不是 paddle.batch, (这个两个函数的实现一样,但是默认参数在 paddle.v2.batch 里面 drop_last 默认是 True, paddle.batch 里默认是 False), 所以会导致 test_reader 不会 yield.

建议更新代码,把 utils.py 中的

import paddle.v2 as paddle
改成 import paddle

或者在

utils.py101 和105 行中把

101      train_reader = paddle.batch(data_reader(data_path, word_dict, True), batch_size)
105      test_reader = paddle.batch(data_reader(data_path, word_dict, False), batch_size)

中加上 drop_last=False.

预训练报错

在SKEP-ERNIE1.0中文模型的基础上,继续pre-train
这一步报错
Traceback (most recent call last):
File "pretraining.py", line 359, in
main(args)
File "pretraining.py", line 351, in main
trainer = trainer_class(params, readers, model)
File "pretraining.py", line 152, in init
BaseTrainer.init(self, params, data_set_reader, model_class)
File "/home/pengjm/Senta/senta/training/base_trainer.py", line 48, in init
self.init_net()
File "/home/pengjm/Senta/senta/training/base_trainer.py", line 137, in init_net
self.init_train_net()
File "/home/pengjm/Senta/senta/training/base_trainer.py", line 161, in init_train_net
**opt_args)
File "/home/pengjm/Senta/senta/training/base_trainer.py", line 776, in optimization
_, param_grads = optimizer.minimize(loss)
File "", line 2, in minimize
File "/home/pengjm/.virtualenvs/paddle-venv/lib/python3.7/site-packages/paddle/fluid/dygraph/base.py", line 277, in impl
return func(*args, **kwargs)
File "/home/pengjm/.virtualenvs/paddle-venv/lib/python3.7/site-packages/paddle/fluid/optimizer.py", line 835, in minimize
no_grad_set=no_grad_set)
File "/home/pengjm/.virtualenvs/paddle-venv/lib/python3.7/site-packages/paddle/fluid/optimizer.py", line 673, in backward
loss.shape)
AssertionError: The loss.shape should be (1L,), but the current loss.shape is (-1,). Maybe that you should call fluid.layers.mean to process the current loss.
请问是什么原因?

使用方法 都无法运行

按照使用方法运行,模块名称不对,改为大写后报错,'Senta' object has no attribute 'get_support_model'

找不到文件

编译lac模块
克隆lac代码,修改Makefile

cd fluid_install_dir/third_party/install/
git clone https://github.com/baidu/lac

修改CMakeList.txt, 将:
SET(PADDLE_ROOT ../../../fluid_install_dir)
改为
SET(PADDLE_ROOT 你的PaddlePaddle Fluid Inference部署路径)

修改哪个文件夹下的cmakelist.txt? 在lac文件夹下的cmakelist.txt中没有找到SET(PADDLE_ROOT ../../../fluid_install_dir)这一句

关于文件中附带的文本预测准确率的问题

我是一个刚开始学习文本情感分析的新手,我在使用这个train训练文件训练后,其准确率即avg_acc能达到很高的值,将近0.99。但是之后模型评价和预测代码分析test文本时,三类情感分析的正确率很低,只有0.64。请问是怎么回事,有什么解决办法吗?
PS:直接训练三类情感标签的情况会出现更低的学习率,请问该怎么改

错别字

readme.md中
模型概览
nets.py 中包含一下模型:
应该该为
nets.py 中包含以下模型:

Out of memory error on GPU 0 应该如何修改呢

paddlepaddle的验证信息

fluid.install_check.run_check()
Running Verify Fluid Program ...
W1022 11:53:24.008435 13978 device_context.cc:236] Please NOTE: device: 0, CUDA Capability: 75, Driver API Version: 10.1, Runtime API Version: 10.0
W1022 11:53:24.010244 13978 device_context.cc:244] device: 0, cuDNN Version: 7.6.
Your Paddle Fluid works well on SINGLE GPU or CPU.
I1022 11:53:24.924460 13978 parallel_executor.cc:421] The number of CUDAPlace, which is used in ParallelExecutor, is 2. And the Program will be copied 2 copies
W1022 11:53:26.624143 13978 fuse_all_reduce_op_pass.cc:72] Find all_reduce operators: 2. To make the speed faster, some all_reduce ops are fused during training, after fusion, the number of all_reduce ops is 1.
I1022 11:53:26.624205 13978 build_strategy.cc:363] SeqOnlyAllReduceOps:0, num_trainers:1
I1022 11:53:26.624480 13978 parallel_executor.cc:285] Inplace strategy is enabled, when build_strategy.enable_inplace = True
I1022 11:53:26.624694 13978 parallel_executor.cc:315] Cross op memory reuse strategy is enabled, when build_strategy.memory_optimize = True or garbage collection strategy is disabled, which is not recommended
I1022 11:53:26.624883 13978 parallel_executor.cc:368] Garbage collection strategy is enabled, when FLAGS_eager_delete_tensor_gb = 0
Your Paddle Fluid works well on MUTIPLE GPU or CPU.
Your Paddle Fluid is installed successfully! Let's start deep Learning with Paddle Fluid now

cat env.sh
set -x
#在LD_LIBRARY_PATH中添加cuda库的路径
export LD_LIBRARY_PATH=/usr/local/cuda/lib64:$LD_LIBRARY_PATH
export LD_LIBRARY_PATH=/usr/local/cuda/extras/CUPTI/lib64:$LD_LIBRARY_PATH
#在LD_LIBRARY_PATH中添加cudnn库的路径
export LD_LIBRARY_PATH=/usr/local/cuda/lib64:$LD_LIBRARY_PATH
#需要先下载NCCL,然后在LD_LIBRARY_PATH中添加NCCL库的路径
export LD_LIBRARY_PATH=/usr/local/cuda/nccl/lib:$LD_LIBRARY_PATH
#如果FLAGS_sync_nccl_allreduce为1,则会在allreduce_op_handle中调用cudaStreamSynchronize(nccl_stream),这种模式在某些情况下可以获得更好的性能
export FLAGS_sync_nccl_allreduce=1
#表示分配的显存块占GPU总可用显存大小的比例,范围[0,1]
export FLAGS_fraction_of_gpu_memory_to_use=1
#选择要使用的GPU
export CUDA_VISIBLE_DEVICES=0,1
#表示是否使用垃圾回收策略来优化网络的内存使用,<0表示禁用,>=0表示启用
export FLAGS_eager_delete_tensor_gb=1.0
#是否使用快速垃圾回收策略
export FLAGS_fast_eager_deletion_mode=1
#垃圾回收策略释放变量的内存大小百分比,范围为[0.0, 1.0]
export FLAGS_memory_fraction_of_eager_deletion=1
#设置fluid路径
export PATH=fluid=/usr/local/lib/python3.7/site-packages/paddle/include/paddle/fluid:$PATH
#设置python
alias python=/usr/bin/python3
set +x

报错信息
Out of memory error on GPU 0. Cannot allocate 90.250244MB memory on GPU 0, available memory is only 25.062500MB.

Please check whether there is any other process using GPU 0.

  1. If yes, please stop them, or start PaddlePaddle on another GPU.
  2. If no, please try one of the following suggestions:
    1. Decrease the batch size of your model.
    2. FLAGS_fraction_of_gpu_memory_to_use is 1.00 now, please set it to a higher value but less than 1.0.
      The command is export FLAGS_fraction_of_gpu_memory_to_use=xxx.

at (/paddle/paddle/fluid/memory/detail/system_allocator.cc:151)
F1021 21:29:34.217520 13068 exception_holder.h:37] std::exception caught,


C++ Call Stacks (More useful to developers):

0 paddle::memory::detail::GPUAllocator::Alloc(unsigned long*, unsigned long)
1 paddle::memory::detail::BuddyAllocator::RefillPool(unsigned long)
2 paddle::memory::detail::BuddyAllocator::Alloc(unsigned long)
3 void* paddle::memory::legacy::Allocpaddle::platform::CUDAPlace(paddle::platform::CUDAPlace const&, unsigned long)
4 paddle::memory::allocation::NaiveBestFitAllocator::AllocateImpl(unsigned long)
5 paddle::memory::allocation::Allocator::Allocate(unsigned long)
6 paddle::memory::allocation::RetryAllocator::AllocateImpl(unsigned long)
7 paddle::memory::allocation::AllocatorFacade::Alloc(paddle::platform::Place const&, unsigned long)
8 paddle::memory::allocation::AllocatorFacade::AllocShared(paddle::platform::Place const&, unsigned long)
9 paddle::memory::AllocShared(paddle::platform::Place const&, unsigned long)
10 paddle::framework::Tensor::mutable_data(paddle::platform::Place, paddle::framework::proto::VarType_Type, unsigned long)
11 paddle::operators::MatMulKernel<paddle::platform::CUDADeviceContext, float>::Compute(paddle::framework::ExecutionContext const&) const
12 std::_Function_handler<void (paddle::framework::ExecutionContext const&), paddle::framework::OpKernelRegistrarFunctor<paddle::platform::CUDAPlace, false, 0ul, paddle::operators::MatMulKernel<paddle::platform::CUDADeviceContext, float>, paddle::operators::MatMulKernel<paddle::platform::CUDADeviceContext, double>, paddle::operators::MatMulKernel<paddle::platform::CUDADeviceContext, paddle::platform::float16> >::operator()(char const*, char const*, int) const::{lambda(paddle::framework::ExecutionContext const&)#1}>::_M_invoke(std::_Any_data const&, paddle::framework::ExecutionContext const&)
13 paddle::framework::OperatorWithKernel::RunImpl(paddle::framework::Scope const&, paddle::platform::Place const&, paddle::framework::RuntimeContext*) const
14 paddle::framework::OperatorWithKernel::RunImpl(paddle::framework::Scope const&, paddle::platform::Place const&) const
15 paddle::framework::OperatorBase::Run(paddle::framework::Scope const&, paddle::platform::Place const&)
16 paddle::framework::details::ComputationOpHandle::RunImpl()
17 paddle::framework::details::FastThreadedSSAGraphExecutor::RunOpSync(paddle::framework::details::OpHandleBase*)
18 paddle::framework::details::FastThreadedSSAGraphExecutor::RunOp(paddle::framework::details::OpHandleBase*, std::shared_ptr<paddle::framework::BlockingQueue > const&, unsigned long*)
19 std::_Function_handler<std::unique_ptr<std::__future_base::_Result_base, std::__future_base::_Result_base::_Deleter> (), std::__future_base::_Task_setter<std::unique_ptr<std::__future_base::_Result, std::__future_base::_Result_base::_Deleter>, void> >::_M_invoke(std::_Any_data const&)
20 std::__future_base::_State_base::_M_do_set(std::function<std::unique_ptr<std::__future_base::_Result_base, std::__future_base::_Result_base::_Deleter> ()>&, bool&)
21 ThreadPool::ThreadPool(unsigned long)::{lambda()#1}::operator()() const

实验复现出现的环境配置问题,env.sh

你好,我在尝试浮现你们的实验时,遇到了环境配置的问题。我根据个人电脑情况修改了env.sh文件,具体内容如下:
set -x
#在LD_LIBRARY_PATH中添加cuda库的路径
export LD_LIBRARY_PATH=/usr/local/cuda-10.0/lib64:$LD_LIBRARY_PATH
export LD_LIBRARY_PATH=/usr/local/cuda-10.0/extras/CUPTI/lib64:$LD_LIBRARY_PATH
#在LD_LIBRARY_PATH中添加cudnn库的路径
#export LD_LIBRARY_PATH=/home/work/cudnn/cudnn_v7.4/cuda/lib64:$LD_LIBRARY_PATH
export LD_LIBRARY_PATH=/usr/local/cuda/lib64:$LD_LIBRARY_PATH
#需要先下载NCCL,然后在LD_LIBRARY_PATH中添加NCCL库的路径
#export LD_LIBRARY_PATH=/home/work/nccl/nccl2.4.2_cuda10.1/lib:$LD_LIBRARY_PATH
export LD_LIBRARY_PATH=/usr/local/cuda/lib64:$LD_LIBARY_PATH
#如果FLAGS_sync_nccl_allreduce为1,则会在allreduce_op_handle中调用cudaStreamSynchronize(nccl_stream),这种模式在某些情况下可以获得更好的性能
export FLAGS_sync_nccl_allreduce=1
#表示分配的显存块占GPU总可用显存大小的比例,范围[0,1]
export FLAGS_fraction_of_gpu_memory_to_use=1
#选择要使用的GPU
export CUDA_VISIBLE_DEVICES=0
#表示是否使用垃圾回收策略来优化网络的内存使用,<0表示禁用,>=0表示启用
export FLAGS_eager_delete_tensor_gb=1.0
#是否使用快速垃圾回收策略
export FLAGS_fast_eager_deletion_mode=1
#垃圾回收策略释放变量的内存大小百分比,范围为[0.0, 1.0]
export FLAGS_memory_fraction_of_eager_deletion=1
#设置fluid路径
#export PATH=fluid=/home/work/python/bin:$PATH
#export PATH=fluid=/home/edward/anaconda3/envs/Paddle-Pytorch/bin:$PATH
export PATH=fluid=/home/edward/anaconda3/envs/Paddle-Pytorch/lib/python3.7/site-packages/paddle/include/paddle:$PATH
#设置python
#alias python=/home/work/python/bin/python
alias python=/home/edward/anaconda3/envs/Paddle-Pytorch/bin/python
set +x
~

但是在运行具体任务时,如: sh ./script/run_infer.sh ./config/roberta_skep_large_en.absa_laptops.infer.json
抛出了这样的错误:
Traceback (most recent call last):
File "./lanch.py", line 137, in
main(lanch_args)
File "./lanch.py", line 130, in main
start_procs(args)
File "./lanch.py", line 121, in start_procs
cmd=cmds[i])
subprocess.CalledProcessError: Command '['/home/edward/anaconda3/envs/Paddle-Pytorch/bin/python', '-u', './train.py', '--param_path', './config/ernie_1.0_skep_large_ch.Chnsenticorp.cls.json', '--log_dir', './log']' died with <Signals.SIGABRT: 6>.

接着我去检查lanch.py文件,我推断出有可能是我的环境参数的问题,但是官方给出的环境参数配置写的不明确,导致我不知道如何修改环境配置参数。望能够给出详细的环境配置过程 #8

例子中的aspect_sentiment是否有误?

开源先点个赞
但是例子中的aspect_sentiment是不是有误

In [8]: my_senta.init_model(model_class="ernie_1.0_skep_large_ch", task="aspect_
   ...: sentiment_classify", use_cuda=use_cuda)
   ...: texts = ["百度是一家高科技公司"]
   ...: aspects = ["高科技"]
   ...: result = my_senta.predict(texts, aspects)
   ...: print(result)
[('百度是一家高科技公司', 'negative')]

看了源码调用Senta.predict, 其中好像并没有在预测用到aspects

    def predict(self, texts_, aspects=None):
        """
        the sentiment classifier's function
        :param texts: a unicode string or a list of unicode strings.
        :return: sentiment prediction results.
        """
        if isinstance(texts_, text_type):
            texts_ = [texts_]

        if isinstance(aspects, text_type):
            aspects = [aspects]

        return_list = convert_texts_to_ids(texts_, self.tokenizer, self.max_seq_len, \
                self.truncation_type, self.padding_id)
        record_dict = structure_fields_dict(return_list, 0, need_emb=False)
        input_list = []
        for item in self.input_keys:
            kv = item.split("#")
            name = kv[0]
            key = kv[1]
            input_item = record_dict[InstanceName.RECORD_ID][key]
            input_list.append(input_item)
        inputs = [array2tensor(ndarray) for ndarray in input_list]
        result = self.inference.run(inputs)
        batch_result = self.model_class.parse_predict_result(result)
        results = []
        if self.inference_type == 'seq_lab':
            for text, probs in zip(texts_, batch_result):
                label = [self.label_map[l] for l in probs]
                results.append((text, label))
        else:
            for text, probs in zip(texts_, batch_result):
                label = self.label_map[np.argmax(probs)]
                results.append((text, label))
        return results

可否获得预测的分值?

感谢开源.

想问一下在预测正负向情感的同时,可否获取相应的倾向分值? 像百度开放平台上的api是可以获取的

谢谢!

咱依赖项能不能更新一下?

咱依赖项能不能更新一下?

全是==限定版本也太。。。。

matplotlib 3.3.1 requires numpy>=1.15, senta 2.0.0 requires numpy==1.14.5

还有这个python3.7的限制,是用了啥新特性吗?没有的话,麻烦考虑一下用3.6的人。

关于识别情感词的问题

请问代码中使用PMI和seed words找情感词(论文3.1节)的部分在哪里?没有找到相关内容,也没有搜到PMI/seed word等关键词。

当运行预训练模型训练代码时,出现如下错误:The loss.shape should be (1L,), but the current loss.shape is (-1,)

WARNING: 08-13 14:03:09: io.py:712 * 139843275020096 paddle.fluid.layers.py_reader() may be deprecated in the near future. Please use paddle.fluid.io.DataLoader.from_generator() instead.
/home/lbj/anaconda3/lib/python3.7/site-packages/paddle/fluid/clip.py:779: UserWarning: Caution! 'set_gradient_clip' is not recommended and may be deprecated in future! We recommend a new strategy: set 'grad_clip' when initializing the 'optimizer'. This method can reduce the mistakes, please refer to documention of 'optimizer'.
warnings.warn("Caution! 'set_gradient_clip' is not recommended "
Traceback (most recent call last):
File "pretraining.py", line 359, in
main(args)
File "pretraining.py", line 351, in main
trainer = trainer_class(params, readers, model)
File "pretraining.py", line 152, in init
BaseTrainer.init(self, params, data_set_reader, model_class)
File "/home/lbj/projects/Senta-master/senta/training/base_trainer.py", line 48, in init
self.init_net()
File "/home/lbj/projects/Senta-master/senta/training/base_trainer.py", line 137, in init_net
self.init_train_net()
File "/home/lbj/projects/Senta-master/senta/training/base_trainer.py", line 161, in init_train_net
**opt_args)
File "/home/lbj/projects/Senta-master/senta/training/base_trainer.py", line 776, in optimization
_, param_grads = optimizer.minimize(loss)
File "", line 2, in minimize
File "/home/lbj/anaconda3/lib/python3.7/site-packages/paddle/fluid/dygraph/base.py", line 277, in impl
return func(*args, **kwargs)
File "/home/lbj/anaconda3/lib/python3.7/site-packages/paddle/fluid/optimizer.py", line 835, in minimize
no_grad_set=no_grad_set)
File "/home/lbj/anaconda3/lib/python3.7/site-packages/paddle/fluid/optimizer.py", line 673, in backward
loss.shape)
AssertionError: The loss.shape should be (1L,), but the current loss.shape is (-1,). Maybe that you should call fluid.layers.mean to process the current loss.

环境:cuda-10.1 cudnn 7.5.0 nccl2.7.8 paddle-gpu 1.6.3.so107

can't find task.json

can't find task.json at task_group_json="./data/en/pretraining/roberta_skep_large_en/task.json"

init_model出错

感谢为百度开源这么先进的模型

但是我在运行实例的时候,出现了
UnicodeDecodeError: 'gbk' codec can't decode byte 0x8c in position 35: illegal multibyte sequence
这个错误,不知道是何原因导致。

aspect是否不支持

python3.7
senta 2.0.0
使用提供的案例,没有找到senta,pip或者源码安装,查看是Senta这个模块,而这个模块中不含有aspect级别分类,请问一下怎么再能实现aspect级别分类

FileNotFoundError: [Errno 2] No such file or directory: '..\\VERSION'

environment:

  • Windows 10 x64
  • python version:anaconda Python 3.8.3
  • paddlepaddle==1.8.5

command

pip install Senta -i https://mirror.baidu.com/pypi/simple

output

Processing c:\users\11031\documents\doc\pyltp\senta Collecting nltk==3.4.5 Using cached nltk-3.4.5.zip (1.5 MB) Collecting numpy==1.14.5 Using cached numpy-1.14.5.zip (4.9 MB) Collecting scikit-learn==0.20.4 Using cached scikit-learn-0.20.4.tar.gz (11.7 MB) Requirement already satisfied: scipy>=0.13.3 in d:\software\anaconda\lib\site-packages (from scikit-learn==0.20.4->Senta==2.0.0) (1.5.0) Collecting sentencepiece==0.1.83 Using cached sentencepiece-0.1.83.tar.gz (497 kB) ERROR: Command errored out with exit status 1: command: 'D:\software\anaconda\python.exe' -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\11031\\AppData\\Local\\Temp\\pip-install-4_uufyts\\sentencepiece_18e2d198d8004a81bf0d73416d152414\\setup.py'"'"'; __file__='"'"'C:\\Users\\11031\\AppData\\Local\\Temp\\pip-install-4_uufyts\\sentencepiece_18e2d198d8004a81bf0d73416d152414\\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base 'C:\Users\11031\AppData\Local\Temp\pip-pip-egg-info-t0ekqrkf' cwd: C:\Users\11031\AppData\Local\Temp\pip-install-4_uufyts\sentencepiece_18e2d198d8004a81bf0d73416d152414\ Complete output (7 lines): Traceback (most recent call last): File "<string>", line 1, in <module> File "C:\Users\11031\AppData\Local\Temp\pip-install-4_uufyts\sentencepiece_18e2d198d8004a81bf0d73416d152414\setup.py", line 29, in <module> with codecs.open(os.path.join('..', 'VERSION'), 'r', 'utf-8') as f: File "D:\software\anaconda\lib\codecs.py", line 905, in open file = builtins.open(filename, mode, buffering) FileNotFoundError: [Errno 2] No such file or directory: '..\\VERSION' ---------------------------------------- ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.

运行实例代码出错

在运行实例代码时报错
from senta import Senta
my_senta = Senta()
use_cuda = True
my_senta.init_model(model_class="ernie_1.0_skep_large_ch", task="sentiment_classify", use_cuda=use_cuda)
这一步没有报错,在
texts = ["中山大学是岭南第一学府"]
result = my_senta.predict(texts)
print(result)
这一步时,报了如下错误,不知道该如何修改。
TypeError: init(): incompatible constructor arguments. The following argument types are supported:
1. paddle.fluid.core_avx.PaddleTensor()

download.sh中模型准确率的问题

你好,我通过download.sh脚本下载了训练好的模型。并使用项目中/data/test_data/corpus.test 进行测试。

python3 sentiment_classify.py 
--test_data_path ./data/test_data/corpus.test 
--word_dict_path ./C-API/config/train.vocab 
--mode eval 
--model_path ./C-API/config/Senta

[test info] model_path: ./C-API/config/Senta, class2_acc: 0.662722, class3_acc: 0.515000

,二分类和三分类的准确率只有0.66和0.515,
请问一下是可能是什么原因?

按格式更换自定义数据集后,训练阶段报错

在样例数据运行通过的情况下
将corpus.train按照格式替换为自定义数据集train.txt
结果报错

Traceback (most recent call last): File "sentiment_classify.py", line 286, in <module> main(args) File "sentiment_classify.py", line 259, in main args.num_passes) File "sentiment_classify.py", line 151, in train_net fetch_list=[cost.name, acc.name]) File "/usr/local/lib/python2.7/dist-packages/paddle/fluid/executor.py", line 470, in run self.executor.run(program.desc, scope, 0, True, True) paddle.fluid.core.EnforceNotMet: Enforce failed. Expected lbl >= 0, but received lbl:-1 < 0:0. at [/paddle/paddle/fluid/operators/math/cross_entropy.cc:51] PaddlePaddle Call Stacks: 0 0x7f60d6b71796p paddle::platform::EnforceNotMet::EnforceNotMet(std::__exception_ptr::exception_ptr, char const*, int) + 486 1 0x7f60d761e05cp paddle::operators::math::CrossEntropyFunctor<paddle::platform::CPUDeviceContext, float>::operator()(paddle::platform::CPUDeviceContext const&, paddle::framework::Tensor*, paddle::framework::Tensor const*, paddle::framework::Tensor const*, bool, int) + 7260 2 0x7f60d7522f58p paddle::operators::CrossEntropyOpKernel<paddle::platform::CPUDeviceContext, float>::Compute(paddle::framework::ExecutionContext const&) const + 472 3 0x7f60d75230c3p std::_Function_handler<void (paddle::framework::ExecutionContext const&), paddle::framework::OpKernelRegistrarFunctor<paddle::platform::CPUPlace, false, 0ul, paddle::operators::CrossEntropyOpKernel<paddle::platform::CPUDeviceContext, float>, paddle::operators::CrossEntropyOpKernel<paddle::platform::CPUDeviceContext, double> >::operator()(char const*, char const*) const::{lambda(paddle::framework::ExecutionContext const&)#1}>::_M_invoke(std::_Any_data const&, paddle::framework::ExecutionContext const&) + 35 4 0x7f60d76ee20cp paddle::framework::OperatorWithKernel::RunImpl(paddle::framework::Scope const&, boost::variant<paddle::platform::CUDAPlace, paddle::platform::CPUPlace, paddle::platform::CUDAPinnedPlace, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_> const&) const + 492 5 0x7f60d76ea63fp paddle::framework::OperatorBase::Run(paddle::framework::Scope const&, boost::variant<paddle::platform::CUDAPlace, paddle::platform::CPUPlace, paddle::platform::CUDAPinnedPlace, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_> const&) + 255 6 0x7f60d6c3240ap paddle::framework::Executor::RunPreparedContext(paddle::framework::ExecutorPrepareContext*, paddle::framework::Scope*, bool, bool, bool) + 298 7 0x7f60d6c32e00p paddle::framework::Executor::Run(paddle::framework::ProgramDesc const&, paddle::framework::Scope*, int, bool, bool) + 128 8 0x7f60d6b5934dp 9 0x7f60d6ba3e14p pybind11::cpp_function::dispatcher(_object*, _object*, _object*) + 2596 10 0x4c37edp PyEval_EvalFrameEx + 31165 11 0x4b9ab6p PyEval_EvalCodeEx + 774 12 0x4c16e7p PyEval_EvalFrameEx + 22711 13 0x4b9ab6p PyEval_EvalCodeEx + 774 14 0x4c16e7p PyEval_EvalFrameEx + 22711 15 0x4c136fp PyEval_EvalFrameEx + 21823 16 0x4b9ab6p PyEval_EvalCodeEx + 774 17 0x4eb30fp 18 0x4e5422p PyRun_FileExFlags + 130 19 0x4e3cd6p PyRun_SimpleFileExFlags + 390 20 0x493ae2p Py_Main + 1554 21 0x7f60f7402830p __libc_start_main + 240 22 0x4933e9p _start + 41

不用CUDA时出现的问题

按照指示搭建环境,下载各种文件后直接跑和readme里一样的例子,唯一改变的是把use_cuda = True 改成False。尝试了很多改变都会回到这个key error错误信息:

代码:

预测中文句子级情感分类任务

my_senta.init_model(model_class="ernie_1.0_skep_large_ch", task="sentiment_classify", use_cuda=use_cuda)
texts = ["中山大学是岭南第一学府"]
result = my_senta.predict(texts)
print(result)

预测中文评价对象级的情感分类任务

my_senta.init_model(model_class="ernie_1.0_skep_large_ch", task="aspect_sentiment_classify", use_cuda=use_cuda)
texts = ["百度是一家高科技公司"]
aspects = ["百度"]
result = my_senta.predict(texts, aspects)
print(result)

预测中文观点抽取任务

my_senta.init_model(model_class="ernie_1.0_skep_large_ch", task="extraction", use_cuda=use_cuda)
texts = ["唐 家 三 少 , 本 名 张 威 。"]
result = my_senta.predict(texts, aspects)
print(result)


KeyError Traceback (most recent call last)
in
10 # 预测中文句子级情感分类任务
11
---> 12 my_senta.init_model(model_class="ernie_1.0_skep_large_ch", task="sentiment_classify", use_cuda=use_cuda)
13 texts = ["中山大学是岭南第一学府"]
14 result = my_senta.predict(texts)

/opt/anaconda3/envs/hsbc/lib/python3.7/site-packages/senta/train.py in init_model(self, model_class, task, use_cuda)
222 tokenizer_params["bpe_json_file"] = _get_abs_path(bpe_j_file)
223
--> 224 tokenizer_class = RegisterSet.tokenizer.getitem(tokenizer_name)
225 self.tokenizer = tokenizer_class(vocab_file=tokenizer_vocab_path,
226 split_char=" ",

/opt/anaconda3/envs/hsbc/lib/python3.7/site-packages/senta/common/register.py in getitem(self, key)
45 except Exception as e:
46 logging.error("module {key} not found: {e}")
---> 47 raise e
48
49 def contains(self, key):

/opt/anaconda3/envs/hsbc/lib/python3.7/site-packages/senta/common/register.py in getitem(self, key)
42 def getitem(self, key):
43 try:
---> 44 return self._dict[key]
45 except Exception as e:
46 logging.error("module {key} not found: {e}")

KeyError: 'FullTokenizer'

请问是哪里出错了呢?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.