是否可以提前知道 CountVectorizer
是否会抛出
ValueError: empty vocabulary?
基本上,我有一个文档语料库,我想过滤掉那些无法通过 CountVectorizer
的文档(我正在使用 stop_words='english'
)
谢谢
最佳答案
您可以使用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]
附注:我太困惑了,看不到第三个文档中的所有单词都是停用词。
关于python - 如何提前判断 CountVectorizer 是否会抛出 ValueError : empty vocabulary?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54054299/