🚀 对话情感识别 (ERC)
对话情感识别(ERC)项目旨在利用文本模态对对话中的情感进行准确分类。本项目在MELD和IEMOCAP两个数据集上进行了实验,具有较高的实用价值和研究意义。
🚀 快速开始
请查看此处获取详细信息。
观看演示视频!
✨ 主要特性
- 目前仅使用文本模态对对话中的情感进行分类。
- 在MELD和IEMOCAP两个数据集上进行实验,取得了较好的效果。
- 提供了EmoBERTa模型的训练和部署方法。
📦 安装指南
前提条件
- 一台x86 - 64的Unix或类Unix机器。
- Python 3.8或更高版本。
- 强烈建议在虚拟环境(如conda、virtualenv等)中运行,以免影响系统Python。
- 克隆[
multimodal - datasets
仓库](https://github.com/tae898/multimodal - datasets)(子模块)。
- 执行
pip install -r requirements.txt
安装依赖。
EmoBERTa训练
首先在train - erc - text.yaml
中配置超参数和数据集,然后在该目录下运行以下命令。建议在虚拟环境中运行。
python train-erc-text.py
此命令将依次调用train - erc - text - hp.py
和train - erc - text - full.py
。
💻 使用示例
训练结果
模型 |
配置 |
MELD加权f1分数 |
IEMOCAP加权f1分数 |
EmoBERTa |
无前后对话 |
63.46 |
56.09 |
|
仅含过去对话 |
64.55 |
68.57 |
|
仅含未来对话 |
64.23 |
66.56 |
|
含前后对话 |
65.61 |
67.42 |
|
→ 无说话者姓名 |
65.07 |
64.02 |
以上数值是五次随机种子运行的平均值。
如果您想查看更多训练测试细节,请查看./results/
。
如果您想下载训练好的检查点等文件,可以从这里下载,这是一个较大的压缩文件。
部署
Huggingface
我们已在Huggingface上发布了模型:
- [emoberta - base](https://huggingface.co/tae898/emoberta - base)
- [emoberta - large](https://huggingface.co/tae898/emoberta - large)
它们分别基于[RoBERTa - base](https://huggingface.co/roberta - base)和[RoBERTa - large](https://huggingface.co/roberta - large),在[MELD和IEMOCAP两个数据集](utterance - ordered - MELD_IEMOCAP.json)上进行训练。我们部署的模型既不考虑说话者信息,也不考虑前后对话,即每次仅对单个语句(如 "I love you")进行分类。
Flask应用
您可以将Flask RESTful服务器应用作为Docker容器运行,也可以作为Python脚本运行。
- 作为Docker容器运行(推荐)
有四个镜像可供选择:
docker run -it --rm -p 10006:10006 tae898/emoberta - base
docker run -it --rm -p 10006:10006 --gpus all tae898/emoberta - base - cuda
docker run -it --rm -p 10006:10006 tae898/emoberta - large
docker run -it --rm -p 10006:10006 --gpus all tae898/emoberta - large - cuda
- 在Python环境中运行
此方法不如Docker方法推荐。
首先运行
pip install -r requirements - deploy.txt
,然后运行app.py
,这是一个Flask RESTful服务器,用法如下:
app.py [-h] [--host HOST] [--port PORT] [--device DEVICE] [--model - type MODEL_TYPE]
例如:
python app.py --host 0.0.0.0 --port 10006 --device cpu --model - type emoberta - base
客户端
应用运行后,您可以向服务器发送文本。首先安装必要的包:pip install -r requirements - client.txt
,然后运行client.py,用法如下:
client.py [-h] [--url - emoberta URL_EMOBERTA] --text TEXT
例如:
python client.py --text "Emotion recognition is so cool!"
将输出:
{
"neutral": 0.0049800905,
"joy": 0.96399665,
"surprise": 0.018937444,
"anger": 0.0071516023,
"sadness": 0.002021492,
"disgust": 0.001495996,
"fear": 0.0014167271
}
📚 详细文档
故障排除
查找和解决问题的最佳方法是查看GitHub的问题标签。如果您找不到所需内容,请随时提出问题,我们会及时响应。
贡献
贡献使开源社区成为一个学习、启发和创造的绝佳场所。您的任何贡献都非常感谢。
- 分叉项目。
- 创建您的功能分支(
git checkout -b feature/AmazingFeature
)。
- 在根仓库目录下运行
make style && quality
,确保代码质量。
- 提交更改(
git commit -m 'Add some AmazingFeature'
)。
- 推送到分支(
git push origin feature/AmazingFeature
)。
- 打开拉取请求。
引用我们的工作
请查看论文。
@misc{kim2021emoberta,
title={EmoBERTa: Speaker-Aware Emotion Recognition in Conversation with RoBERTa},
author={Taewoon Kim and Piek Vossen},
year={2021},
eprint={2108.12009},
archivePrefix={arXiv},
primaryClass={cs.CL}
}
📄 许可证
本项目采用MIT许可证。
作者