根据想忽略的自然语言信息的多少,可以为流水线使用多个停用词表的并集或交集。现给出 sklearn和 nltk之间停用词的比较情况。
from sklearn.feature_extraction.text import ENGLISH_STOP_WORDS as sklearn_stop_words
import nltk
stop_words = nltk.corpus.stopwords.words('english')
print(len(sklearn_stop_words))
print(len(stop_words) )
# NLTK停用词表中有60个词不包含在更大的 sklearn 停用词表中
print(len(set(stop_words).union(sklearn_stop_words)) )
# NLTK 和 sklearn 共同的停用词不到总数的1/3(在378 个停用词中有119 个相同)
print(len(set(stop_words).intersection(sklearn_stop_words)))