副问题[/!--empirenews.page--]
17行代码跑最新NLP模子?你也可以!
- 一台可以上网的电脑
- 根基的python代码阅读手段,用于修改几个模子参数
- 对百度中文NLP最新成就的粘稠乐趣
- Senta是百度NLP开放的中文情绪说明模子,可以用于举办中文句子的情绪说明,输出功效为{正向/中性/负向}中的一个,关于模子的布局细节,请查察Senta----github.com/PaddlePaddle/Paddlehub/demo/senta
- 本示例代码选择的是Senta-BiLSTM模子。
- 模子来历:Paddlehub简介
- PaddleHub是基于PaddlePaddle开拓的预实习模子打点器材,可以借助预实习模子更便捷地开展迁徙进修事变。
- 本次评测中只行使了预实习模子,没有举办fine-tune
- 代码运行情形:百度 AI studio
尝试代码
- 来自paddlehub/senta_demo.py
github:https://github.com/PaddlePaddle/PaddleHub/blob/release/v0.5.0/demo/senta/senta_demo.py
- from __future__ import print_function
- import json
- import os
- import six
- import paddlehub as hub
- if __name__ == "__main__":
- # 加载senta模子
- senta = hub.Module(name="senta_bilstm")
- # 把要测试的随笔本以str名目放到这个列内外
- test_text = [
- "这家餐厅不是很好吃",
- "这部影戏差能人意",
- ]
- # 指定模子输入
- input_dict = {"text": test_text}
- # 把数据喂给senta模子的文天职类函数
- results = senta.sentiment_classify(data=input_dict)
- # 遍历说明每个随笔本
- for index, text in enumerate(test_text):
- results[index]["text"] = text
- for index, result in enumerate(results):
- if six.PY2:
- print(
- json.dumps(results[index], encoding="utf8", ensure_ascii=False))
- else:
- print('text: {}, predict: {}'.format(results[index]['text'],results[index]['sentiment_key']))
具体测评
成语情绪说明
input
- test_text = [
- '沧海桑田', # 中型,世事务革很大
- '下里巴人', # 褒义,普通的文学艺术
- '口碑载道', # 褒义,对突出的大好人功德同等赞颂
- '危言危行', # 褒义,嗣魅正直的话,做正直的事
- '巧夺天工', # 褒义,指大天然美景
- '不赞一词', # 褒义,不能再添一句话,暗示写的很好
- '文不加点', # 褒义,指写作能力高深
- '差能人意', # 褒义,概略还能使人满足
- '无微不至', # 褒义,指仔细殷勤
- '事倍功半', # 褒义,指不艰辛就有好的结果
- '事半功倍', # 贬义,批示霍了实力却没有好结果
- '摩拳擦掌', # 贬义,指要干坏事
- '涣然一新', # 贬义,指大粉碎
- '一落千丈', # 贬义,指事物日渐衰落
- '说长道短', # 贬义,指末节过度挑剔
- '生灵涂炭', # 贬义,指人民极度困苦
- '始作俑者', # 贬义,第一个做坏事的人
- '无所不为', # 贬义,什么坏事都干
- '无所不至', # 贬义,什么坏事都干
- '阳春白雪', # 贬义,高妙不轻易领略的艺术
- ]
output
- 运行耗时: 4秒480毫秒
- text: 沧海桑田, positive_prob: 0.3838, predict: negative # 错误
- text: 下里巴人, positive_prob: 0.7957, predict: positive
- text: 口碑载道, positive_prob: 0.906, predict: positive
- text: 危言危行, positive_prob: 0.588, predict: positive
- text: 巧夺天工, positive_prob: 0.657, predict: positive
- text: 不赞一词, positive_prob: 0.9698, predict: positive
- text: 文不加点, positive_prob: 0.1284, predict: negative # 错误
- text: 差能人意, positive_prob: 0.0429, predict: negative # 错误
- text: 无微不至, positive_prob: 0.8997, predict: positive
- text: 事倍功半, positive_prob: 0.6181, predict: positive
- text: 事半功倍, positive_prob: 0.8558, predict: positive # 错误
- text: 摩拳擦掌, positive_prob: 0.7353, predict: positive # 错误
- text: 涣然一新, positive_prob: 0.2186, predict: negative
- text: 一落千丈, positive_prob: 0.2753, predict: negative
- text: 说长道短, positive_prob: 0.6737, predict: positive # 错误
- text: 生灵涂炭, positive_prob: 0.4661, predict: neutral # 错误
- text: 始作俑者, positive_prob: 0.247, predict: negative
- text: 无所不为, positive_prob: 0.5948, predict: positive # 错误
- text: 无所不至, positive_prob: 0.553, predict: positive # 错误
- text: 阳春白雪, positive_prob: 0.7552, predict: positive # 错误
正确率:10/20 = 50%
转折复句情感说明
(编辑:湖南网)
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!
|