【问题标题】:Textblob and sentiment analysis: how to refine a dictionary?Textblob 和情感分析:如何提炼字典?
【发布时间】:2020-10-07 21:57:32
【问题描述】:

许多人使用文本 blob 对文本进行情感分析。我确信我在理解该方法以及如何使用它时遗漏了一些东西,但是对于我从分析中获得的结果来说,有些东西根本不起作用。

这是我拥有的数据示例:

Top                                                     Text                                                   label    sentiment   polarity
51  CVD-Grown Carbon Nanotube Branches on Black Si...   silicon-carbon nanotube (bSi-CNT) hybrid struc...         -1    (-0.16666666666666666, 0.43333333333333335) -0.166667
69  Navy postpones its largest-ever Milan exercise...   Navy on Tuesday postponed a multi-nation mega ...           -1  (-0.125, 0.375) -0.125000
81 Malaysia rings alarm bell on fake Covid...   The United Nations International Children's Em...                   -1  (-0.5, 1.0) -0.500000
82  Poison Not Transmitted By Air...    it falls on the fabric remains 9 hours, so was...                   -1  (-0.2, 0.0) -0.200000
87  A WhatsApp rumor is spreading that is allegedl...   strict about unsourced speculation than other ...        -1 (-0.1, 0.1) -0.100000
90  Dumb Whatsapp Forwards - Page 2 - Cricket Web   as the ones that say like or share this pictur...          -1   (-0.375, 0.5)   -0.375000
144 malaysia | Unicef Malaysia rings alarm b... such messages claiming to be from us,” #Milan...                -1  (-0.5, 1.0) -0.500000
134 False and unverified claims are being...    Soccer was not issued by the U...                               -1  (-0.4000000000000001, 0.6)  -0.400000
123 Truth behind the Viral message about Co...  number of stories ever since the wave of misin...               -1  (-0.4, 0.7) -0.400000
166 In India, Fake WhatsApp Forwards on Coronaviru...   of confirmed cases of rises rapidl...                   -1  (-0.5, 1.0) -0.500000

我使用了以下算法:

df['sentiment'] = df['Top'].apply(lambda Tweet: TextBlob(Tweet).sentiment)

df1=pd.DataFrame(df['sentiment'].tolist(), index= df.index)

df_new = df
df_new['polarity'] = df1['polarity']
df_new.polarity = df1.polarity.astype(float)
df_new['subjectivity'] = df1['subjectivity']
df_new.subjectivity = df1.polarity.astype(float)
# print(df_new)

conditionList = [
    df_new['polarity'] == 0,
    df_new['polarity'] > 0,
    df_new['polarity'] < 0]
choiceList = ['neutral', 'not_fake', 'fake']
df_new['label'] = np.select(conditionList, choiceList, default='no_label')

但正如您所见,所有这些消息都来自事实核查来源,因此它们不是假的。 我怎样才能改善结果,也许删除一些特定的词? 我可以看到,如果文本包含虚假、未经验证、病毒性、虚假,则会被标记为负面,这会使结果变得更糟。

【问题讨论】:

  • 首先,情绪和事实核查是两个不同的东西。它们不相关,因此您可以使用其极性分数来判断样本是否是假的。
  • 您是否尝试过删除停用词,同时专注于动词、形容词和名词?

标签: python sentiment-analysis textblob


【解决方案1】:

您的所有文本都具有负极性,因此根据您的代码,它们会被标记为假的。

没有说明如何确定极性场,它是在源文件中预先计算的。如果它使用 textblob 默认极性算法,它运行的是什么文本?

另外,可能有一个错字。Df_new.subjectivity 被分配了极性的浮点数

【讨论】:

  • 鉴于文本的长度,我使用了 Tweet,但我不确定是否是使用谷歌新闻的情况。我该如何改进 textblob 的算法?我以为我必须使用默认的,而不做任何更改。
  • Textblob 在设计上将“消极性”作为极性来衡量。文本“对你妈妈撒谎不好”返回负极性,因为“不好”是负面的。你的代码说任何带有负极性的东西都是假的,因此“对你妈妈撒谎是不好的”被你的代码标记为假的。这不是编码问题,你的基本前提是有缺陷的
  • 我明白你的意思。我在看这个答案:datascience.stackexchange.com/questions/75364/…。当然,我想改进算法,因为我不支持 Python 中的默认内置函数(尽管我在这里使用了 TextBlob)。
猜你喜欢
  • 2020-08-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-03-26
  • 2018-06-25
  • 2017-09-27
相关资源
最近更新 更多