Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sentiment Analysis Application #1505

Merged
merged 37 commits into from
Dec 27, 2021
Merged

Sentiment Analysis Application #1505

merged 37 commits into from
Dec 27, 2021

Conversation

1649759610
Copy link
Contributor

PR types

New features

PR changes

Models

Description

add sentiment_analysis application.

@tianxin1860 tianxin1860 changed the title Mynlp Sentiment Analysis Application Dec 23, 2021
Copy link

@tianxin1860 tianxin1860 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

通篇中英文之间需要加 1 个空格

- 手把手搭建起 细粒度 情感分析系统:抽取语句中评论维度以及相应观点,并基于评价维度的粒度进行情感分析。
- 提供训练、预测、部署一站式能力。
- 效果好
- 基于情感分析建模的专属模型SKEP,解决通用模型对情感信息不敏感的痛点。

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

中英文字符间需要 1 个空格


针对以上提到的细粒度情感分析,我们提出的解决方案如下图所示。整个情感分析的过程包含两个阶段,依次是评论维度和观点抽取模型,细粒度情感分类模型。对于给定的一段文本,首先基于前者抽取出文本语句中潜在的评论维度以及该维度相应的评论观点,然后将评论维度、观点以及原始文本进行拼接,传给细粒度情感分类模型以识别出该评论维度的情感色彩。

这里需要提到的是,由于目前市面上的大多数模型是基于通用语料训练出来的,这些模型可能并不会对情感信息那么敏感。基于这样的考量,本项目使用了百度自研的SKEP预训练模型,其在预训练阶段便设计了多种情感信息相关的预训练目标进行训练。作为一种情感专属的模型,其更适合用来做上边提到的评论维度和观点抽取任务,以及细粒度情感分类任务。

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

中英文字符间需要 1 个空格


这里需要提到的是,由于目前市面上的大多数模型是基于通用语料训练出来的,这些模型可能并不会对情感信息那么敏感。基于这样的考量,本项目使用了百度自研的SKEP预训练模型,其在预训练阶段便设计了多种情感信息相关的预训练目标进行训练。作为一种情感专属的模型,其更适合用来做上边提到的评论维度和观点抽取任务,以及细粒度情感分类任务。

另外,本项目使用的是Large版的SKEP模型,考虑到企业用户在线上部署时会考虑到模型预测效率,所以本项目专门提供了一个通用版的小模型[PP-MiniLM](https://github.com/LiuChiachi/PaddleNLP/tree/add-ppminilm/examples/model_compression/PP-MiniLM)以及一套量化策略,用户可以使用相应情感数据集对PP-MinLM进行微调,然后进行量化,以达到更快的使用效率。

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

中英文字符间需要 1 个空格


这里需要提到的是,由于目前市面上的大多数模型是基于通用语料训练出来的,这些模型可能并不会对情感信息那么敏感。基于这样的考量,本项目使用了百度自研的SKEP预训练模型,其在预训练阶段便设计了多种情感信息相关的预训练目标进行训练。作为一种情感专属的模型,其更适合用来做上边提到的评论维度和观点抽取任务,以及细粒度情感分类任务。

另外,本项目使用的是Large版的SKEP模型,考虑到企业用户在线上部署时会考虑到模型预测效率,所以本项目专门提供了一个通用版的小模型[PP-MiniLM](https://github.com/LiuChiachi/PaddleNLP/tree/add-ppminilm/examples/model_compression/PP-MiniLM)以及一套量化策略,用户可以使用相应情感数据集对PP-MinLM进行微调,然后进行量化,以达到更快的使用效率。

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PP-MiniLM 要链接 PaddleNLP 的官方地址

- 效果好
- 基于情感分析建模的专属模型SKEP,解决通用模型对情感信息不敏感的痛点。
- 性能优
- 提供开源小模型以及配套优化策略,以解决大模型预测效率问题。

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • 提供开源小模型及量化加速方案,大幅提升预测性能。

python == 3.8
CUDA Version: 10.2
NVIDIA Driver Version: 440.64.00
GPU: Tesla V100

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

只需要 1 个空格吧?

```

### 3.2 数据说明
本项目需要训练两个阶段的模型:评论维度和观点抽取模型,细粒度情感分类模型。本次针对这抽取和分类模型,我们分别开源了Deomo数据:[data_ext](https://bj.bcebos.com/v1/paddlenlp/data/data_ext.tar.gz)和[data_cls](https://bj.bcebos.com/v1/paddlenlp/data/data_cls.tar.gz)。

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deomo -> Demo

```

### 3.6 小模型优化策略
本项目提供了一套基于[PP-MiniLM](https://github.com/LiuChiachi/PaddleNLP/tree/add-ppminilm/examples/model_compression/PP-MiniLM)中文特色小模型的细粒度情感分类解决方案。PP-MiniLM提供了一套完整的小模型优化方案:首先使用Task-agnostic的方式进行模型蒸馏、然后依托于[PaddleSlim](https://github.com/PaddlePaddle/PaddleSlim) 进行模型裁剪、模型量化等模型压缩技术,有效减小了模型的规模,加快了模型运行速度。

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PP-MiniLM 链接到官方地址


[1] [文本情感分析](https://baike.baidu.com/item/%E6%96%87%E6%9C%AC%E6%83%85%E6%84%9F%E5%88%86%E6%9E%90/19431243?fr=aladdin)

[2] [SKEP论文](https://aclanthology.org/2020.acl-main.374.pdf)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

论文的引用格式是否规范一下?

Copy link

@tianxin1860 tianxin1860 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. utils.py 感觉可以抽取出来作为共享模块。
  2. 直接新建 1 个 pp-minilm 子目录不确定用户是否容易理解?


## 1. 方案设计

本项目将针对语句中的维度级别进行情感分析,对于给定的一段文本,我们在基于评论维度和观点抽取模型抽取出评论维度和观点后,便可以有针对性的对各个维度进行评论。具体来讲,本实践将抽取出的评论维度和评论观点进行拼接,然后原始语句进行拼接作为一条独立的训练语句。

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

然后原始语句 -> 然后和原始语句

}
results.append(result)

# print results

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

没用的注释删掉吧

@@ -0,0 +1,31 @@
# Copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

utils.py 感觉可以抽出来作为共享模块?


### 2.2 架构&功能

针对以上提到的细粒度情感分析,我们提出的解决方案如下图所示。整个情感分析的过程包含两个阶段,依次是评论维度和观点抽取模型,细粒度情感分类模型。对于给定的一段文本,首先基于前者抽取出文本语句中潜在的评论维度以及该维度相应的评论观点,然后将评论维度、观点以及原始文本进行拼接,传给细粒度情感分类模型以识别出该评论维度的情感色彩。
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

评论维度 统一成 评价维度 吧

另外,本项目使用的是 Large 版的 SKEP 模型,考虑到企业用户在线上部署时会考虑到模型预测效率,所以本项目专门提供了一个通用版的小模型 [PP-MiniLM](https://github.com/LiuChiachi/PaddleNLP/tree/add-ppminilm/examples/model_compression/PP-MiniLM) 以及一套量化策略,用户可以使用相应情感数据集对 PP-MiniLM 进行微调,然后进行量化,以达到更快的使用效率。

<center> <img src="./imgs/sentiment_system.png" /></center>
<center>图1 情感分析系统图 </center>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

图说明需要居中下

├── run_export.sh # 动转静模型导出命令
├── run_static_predict.sh # 全流程静态图单条预测命令
├── requirements.txt # 环境依赖
└── README.md
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shell脚本和python脚本命名建议统一下;是否单建一个/predict的目录呢


### 3.1 运行环境和依赖安装
(1) 运行环境
除非特殊说明,本实验默认是在以下配置环境研发运行的:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这样的话,可以加一个环境依赖,python、paddlepaddle、paddlenlp等所有library的版本依赖。版本依赖一般是xx以上吧
格式比如:
python >= 3.6
paddlepaddle >= 2.2

@@ -0,0 +1,138 @@
# 情感分析
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

开头加下目录吧

```shell
.
├── data # 数据目录
├── checkpoints # 模型保存目录
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

是否需要checkpoints ?

```shell
.
├── data # 数据目录
├── checkpoints # 模型保存目录
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

是否需要checkpoints ?

@@ -0,0 +1,4 @@
numpy==1.19.5
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

版本依赖需要明确下是==,还是>=


本项目中,无论是评论维度和观点抽取模型,还是细粒度情感分类模型,使用的均是 Large 版的 SKEP 模型,考虑到企业用户在线上部署时会考虑到模型预测效率,所以本项目提供了开源小模型 [PP-MiniLM](https://github.com/PaddlePaddle/PaddleNLP/tree/develop/examples/model_compression/pp-minilm) 及量化加速方案,大幅提升预测性能。

在本项目中,我们基于 PP-MiniLM 中文特色小模型进行 fine-tune 细粒度情感分类模型、然后使用 [PaddleSlim](https://github.com/PaddlePaddle/PaddleSlim) 进行模型量化,减小模型规模,加快模型预测性能。
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

、-> ,

## 3. 对量化后的小模型进行性能测试

### 3.1 环境要求
本节需要使用安装有 Inference 预测库的 [PaddlePaddle 2.2.1](https://paddleinference.paddlepaddle.org.cn/user_guides/download_lib.html) 进行预测,请根据合适的机器环境进行下载安装。若想要得到明显的加速效果,推荐在 NVIDA Tensor Core GPU(如 T4、A10、A100) 上进行测试,若在 V 系列 GPU 卡上测试,由于其不支持 Int8 Tensor Core,将达不到预期的加速效果。
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inference -> Paddle Inference

```

### 3.6 小模型优化策略
本项目提供了一套基于 [PP-MiniLM](https://github.com/LiuChiachi/PaddleNLP/tree/add-ppminilm/examples/model_compression/PP-MiniLM) 中文特色小模型的细粒度情感分类解决方案。PP-MiniLM 提供了一套完整的小模型优化方案:首先使用 Task-agnostic 的方式进行模型蒸馏、然后依托于 [PaddleSlim](https://github.com/PaddlePaddle/PaddleSlim) 进行模型裁剪、模型量化等模型压缩技术,有效减小了模型的规模,加快了模型运行速度。
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里的链接需要改成官方的版本,而且目录我改成小写得了。
https://github.com/PaddlePaddle/PaddleNLP/tree/develop/examples/model_compression/pp-minilm


这里需要提到的是,由于目前市面上的大多数模型是基于通用语料训练出来的,这些模型可能并不会对情感信息那么敏感。基于这样的考量,本项目使用了百度自研的 SKEP 预训练模型,其在预训练阶段便设计了多种情感信息相关的预训练目标进行训练。作为一种情感专属的模型,其更适合用来做上边提到的评论维度和观点抽取任务,以及细粒度情感分类任务。

另外,本项目使用的是 Large 版的 SKEP 模型,考虑到企业用户在线上部署时会考虑到模型预测效率,所以本项目专门提供了一个通用版的小模型 [PP-MiniLM](https://github.com/LiuChiachi/PaddleNLP/tree/add-ppminilm/examples/model_compression/PP-MiniLM) 以及一套量化策略,用户可以使用相应情感数据集对 PP-MiniLM 进行微调,然后进行量化,以达到更快的使用效率。
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

链接地址要使用PaddlePaddle org的版本

@@ -0,0 +1,4 @@
numpy==1.19.5
tqdm==4.27.0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不能限制版本。会导致未来新框架版本用户冲突,我理解这些requirements都是不需要的,请删除。

@@ -0,0 +1,12 @@
export CUDA_VISIBLE_DEVICES=7
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

提交代码的时候这些CUDA VISIBLE都需要默认为0,默认外部单卡用户会运行失败

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不太理解为什么需要两个脚本区分batch和非batch的概念

print("default input_text:", input_text)
predictor.predict(input_text.strip().replace(" ", ""))

while True:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

为什么是用循环的方式呢?

np.random.seed(seed)


def compute_md5(file_path):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个函数没看到有用到?

@@ -0,0 +1,10 @@
export CUDA_VISIBLE_DEVICES=1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

VISIBILE DEVICES整统一一下到0

@@ -0,0 +1,63 @@
# 评论维度和观点抽取模型
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

可否简化为 『评论观点抽取』
与AI开放平台使用场景保持一致

@chenxiaozeng chenxiaozeng merged commit a93a047 into PaddlePaddle:develop Dec 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants