$ hub install emotion_detection_textcnn==1.3.0
模型名称 | emotion_detection_textcnn |
---|---|
类别 | 文本-情感分析 |
网络 | TextCNN |
数据集 | 百度自建数据集 |
是否支持Fine-tuning | 否 |
模型大小 | 122MB |
最新更新日期 | 2021-02-26 |
数据指标 | - |
paddlepaddle >= 1.8.0
paddlehub >= 1.8.0
$ hub install emotion_detection_textcnn
$ hub run emotion_detection_textcnn --input_text "今天天气真好"
或者$ hub run emotion_detection_textcnn --input_file test.txt
test.txt 存放待预测文本, 如:
这家餐厅很好吃
这部电影真的很差劲
import paddlehub as hub
module = hub.Module(name="emotion_detection_textcnn")
test_text = ["今天天气真好", "湿纸巾是干垃圾", "别来吵我"]
results = module.emotion_classify(texts=test_text)
for result in results:
print(result['text'])
print(result['emotion_label'])
print(result['emotion_key'])
print(result['positive_probs'])
print(result['neutral_probs'])
print(result['negative_probs'])
# 今天天气真好 2 positive 0.9267 0.0714 0.0019
# 湿纸巾是干垃圾 1 neutral 0.0062 0.9896 0.0042
# 别来吵我 0 negative 0.0732 0.1477 0.7791
def emotion_classify(texts=[], data={}, use_gpu=False, batch_size=1)
emotion_detection_textcnn预测接口,预测输入句子的情感分类(三分类,积极/中立/消极)
参数
返回
def get_labels()
获取emotion_detection_textcnn的类别
返回
def get_vocab_path()
获取预训练时使用的词汇表
返回
PaddleHub Serving可以部署一个在线情感分析服务,可以将此接口用于在线web应用。
运行启动命令:
$ hub serving start -m emotion_detection_textcnn
启动时会显示加载模型过程,启动成功后显示
Loading emotion_detection_textcnn successful.
这样就完成了服务化API的部署,默认端口号为8866。
NOTE: 如使用GPU预测,则需要在启动服务之前,请设置CUDA_VISIBLE_DEVICES环境变量,否则不用设置。
配置好服务端,以下数行代码即可实现发送预测请求,获取预测结果
import requests
import json
# 待预测数据
text = ["这家餐厅很好吃", "这部电影真的很差劲"]
# 设置运行配置
# 对应本地预测emotion_detection_textcnn.emotion_classify(texts=text, batch_size=1, use_gpu=True)
data = {"texts": text, "batch_size": 1, "use_gpu":True}
# 指定预测方法为emotion_detection_textcnn并发送post请求,content-type类型应指定json方式
# HOST_IP为服务器IP
url = "http://HOST_IP:8866/predict/emotion_detection_textcnn"
headers = {"Content-Type": "application/json"}
r = requests.post(url=url, headers=headers, data=json.dumps(data))
# 打印预测结果
print(json.dumps(r.json(), indent=4, ensure_ascii=False))
1.0.0
初始发布
1.1.0
大幅提升预测性能
1.2.0
模型升级,支持用于文本分类,文本匹配等各种任务迁移学习
1.3.0
移除 Fluid API