Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/322.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 没有这样的文件或目录:';google_news_vectors.bin';_Python_Gensim_Word2vec - Fatal编程技术网

Python 没有这样的文件或目录:';google_news_vectors.bin';

Python 没有这样的文件或目录:';google_news_vectors.bin';,python,gensim,word2vec,Python,Gensim,Word2vec,我试图加载google_news_vectors.bin文件,但它给出了一个 错误。下面是我的代码,它写在nlp_gen2.py文件中 我得到的错误是: FileNotFoundError Traceback (most recent call last) in 1 import gensim ----> 2 model = gensim.models.KeyedVectors.load_word2vec_format('google_news_vectors.bin', binary=T

我试图加载google_news_vectors.bin文件,但它给出了一个 错误。下面是我的代码,它写在nlp_gen2.py文件中

我得到的错误是:

FileNotFoundError Traceback (most recent call last) in 1 import gensim
----> 2 model = gensim.models.KeyedVectors.load_word2vec_format('google_news_vectors.bin',
binary=True)

C:\Anaconda3\envs\DataScience\lib\site-packages\gensim\models\keyedvectors.py
in load_word2vec_format(cls, fname, fvocab, binary, encoding,
unicode_errors, limit, datatype) 1547 return _load_word2vec_format(
1548 cls, fname, fvocab=fvocab, binary=binary, encoding=encoding,
unicode_errors=unicode_errors, -> 1549 limit=limit, datatype=datatype)
1550 1551 @classmethod

C:\Anaconda3\envs\DataScience\lib\site-packages\gensim\models\utils_any2vec.py
in _load_word2vec_format(cls, fname, fvocab, binary, encoding,
unicode_errors, limit, datatype, binary_chunk_size) 273 274
logger.info("loading projection weights from %s", fname) --> 275 with
utils.open(fname, 'rb') as fin: 276 header =
utils.to_unicode(fin.readline(), encoding=encoding) 277 vocab_size,
vector_size = (int(x) for x in header.split()) # throws for invalid
file format

C:\Anaconda3\envs\DataScience\lib\site-packages\smart_open\smart_open_lib.py
in open(uri, mode, buffering, encoding, errors, newline, closefd,
opener, ignore_ext, transport_params) 185 encoding=encoding, 186
errors=errors, --> 187 newline=newline, 188 ) 189 if fobj is not None:

C:\Anaconda3\envs\DataScience\lib\site-packages\smart_open\smart_open_lib.py
in _shortcut_open(uri, mode, ignore_ext, buffering, encoding, errors,
newline) 285 open_kwargs['errors'] = errors 286 --> 287 return
_builtin_open(local_path, mode, buffering=buffering, **open_kwargs) 288 289

FileNotFoundError: [Errno 2] No such file or directory:
'google_news_vectors.bin'
我的文件结构如下所示:


如何解决此问题?

文件名为“GoogleNews-vectors-negative300.bin”,但如您所见,该文件已损坏。再次下载并解包rar。

您的问题没有清楚显示文件的名称,因为浏览器没有显示文件扩展名。 请确保打开它们

出于某种原因,您有一个名为
GoogleNews-vectors-negative300.bin的文件夹。事实不应如此

选项A-手动解压缩
  • 下载
    GoogleNews-vectors-negative300.bin.gz
    。它应该正好是1647046227字节,它的MD5是
    1c892c4707a8a1a508b01a01735c0339
    。 通过检查文件属性确认文件大小

  • 解压缩文件。看起来您已经安装了WinRAR,它应该能够执行gunzip操作

  • 您现在应该有一个3644258522字节的文件
    GoogleNews-vectors-negative300.bin
    ,它的MD5是
    023bfd73698638bdad5f84df53404c8b

  • 现在,以下代码应该可以工作了:

    import gensim
    filename = 'GoogleNews-vectors-negative300.bin'
    model = gensim.models.KeyedVectors.load_word2vec_format(filename, binary=True)
    
    import gensim
    filename = 'GoogleNews-vectors-negative300.bin.gz'
    model = gensim.models.KeyedVectors.load_word2vec_format(filename, binary=True)
    
选项B-让gensim进行解压缩
  • 下载
    GoogleNews-vectors-negative300.bin.gz
    。它应该正好是1647046227字节,它的MD5是
    1c892c4707a8a1a508b01a01735c0339
    。 通过检查文件属性确认文件大小

  • 现在,以下代码应该可以工作了:

    import gensim
    filename = 'GoogleNews-vectors-negative300.bin'
    model = gensim.models.KeyedVectors.load_word2vec_format(filename, binary=True)
    
    import gensim
    filename = 'GoogleNews-vectors-negative300.bin.gz'
    model = gensim.models.KeyedVectors.load_word2vec_format(filename, binary=True)
    


这个答案就是基于此。

我认为您的程序正在寻找一个名为
google\u news\u vectors.bin的文件,但它没有找到该文件。该文件位于同一文件夹中。您显示文件结构的方式并不理想。请或者,在目录中打开命令行,并使用
dir
命令打印文件列表。新文件未损坏,键入的名称是否正确?