【问题标题】:gensim Getting Started Error: No such file or directory: 'text8'gensim 入门错误:没有这样的文件或目录:'text8'
【发布时间】:2017-05-28 11:39:33
【问题描述】:

我正在学习 python 中的 word2vec 和 GloVe 模型,所以我正在浏览这个可用的here

我在 Idle3 中一步步编译这些代码后:

>>>from gensim.models import word2vec
>>>import logging
>>>logging.basicConfig(format='%(asctime)s : %(levelname)s : %(message)s', level=logging.INFO)
>>>sentences = word2vec.Text8Corpus('text8')
>>>model = word2vec.Word2Vec(sentences, size=200)

我收到此错误:

2017-01-13 11:15:41,471 : INFO : collecting all words and their counts
Traceback (most recent call last):
  File "<pyshell#4>", line 1, in <module>
    model = word2vec.Word2Vec(sentences, size=200)
  File "/usr/local/lib/python3.5/dist-packages/gensim/models/word2vec.py", line 469, in __init__
    self.build_vocab(sentences, trim_rule=trim_rule)
  File "/usr/local/lib/python3.5/dist-packages/gensim/models/word2vec.py", line 533, in build_vocab
    self.scan_vocab(sentences, progress_per=progress_per, trim_rule=trim_rule)  # initial survey
  File "/usr/local/lib/python3.5/dist-packages/gensim/models/word2vec.py", line 545, in scan_vocab
    for sentence_no, sentence in enumerate(sentences):
  File "/usr/local/lib/python3.5/dist-packages/gensim/models/word2vec.py", line 1536, in __iter__
    with utils.smart_open(self.fname) as fin:
  File "/usr/local/lib/python3.5/dist-packages/smart_open-1.3.5-py3.5.egg/smart_open/smart_open_lib.py", line 127, in smart_open
    return file_smart_open(parsed_uri.uri_path, mode)
  File "/usr/local/lib/python3.5/dist-packages/smart_open-1.3.5-py3.5.egg/smart_open/smart_open_lib.py", line 558, in file_smart_open
    return open(fname, mode)
FileNotFoundError: [Errno 2] No such file or directory: 'text8'

我该如何纠正这个问题? 提前感谢您的帮助。

【问题讨论】:

    标签: python python-3.x error-handling gensim word2vec


    【解决方案1】:

    您似乎缺少此处使用的文件。具体来说,它正在尝试打开text8,但找不到它(因此是FileNotFoundError)。

    您可以按照in the documentation for Text8Corpus 的说明从here 下载文件本身:

    Docstring:      
    Iterate over sentences from the "text8" corpus, unzipped from http://mattmahoney.net/dc/text8.zip .
    

    并使其可用。 提取它,然后将其作为参数提供给Text8Corpus

    sentences = word2vec.Text8Corpus('/path/to/text8')
    

    【讨论】:

    • 在我使用 svn checkout word2vec.googlecode.com/svn/trunk 后,我得到了这个... svn: E170013: Unable to connect to a repository at URL 'word2vec.googlecode.com/svn/trunk' .... svn: E160013: '/svn /trunk' path not found ...我在终端中输入了该路径
    • @Clueless_programmer 只需获取 zip,解压缩并将其作为 Text8Corpus 的路径提供,我已经更改了答案以说明这一点。
    猜你喜欢
    • 1970-01-01
    • 2021-10-31
    • 1970-01-01
    • 1970-01-01
    • 2013-08-08
    • 2013-11-04
    • 2012-02-18
    • 2012-10-21
    • 2011-03-22
    相关资源
    最近更新 更多