在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 狗狗训练要多少钱
5 深圳狗狗训练
6 训练狗狗唤回
7 狗狗叫怎么训练
8 狗狗训练班
10 狗狗社会化训练
11 狗狗叫回训练
12 广州狗狗训练学校
13 狗狗训练躺下
14 狗狗随行训练
15 训练狗狗巡回
16 狗狗要怎么训练
17 狗狗喂食训练
18 训练狗狗躺下