gojomo's answer is right
gensim.models.KeyedVectors.load_word2vec_format("GoogleNews-vectors-negative300.bin.gz", binary=True)
如果仍然出现如下错误,请尝试升级gensim的所有依赖项(例如smart_open)
pip install --upgrade gensim
文件“/home/liangn/PythonProjects/DeepRecommendation/Algorithm/Word2Vec.py”,第 18 行,位于initself.model = gensim.models.KeyedVectors.load_word2vec_format(w2v_path,binary=True)
文件“/home/liangn/PythonProjects/venvLiang/lib/python2.7/site-packages/gensim/models/keyedvectors.py”,第191行,采用load_word2vec_format,其中utils.smart_open(fname)为fin:
文件“/home/liangn/PythonProjects/venvLiang/lib/python2.7/site-packages/smart_open/smart_open_lib.py”,第138行,在smart_open中
返回 file_smart_open(parsed_uri.uri_path, 模式)
文件“/home/liangn/PythonProjects/venvLiang/lib/python2.7/site-packages/smart_open/smart_open_lib.py”,第 642 行,位于 file_smart_open
返回compression_wrapper(打开(fname,模式),fname,模式)
文件“/home/liangn/PythonProjects/venvLiang/lib/python2.7/site-packages/smart_open/smart_open_lib.py”,第630行,在compression_wrapper中
返回 make_close(GzipFile)(file_obj, 模式)
文件“/usr/lib64/python2.7/gzip.py”,第 94 行,位于initfileobj = self.myfileobj =builtin.open(文件名、模式或“rb”)
类型错误:强制转换为 Unicode:需要字符串或缓冲区,已找到文件