是否可以提前知道CountVectorizer
是否会抛出
ValueError:空词汇?
基本上,我有大量文档,我想过滤掉不会通过CountVectorizer
的文档(我正在使用stop_words='english'
)
谢谢
答案 0 :(得分:1)
您可以使用build_analyzer()
识别那些文档。试试吧!
from sklearn.feature_extraction.text import CountVectorizer
corpus = [
'This is the first document.',
'This document is the second document.',
'And this is the third one.',
'Is this the first document?',
'this is to',
'she has'
]
analyzer = CountVectorizer(stop_words='english').build_analyzer()
filter_condtn = [True if analyzer(doc) else False for doc in corpus ]
#[True, True, False, True, False, False]
P.S。 :太糊涂了,看不到第三个文档中的所有单词都是停用词。