是否有一种廉价且简单的方法可以防止 sklearnCountVectorizer
仅使用stop_words
参数停止一元组,并使其也停止二元组?我的意思在以下片段中进行了说明:
from sklearn.feature_extraction.text import CountVectorizer
texts = ['hello this is text number one yes yes',
'hello this is text number two stackflow']
stop_words = {'hello this'}
model = CountVectorizer(analyzer='word',
ngram_range=(1,2),
max_features=3,
stop_words=stop_words)
doc_vectors = model.fit_transform(texts).toarray()
print(doc_vectors)
print(model.get_feature_names())
所以这段代码的作用是输出以下内容:
>>> [[1 1 1]
>>> [1 1 1]]
>>> ['hello', 'hello this', 'is']
如您所见,我希望计算出双字母“你好”(它被喂给停用词)。我看过一些他们使用管道或自定义分析器的帖子,并且我浏览了文档,但是没有更简单的方法解决这个问题吗?
谢谢!