【问题标题】:Python natural language processing stop words [duplicate]Python自然语言处理停用词[重复]
【发布时间】:2023-03-06 06:19:01
【问题描述】:

我只是在用 Python 对 NLP 进行一些研究,发现了一些奇怪的东西。

审查以下负面推文:

neg_tweets = [('I do not like this car', 'negative'),
          ('This view is horrible', 'negative'),
          ('I feel tired this morning', 'negative'),
          ('I am not looking forward to the concert', 'negative'),<---
          ('He is my enemy', 'negative')]

并通过删除停用词进行一些处理。

clean_data = []
stop_words = set(stopwords.words("english"))

for (words, sentiment) in pos_tweets + neg_tweets:
words_filtered = [e.lower() for e in words.split() if e not in stop_words]
clean_data.append((words_filtered, sentiment))

部分输出为:

 (['i', 'looking', 'forward', 'concert'], 'negative')

我很难理解为什么停用词包括“不”,这会影响推文的情绪。

我的理解是停用词在情感方面没有价值。

那么,我的问题是为什么“不”包含在停用词列表中?

【问题讨论】:

  • 主要是因为它们最常用于搜索和检索。这不是您的用例。
  • 我不知道为什么,但我认为你可以这样做:take_out_not = set(('not')) stop_words = set(stopwords.words("english")) - take_out_not
  • 停用词列表并非专门为情绪分析而设计的。在删除停用词之前,请自定义要删除的内容。例如,您可以手动从停用词列表中删除否定词。

标签: python text nltk analysis


【解决方案1】:

句子中的停用词“一般”很少或没有用处。正如斯坦福 NLP 小组所说:

有时,一些极其常见的词在帮助选择符合用户需求的文档方面似乎没有什么价值,它们会完全从词汇表中排除。这些词称为停用词

为什么是“不”这个词? :仅仅因为它经常出现在英语词汇表中,并且“通常”不重要或不重要,例如,如果您正在做文本摘要,而这些停用词几乎没有用处,而这一切都取决于频率分布话(如tf-idf.

那你能做什么?嗯,这是一个非常广泛的主题,称为Negation Handling。这是一个非常广泛的领域,有许多不同的方法。我最喜欢的方法之一是在删除停用词或计算词向量之前简单地附加前面或后面的否定子句。例如,您可以将not looking 转换为not_looking,在计算并转换为向量空间时会完全不同。您可以在 SO 答案 here 中找到执行类似操作的代码。

我希望这会有所帮助!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-06-28
    • 1970-01-01
    • 1970-01-01
    • 2018-07-05
    相关资源
    最近更新 更多