溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點(diǎn)擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

python如何實(shí)現(xiàn)文字情緒識別

發(fā)布時(shí)間:2022-03-18 13:43:30 來源:億速云 閱讀:312 作者:小新 欄目:開發(fā)技術(shù)

這篇文章主要為大家展示了“python如何實(shí)現(xiàn)文字情緒識別”,內(nèi)容簡而易懂,條理清晰,希望能夠幫助大家解決疑惑,下面讓小編帶領(lǐng)大家一起研究并學(xué)習(xí)一下“python如何實(shí)現(xiàn)文字情緒識別”這篇文章吧。

文字情緒識別

paddlepaddle面前,自然語言處理也變得非常簡單。實(shí)現(xiàn)文字情緒識別我們同樣需要安裝PaddlePaddle和Paddlehub,具體安裝參見三中內(nèi)容。

然后就是我們的代碼部分了:

import paddlehub as hub        
senta = hub.Module(name='senta_lstm')        # 加載模型
sentence = [    # 準(zhǔn)備要識別的語句
    '你真美', '你真丑', '我好難過', '我不開心', '這個(gè)游戲好好玩', '什么垃圾游戲',
]
results = senta.sentiment_classify(data={text:sentence})    # 情緒識別
# 輸出識別結(jié)果
for result in results:
    print(result)

識別的結(jié)果是一個(gè)字典列表:

{'text': '你真美', 'sentiment_label': 1, 'sentiment_key': 'positive', 'positive_probs': 0.9602, 'negative_probs': 0.0398}
{'text': '你真丑', 'sentiment_label': 0, 'sentiment_key': 'negative', 'positive_probs': 0.0033, 'negative_probs': 0.9967}
{'text': '我好難過', 'sentiment_label': 1, 'sentiment_key': 'positive', 'positive_probs': 0.5324, 'negative_probs': 0.4676}
{'text': '我不開心', 'sentiment_label': 0, 'sentiment_key': 'negative', 'positive_probs': 0.1936, 'negative_probs': 0.8064}
{'text': '這個(gè)游戲好好玩', 'sentiment_label': 1, 'sentiment_key': 'positive', 'positive_probs': 0.9933, 'negative_probs': 0.0067}
{'text': '什么垃圾游戲', 'sentiment_label': 0, 'sentiment_key': 'negative', 'positive_probs': 0.0108, 'negative_probs': 0.9892}

其中sentiment_key字段包含了情緒信息。

以上是“python如何實(shí)現(xiàn)文字情緒識別”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對大家有所幫助,如果還想學(xué)習(xí)更多知識,歡迎關(guān)注億速云行業(yè)資訊頻道!

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI