简体   繁体   English

TextBlob如何计算情感极性? 如何使用机器学习分类器计算情感价值?

[英]How does TextBlob calculate sentiment polarity? How can I calculate a value for sentiment with machine learning classifier?

how does TextBlob calculate an empirical value for the sentiment polarity. TextBlob如何计算情感极性的经验值。 I have used naive bayes but it just predicts whether it is positive or negative. 我使用过朴素的贝叶斯,但它只是预测它是正面还是负面。 How could I calculate a value for the sentiment like TextBlob does? 我如何像TextBlob一样为情感计算值?

Here is an example from the site: https://textblob.readthedocs.io/en/dev/quickstart.html#sentiment-analysis 这是该站点的示例: https : //textblob.readthedocs.io/en/dev/quickstart.html#sentiment-analysis

text1 = TextBlob("Today is a great day, but it is boring")
text1.sentiment.polarity
# You can derive the sentiment based on the polarity.

Here is a sample code of how I used TextBlob in tweets sentiments: 这是我如何在推文情感中使用TextBlob的示例代码:

from textblob import TextBlob
### My input text is a column from a dataframe that contains tweets. 

def sentiment(x):
    sentiment = TextBlob(x)
    return sentiment.sentiment.polarity

tweetsdf['sentiment'] = tweetsdf['processed_tweets'].apply(sentiment)
tweetsdf['senti'][tweetsdf['sentiment']>0] = 'positive'
tweetsdf['senti'][tweetsdf['sentiment']<0] = 'negative'
tweetsdf['senti'][tweetsdf['sentiment']==0] = 'neutral'

Based on the polarity and how the sentences were really sounding, I ended up with the logic above. 基于极性和句子的发音,我得出了以上逻辑。 Note that this might not be the case for some tweets. 请注意,某些推文可能并非如此。

I personally found vader sentiments compound score to be making more sense so that I can figure out a range for positive, negative and neutral sentiments based on the compound score & the tweet text instead of just assigning postivie sentiment for all texts with polarity >0 我个人发现vader情绪的复合分数更有意义,因此我可以根据复合分数和tweet文本确定积极,消极和中性情绪的范围,而不是为极性> 0的所有文本分配暂态情绪

Need more clarity in your question. 您的问题需要更多的说明。 Are you talking about creating your own code base for calculating the sentiment? 您是在谈论创建自己的代码库来计算情感吗?

TextBlob does NLP tasks like tokenization, sentiment analysis, POS tagging etc. Refer to the source code as to how the sentiment polarity & subjectivity is calculated. TextBlob执行NLP任务,例如标记化,情感分析,POS标记等。有关如何计算情感极性和主观性的信息,请参阅源代码

You calculate the sentiment using TextBlob or Vader. 您可以使用TextBlob或Vader计算情感。 Based on the polarity and subjectivity, you determine whether it is a positive text or negative or neutral. 根据极性和主观性,您可以确定它是正面文字还是负面文字或中性文字。 For TextBlog, if the polarity is >0, it is considered positive, <0 -is considered negative and ==0 is considered neutral. 对于TextBlog,如果极性> 0,则将其视为正极,将<0-视为负极,并将== 0视为中性。 For vader sentiments, this is based on the compound score. 对于vader情绪,这是基于综合得分。

Then you train the classifier based on your sentiments (positive, negative, neutral) and proceed with prediction. 然后,根据您的情绪(积极,消极,中立)训练分类器,并进行预测。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM