Get the App
SLTechnology News&Howtos  ›  Development  › 

How to realize text emotion recognition by python

Shulou Source: shulou.com Published: 2022-06-01 04:59:28 10月03日 Update

This article mainly shows you "python how to achieve text emotion recognition", the content is easy to understand, clear, hope to help you solve your doubts, the following let the editor lead you to study and learn "python how to achieve text emotion recognition" this article.

Text emotion recognition

In the face of paddlepaddle, natural language processing has also become very simple. To achieve text emotion recognition, we also need to install PaddlePaddle and Paddlehub. For specific installation, please see part 3.

And then there's the part of our code:

Import paddlehub as hub senta = hub.Module (name='senta_lstm') # load model sentence = [# prepare the sentences to be identified: 'you are so beautiful', 'you are so ugly','I'm so sad','I'm not happy', 'have a good time in this game', 'what junk game' ] results = senta.sentiment_classify (data= {text:sentence}) # emotion recognition # output recognition result for result in results: print (result)

The result of recognition is a list of dictionaries:

{'text':' you are beautiful, 'sentiment_label': 1,' sentiment_key': 'positive',' positive_probs': 0.9602, 'negative_probs': 0.0398}

{'text':' you are ugly, 'sentiment_label': 0,' sentiment_key': 'negative',' positive_probs': 0.0033, 'negative_probs': 0.9967}

{'text':' I'm so sad, 'sentiment_label': 1,' sentiment_key': 'positive',' positive_probs': 0.5324, 'negative_probs': 0.4676}

{'text':' I am unhappy', 'sentiment_label': 0,' sentiment_key': 'negative',' positive_probs': 0.1936, 'negative_probs': 0.8064}

{'text':' is a good game', 'sentiment_label': 1,' sentiment_key': 'positive',' positive_probs': 0.9933, 'negative_probs': 0.0067}

{'text':' what junk games', 'sentiment_label': 0,' sentiment_key': 'negative',' positive_probs': 0.0108, 'negative_probs': 0.9892}

The sentiment_key field contains emotional information.

The above is all the content of the article "how to achieve text emotion recognition in python". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Tags: Emotions text content articles fun sad garbage results learning help code information dictionaries fields that is easy to understand more organization models knowledge Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno vpn OPPO Reno Redmi macOS Shulou Tech Info