Are you sure you want to delete this task? Once this task is deleted, it cannot be recovered.
wdxwj a91bd637fc | 2 years ago | |
---|---|---|
ascend310_infer | 2 years ago | |
infer | 2 years ago | |
modelarts | 2 years ago | |
script | 2 years ago | |
src | 2 years ago | |
.gitignore | 3 years ago | |
Dockerfile | 2 years ago | |
LICENSE | 3 years ago | |
README.md | 2 years ago | |
README_CN.md | 2 years ago | |
eval.py | 2 years ago | |
export.py | 2 years ago | |
postprocess.py | 2 years ago | |
preprocess.py | 2 years ago | |
requirements.txt | 3 years ago | |
roberta_en.encoder.json | 2 years ago | |
roberta_en.vocab.bpe | 2 years ago | |
roberta_en.vocab.txt | 2 years ago | |
train.py | 2 years ago |
情感分析旨在自动识别和提取文本中的倾向、立场、评价、观点等主观信息。它包含各式各样的任务,比如句子级情感分类、评价对象级情感分类、观点抽取、情绪分类等。情感分析是人工智能的重要研究方向,具有很高的学术价值。同时,情感分析在消费决策、舆情分析、个性化推荐等领域均有重要的应用,具有很高的商业价值。
近日,百度正式发布情感预训练模型SKEP(Sentiment Knowledge Enhanced Pre-training for Sentiment Analysis)。SKEP利用情感知识增强预训练模型, 在14项中英情感分析典型任务上全面超越SOTA,此工作已经被ACL 2020录用。
论文地址:https://arxiv.org/abs/2005.05635
为了方便研发人员和商业合作伙伴共享效果领先的情感分析技术,本次百度在Senta中开源了基于SKEP的情感预训练代码和中英情感预训练模型。而且,为了进一步降低用户的使用门槛,百度在SKEP开源项目中集成了面向产业化的一键式情感分析预测工具。用户只需要几行代码即可实现基于SKEP的情感预训练以及模型预测功能。
demo数据下载
下载demo数据用作SKEP训练和情感分析任务训练
sh download_en_data.sh # 英文测试数据
句子级情感分类数据集的说明
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 .
...
评价对象级情感分类数据集的说明
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
...
从官网下载安装MindSpore之后,您可以按照如下步骤进行训练和评估:
- 请先准备Roberta权重文件(ckpt)。通过设置环境变量DEVICE_ID和RANK_SIZE来决定是否使用分布式运行。
bash scripts/train.sh
.
└─senta
├─README.md
├─scripts
├─download_en_data.sh # 下载数据集
├─eval.sh # Ascend上单机验证脚本
├─train.sh # Ascend上单机训练脚本
├─src
├─common
├─register.py # 用于动态加载文件
├─rule.py # 命名、截断规则
├─data
├─data_set_reader
├─basic_dataset_reader_without_fields.py # 基础的task_reader
├─basic_dataset_reader.py # 一个基础的data_set_reader
├─ernie_onesentclassification_dataset_reader_en.py # SST_reader
├─roberta_twosentclassification_dataset_reader_en.py # Sem_L_reader
├─fild_reader
├─ernie_text_field_reader.py # text_reader
├─scalar_field_reader.py # scalar_reader
├─tokenizer
├─custom_tokenizer.py # 基础的分词器
├─tokenization_spm.py # 文本处理
├─tokenization_utils.py # 编码转换等工具
├─tokenization_wp.py # Gpt bpe tokenizer
├─tokenizer.py # tokenizer 基类
├─models
├─roberta_one_sent_classification_en.py # 模型
├─training
├─optimizer.py # 自定义学习率
├─utils
├─args.py # 参数解析模块
├─params.py # 参数清洗模块
├─util_helper.py # 文本处理
├─bert_model.py # BERT模型
├─make_dataset.py # 生成数据集
├─config.py # 参数配置
├─eval.py # 评估网络
├─train.py # 训练网络
└─export.py # 导出模型
用法:train.py [--job JOB] [--data_url DATA_URL] [----train_url TRAIN_URL]
选项:
--job job to be trained (SST-2 or Sem-L)
--data_url 数据集路径
--train_url 模型保存路径
用法:train.py [--job JOB] [--data_url DATA_URL] [----ckpt CKPT]
选项:
--job job to be trained (SST-2 or Sem-L)
--data_url 数据集路径
--ckpt 检查点文件保存路径
可以在config.py
文件中配置参数。
Parameters for optimization:
learning_rate 学习率
bash scripts/train.sh
注意如果所运行的数据集较大,建议添加一个外部环境变量,确保HCCL不会超时。
export HCCL_CONNECT_TIMEOUT=600
将HCCL的超时时间从默认的120秒延长到600秒。
注意若使用的BERT模型较大,保存检查点时可能会出现protobuf错误,可尝试使用下面的环境集。export PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python
无需修改配置,可直接在ModelArts上进行分布式训练。
bash scripts/train.sh
注意训练过程中会根据device_num和处理器总数绑定处理器内核。
运行以下命令前,确保已设置加载与训练检查点路径。请将检查点路径设置为绝对全路径,例如,/username/pretrain/checkpoint_100_300.ckpt。
python eval.py --data_url ./data/ --ckpt /username/pretrain/checkpoint_100_300.ckpt --job SST-2
python eval.py --data_url ./data/ --ckpt /username/pretrain/checkpoint_100_300.ckpt --job Sem-L
python export.py --ckpt_file [CKPT_PATH] --file_name [FILE_NAME] --file_format [FILE_FORMAT]
参数ckpt_file
是必需的,EXPORT_FORMAT
必须在 ["AIR", "MINDIR"]中进行选择。
参数 | Ascend | GPU |
---|---|---|
模型版本 | BERT_large | |
资源 | Ascend 910;CPU 2.60GHz,192核;内存 755GB;系统 Euler2.8 | |
上传日期 | 2020-08-22 | |
MindSpore版本 | 1.1.0 | |
数据集 | SST-2 | |
训练参数 | src/config.py | |
优化器 | Adam | |
损失函数 | SoftmaxCrossEntropy | |
输出 | 概率 | |
轮次 | 5 | |
Batch_size | 24 | |
损失 | 0.01 | |
速度 | 324毫秒/步 | |
总时长 | 80分钟 | |
参数(M) | 110 | |
微调检查点 | 1.3G(.ckpt文件) |
请浏览官网主页。
No Description
Text Python C++ Markdown Shell other
Dear OpenI User
Thank you for your continuous support to the Openl Qizhi Community AI Collaboration Platform. In order to protect your usage rights and ensure network security, we updated the Openl Qizhi Community AI Collaboration Platform Usage Agreement in January 2024. The updated agreement specifies that users are prohibited from using intranet penetration tools. After you click "Agree and continue", you can continue to use our services. Thank you for your cooperation and understanding.
For more agreement content, please refer to the《Openl Qizhi Community AI Collaboration Platform Usage Agreement》