在Python中使用NLTK删除停用词
当计算机处理自然语言时,某些极端通用的单词似乎在帮助选择符合用户需求的文档方面几乎没有值,因此完全从词汇表中排除了。这些单词称为停用词。
例如,如果您输入的句子为-
John is a person who takes care of the people around him.
停止单词删除后,您将获得输出-
['John', 'person', 'takes', 'care', 'people', 'around', '.']
NLTK收集了这些停用词,我们可以将其从任何给定的句子中删除。这在NLTK.corpus模块内部。我们可以用它来过滤掉句子中的停用词。例如,
示例
from nltk.corpus import stopwords from nltk.tokenize import word_tokenize my_sent = "John is a person who takes care of people around him." tokens = word_tokenize(my_sent) filtered_sentence = [w for w in tokens if not w in stopwords.words()] print(filtered_sentence)
输出结果
这将给出输出-
['John', 'person', 'takes', 'care', 'people', 'around', '.']
热门推荐
1 训练狗狗基础
2 怎么训练狗狗笑
3 怎么训练狗狗卧下
4 上海狗狗训练基地
5 训练狗狗排便
6 狗狗基础训练
8 如何训练狗狗装死
9 狗狗站姿训练
10 狗狗训练用品
11 训练狗狗吧
12 狗狗要怎么训练
13 怎么训练狗狗玩球
14 训练狗狗唤回
15 狗狗训练躺下
16 狗狗训练指令
17 狗狗的训练技巧
18 狗狗不好训练