首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法重新创建训练FastText的Gensim文档。TypeError:必须提供corpus_file或corpus_iterable值之一

无法重新创建训练FastText的Gensim文档。TypeError:必须提供corpus_file或corpus_iterable值之一
EN

Stack Overflow用户
提问于 2021-05-17 16:13:30
回答 1查看 1.9K关注 0票数 4

我正在尝试制作我自己的Fasttext嵌入,所以我使用了4.0版本的官方Gensim文档和4.0

代码语言:javascript
复制
from gensim.models import FastText
from gensim.test.utils import common_texts

model = FastText(vector_size=4, window=3, min_count=1)  # instantiate
model.build_vocab(sentences=common_texts)
model.train(sentences=common_texts, total_examples=len(common_texts), epochs=10)

令我惊讶的是,它给我的错误是:

代码语言:javascript
复制
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-4-6b2d1de02d90> in <module>
      1 model = FastText(vector_size=4, window=3, min_count=1)  # instantiate
----> 2 model.build_vocab(sentences=common_texts)
      3 model.train(sentences=common_texts, total_examples=len(common_texts), epochs=10)

~/anaconda3/lib/python3.8/site-packages/gensim/models/word2vec.py in build_vocab(self, corpus_iterable, corpus_file, update, progress_per, keep_raw_vocab, trim_rule, **kwargs)
    477 
    478         """
--> 479         self._check_corpus_sanity(corpus_iterable=corpus_iterable, corpus_file=corpus_file, passes=1)
    480         total_words, corpus_count = self.scan_vocab(
    481             corpus_iterable=corpus_iterable, corpus_file=corpus_file, progress_per=progress_per, trim_rule=trim_rule)

~/anaconda3/lib/python3.8/site-packages/gensim/models/word2vec.py in _check_corpus_sanity(self, corpus_iterable, corpus_file, passes)
   1484         """Checks whether the corpus parameters make sense."""
   1485         if corpus_file is None and corpus_iterable is None:
-> 1486             raise TypeError("Either one of corpus_file or corpus_iterable value must be provided")
   1487         if corpus_file is not None and corpus_iterable is not None:
   1488             raise TypeError("Both corpus_file and corpus_iterable must not be provided at the same time")

TypeError: Either one of corpus_file or corpus_iterable value must be provided

有人能帮我一下这里发生的事吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-05-17 17:58:23

所以我找到了答案。在这两个方面,他们对论点sentence都有问题:

代码语言:javascript
复制
model.build_vocab(sentences=common_texts)
model.train(sentences=common_texts, total_examples=len(common_texts), epochs=10)

您所要做的就是删除参数名,或者传递第一个参数,即corpus_iterable

代码语言:javascript
复制
model.build_vocab(common_texts)
model.train(common_texts, total_examples=len(common_texts), epochs=10)

代码语言:javascript
复制
model.build_vocab(corpus_iterable=common_texts)
model.train(corpus_iterable=common_texts, total_examples=len(common_texts), epochs=10)
票数 12
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67573416

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档