一、背景:
免费的午餐当然没那么好。但也可以用用,解决很多问题了。
预训练模型大行其道,原因就是,大厂训练好的模型,发布小厂直接调用。省力省时
二、使用
百度:
1、百度的paddlehub
安装 pip install paddlehub
2、装好了调用
import paddlehub as hub
module = hub.Module(name="emotion_detection_textcnn")
test_text = ["今天天气真好", "湿纸巾是干垃圾", "别来吵我"]
results = module.emotion_classify(texts=test_text)
print(resutls)
# 会得到每个句子的情感分类,以及概率 probs
情感识别方面,PaddleHub现在这方面的模型有:
1 、二分类的模型,senta_lstm,senta_gru,senta_cnn,senta_bow,senta_bilstm,
2 、三分类的模型 emotion_detection_textcnn
3、有坑
如果你的服务有其他模型,要使用懒加载,不然会报错,
就是启动的时候不加载,调用的时候用hub.Module加载进来。
def sentiment_predict():
if self.model:
self.model = hub.Module(name="emotion_detection_textcnn")
else:
emotion_result = self.model.emotion_classify(data={"text": [text]})
追一科技:
https://github.com/ZhuiyiTechnology/pretrained-models
主要是用bert4keras
例子不要太多哦
https://github.com/bojone/bert4keras/tree/master/examples