Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize text emotion recognition by python

2025-01-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report