当前位置: 首页 > news >正文

基于开源模型对文本和音频进行情感分析

应用场景

  1. 从商品详情页爬取商品评论,对其做舆情分析;
  2. 电话客服,对音频进行分析,做舆情分析;

通过开发相应的服务接口,进一步工程化;

模型选用

  • 文本,选用了通义实验室fine-tune的structBERT 模型,基于大众点评的评论数据进行训练,使用预训练模型进行推理,CPU 能跑,支持模型微调,基本上不用微调了,因为他是基于电商领域的数据集进行训练的,基本够用,可本地部署;

参考论文:

title: Incorporating language structures into pre-training for deep language understanding
author:Wang, Wei and Bi, Bin and Yan, Ming and Wu, Chen and Bao, Zuyi and Xia, Jiangnan and Peng, Liwei and Si, Luo
journal:arXiv preprint arXiv:1908.04577,
year:2019

版本依赖:

modelscope-lib 最新版本

推理代码:

semantic_cls = pipeline(Tasks.text_classification, 'damo/nlp_structbert_sentiment-classification_chinese-base')comment0 = '非常厚实的一包大米,来自遥远的东北,盘锦大米,应该不错的,密封性很好。卖家的服务真是贴心周到!他们提供了专业的建议,帮助我选择了合适的商品。物流速度也很快,让我顺利收到了商品。'
result0 = semantic_cls(input=comment0)
if result0['scores'][0] > result0['scores'][1]:print("'" + comment0 + "',属于" + result0["labels"][0] + "评价")
else:print("'" + comment0 + "',属于" + result0["labels"][1] + "评价")comment1 = '食物的口感还不错,不过店员的服务态度可以进一步改善一下。'
result1 = semantic_cls(input=comment1)
if result1['scores'][0] > result1['scores'][1]:print("'" + comment1 + "',属于" + result1["labels"][0] + "评价")
else:print("'" + comment1 + "',属于" + result1["labels"][1] + "评价")comment2 = '衣服尺码合适,色彩可以再鲜艳一些,客服响应速度一般。'
result2 = semantic_cls(input=comment2)
if result2['scores'][0] > result2['scores'][1]:print("'" + comment2 + "',属于" + result2["labels"][0] + "评价")
else:print("'" + comment2 + "',属于" + result2["labels"][1] + "评价")comment3 = '物流慢,售后不好,货品质量差。'
result3 = semantic_cls(input=comment3)
if result3['scores'][0] > result3['scores'][1]:print("'" + comment3 + "',属于" + result3["labels"][0] + "评价")
else:print("'" + comment3 + "',属于" + result3["labels"][1] + "评价")comment4 = '物流包装顺坏,不过客服处理速度比较快,也给了比较满意的赔偿。'
result4 = semantic_cls(input=comment4)
if result4['scores'][0] > result4['scores'][1]:print("'" + comment4 + "',属于" + result4["labels"][0] + "评价")
else:print("'" + comment4 + "',属于" + result4["labels"][1] + "评价")comment5 = '冰箱制冷噪声较大,制冷慢。'
result5 = semantic_cls(input=comment5)
if result5['scores'][0] > result5['scores'][1]:print("'" + comment5 + "',属于" + result5["labels"][0] + "评价")
else:print("'" + comment5 + "',属于" + result5["labels"][1] + "评价")comment6 = '买了一件刘德华同款鞋,穿在自己脚上不像刘德华,像扫大街的。'
result6 = semantic_cls(input=comment6)
if result6['scores'][0] > result6['scores'][1]:print("'" + comment6 + "',属于" + result6["labels"][0] + "评价")
else:print("'" + comment6 + "',属于" + result6["labels"][1] + "评价")

运行结果:

'非常厚实的一包大米,来自遥远的东北,盘锦大米,应该不错的,密封性很好。卖家的服务真是贴心周到!他们提供了专业的建议,帮助我选择了合适的商品。物流速度也很快,让我顺利收到了商品。',属于正面评价
'食物的口感还不错,不过店员的服务态度可以进一步改善一下。',属于正面评价
'衣服尺码合适,色彩可以再鲜艳一些,客服响应速度一般。',属于正面评价
'物流慢,售后不好,货品质量差。',属于负面评价
'物流包装顺坏,不过客服处理速度比较快,也给了比较满意的赔偿。',属于正面评价
'冰箱制冷噪声较大,制冷慢。',属于负面评价
'买了一件刘德华同款鞋,穿在自己脚上不像刘德华,像扫大街的。',属于负面评价

  • 音频,选用了通义实验室 fine-tune的emotion2vec微调模型,CPU 能跑,可本地部署;

参考论文:

title: Self-Supervised Pre-Training for Speech Emotion Representation
author:Ma, Ziyang and Zheng, Zhisheng and Ye, Jiaxin and Li, Jinchao and Gao, Zhifu and Zhang, Shiliang and Chen, Xie
journal:arXiv preprint arXiv:2312.15185
year:2023

开源地址:

Official PyTorch code for extracting features and training downstream models with emotion2vec: Self-Supervised Pre-Training for Speech Emotion Representation

版本依赖:

modelscope >= 1.11.1

funasr>=1.0.5

推理代码:

from funasr import AutoModelmodel = AutoModel(model="iic/emotion2vec_base_finetuned", model_revision="v2.0.4")wav_file = f"{model.model_path}/example/test.wav"
res = model.generate(wav_file, output_dir="./outputs", granularity="utterance", extract_embedding=False)
print(res)scores = res[0]["scores"]max_score = 0
max_index = 0
i = 0
for score in scores:if score > max_score:max_score = scoremax_index = ii += 1print("音频分析后,情感基调为:" + res[0]["labels"][max_index])

运行结果

rtf_avg: 0.263: 100%|██████████| 1/1 [00:02<00:00,  2.64s/it]
[{'key': 'rand_key_2yW4Acq9GFz6Y', 'labels': ['生气/angry', '厌恶/disgusted', '恐惧/fearful', '开心/happy', '中立/neutral', '其他/other', '难过/sad', '吃惊/surprised', '<unk>'], 'scores': [0.06824027001857758, 0.030794354155659676, 0.20301730930805206, 0.09666425734758377, 0.12219445407390594, 0.06753909587860107, 0.13648174703121185, 0.11873088777065277, 0.1563376784324646]}]


音频分析后,情感为:恐惧/fearful

Process finished with exit code 0

http://www.lryc.cn/news/304494.html

相关文章:

  • SQL中为什么不要使用1=1
  • python 几种常见的音频数据读取、保存方式
  • 关于msvcr120.dll丢失怎样修复的详细解决步骤方法分享,msvcr120.dll文件的相关内容
  • 简单几步通过DD工具把云服务器系统Linux改为windows
  • 使用 package.json 配置代理解决 React 项目中的跨域请求问题
  • 生成 Let‘s Encrypt 免费证书
  • int128的实现(基本完成)
  • 【linux】使用 acme.sh 实现了 acme 协议生成免费的SSL 证书
  • MACOS上面C/C++获取网卡索引,索引获取网卡接口名
  • 解决SSH远程登录开饭板出现密码错误问题
  • 什么时候用ref和reactive
  • Java实战:Spring Boot实现邮件发送服务
  • 重磅!MongoDB推出Atlas Stream Processing公共预览版
  • dell戴尔电脑灵越系列Inspiron 15 3520原厂Win11系统中文版/英文版
  • k8s(3)
  • Java多线程并发学习
  • Curfew e-Pass 管理系统存在Sql注入漏洞 附源代码
  • 记阿里云mysql丢表丢数据的实践记录
  • 自然语言转SQL的应用场景探索
  • Python学习笔记——PySide6设计GUI应用之UI与逻辑分离
  • 【智能家居入门2】(MQTT协议、微信小程序、STM32、ONENET云平台)
  • Java架构师之路九、设计模式:常见的设计模式,如单例模式、工厂模式、策略模式、桥接模式等
  • 【OpenAI官方课程】第三课:ChatGPT文本总结Summarizing
  • 跨越千年医学对话:用AI技术解锁中医古籍知识,构建能够精准问答的智能语言模型,成就专业级古籍解读助手(LLAMA)
  • 初识表及什么是数据表
  • 使用Docker部署DataX3.0+DataX-Web
  • 庖丁解牛-二叉树的遍历
  • 一文了解LM317T的引脚介绍、参数解读
  • 【2024.02.22】定时执行专家 V7.0 发布 - TimingExecutor V7.0 Release - 龙年春节重大更新版本
  • ☀️将大华摄像头画面接入Unity 【1】配置硬件和初始化摄像头