我的磁盘上有 9GB 的分段文档,而我的 vps 只有 4GB 内存。
如何在初始化时不加载所有语料库的情况下对所有数据集进行向量化?有示例代码吗?
我的代码如下:
contents = [open('./seg_corpus/' + filename).read()
for filename in filenames]
vectorizer = CountVectorizer(stop_words=stop_words)
vectorizer.fit(contents)
最佳答案
尝试一下,您可以仅将文件句柄传递到 fit
方法中,而不是将所有文本加载到内存中,但必须在 中指定
构造函数。input='file'
>CountVectorizer
contents = [open('./seg_corpus/' + filename)
for filename in filenames]
vectorizer = CountVectorizer(stop_words=stop_words, input='file')
vectorizer.fit(contents)
关于python - 使用大数据集进行 scikit-learn 向量化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40054473/