这两天实验了一下情感倾向分析的API,感觉很不错,用Python写了一个API调用及数据提取的函数,与大家分享。
from aip import AipNlp
import pandas as pd
""" 你的 APPID AK SK """
APP_ID = 'XXXXXXX'
API_KEY = 'XXXXXXXXXX'
SECRET_KEY = 'XXXXXXXXXXXX'
client = AipNlp(APP_ID, API_KEY, SECRET_KEY)
demotext = "百度情感分析API棒棒的!"
""" 调用情感倾向分析,返回具体数值 """
def get_sentiment(text):
#print (text)
json_data=client.sentimentClassify(text)
text=json_data['text']
items=json_data['items']
items=items[0]
positive_prob=items['positive_prob']
confidence=items['confidence']
negative_prob=items['negative_prob']
sentiment=items['sentiment']
return text,positive_prob,confidence,negative_prob,sentiment
print (get_sentiment(demotext))
TOP
切换版块
这两天试用了一下百度的几个文本的AI,感觉效果都不错。