停用词删除困境

3

我在使用NLTK中的停用词函数时遇到了一个两难的问题。我正在处理社交媒体平台上的用户生成内容,通过使用NLTK删除停用词。然而,问题在于我想保留用户文本中的人称代词,这对分类任务非常重要。这些包括“I”、“you”、“we”等单词。

不幸的是,停用词函数也删除了这些单词,而我需要它们存在。我该如何解决这个问题?


你为什么要首先移除停用词? - Oliver Mason
nltk停用词不过是一组字符串。你可以创建自己的停用词集合。甚至可以查看nltk停用词并从中删除想要保留的停用词。 - Green
@OliverMason 针对文本分类任务 - 我想除去用户帖子中除人称代词外的不必要单词,这些代词可能表明我感兴趣的变量。 - user13408753
@Green 谢谢 :) ,我刚开始接触这个,需要一些验证。 - user13408753
1个回答

3
import nltk
from nltk.corpus import stopwords
stop_words= stopwords.words('english')
type(stop_words)
print(len(stop_words))

如果您查看输出,停用词的类型是List。那么:
personal_pronouns= ['i', 'you', 'she', 'he', 'they'] # you can add another words for remove
for word in personal_pronouns:
    if word in stop_words:
        stop_words.remove(word)
        print(word+ '  Deleted')
print(len(stop_words))

非常感谢,我非常感激! - user13408753
@Poppy 不客气 :) 如果你得到了问题的答案,可以接受。 - mohammad karami sheykhlan
同时:stop_words.extend(personal_pronouns) - Nik Drosakis

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接