对于NLP的应用,我们通常先把停用词、出现频率很低的词汇过滤掉,类似于特征筛选的过程
建立停用词的方法:
# 方法1:自己建立一个停用词词典
stop_words=["the","an","is","there"]
# 在使用时:假设word_list包含了文本里的单词
word_list=["we","are","the","students"]
filtered_words=[word for word in word_list if word not in word_list]
print(filtered_words)
# 方法2:直接利用别人已经构建好的停用词库
from nltk.corpus import stopwords
cachedStopWords=stopWords.words("english")