过滤词—Filtering Words

对于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")
发布了18 篇原创文章 · 获赞 0 · 访问量 136

猜你喜欢

转载自blog.csdn.net/weixin_43979941/article/details/105058405