Ris*_*sia 7 python nlp gensim word2vec
我正在尝试实现 word2vec 模型并收到属性错误
AttributeError:类型对象“Word2Vec”没有属性“load_word2vec_format”
下面是代码:
wv = Word2Vec.load_word2vec_format("GoogleNews-vectors-negative300.bin.gz", binary=True)
wv.init_sims(replace=True)
Run Code Online (Sandbox Code Playgroud)
请让我知道这个问题?
小智 4
gojomo的回答是正确的
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 行,init self.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, mode)
文件“/home/liangn/PythonProjects/venvLiang/lib/python2.7/site-packages/smart_open/smart_open_lib.py”,第642行,在file_smart_open中返回compression_wrapper(open(fname, mode), fname, mode)
文件“/home/liangn/PythonProjects/venvLiang/lib/python2.7/site-packages/smart_open/smart_open_lib.py”,第630行,在compression_wrapper中返回make_ opening(GzipFile)(file_obj,模式)
文件“/usr/lib64/python2.7/gzip.py”,第 94 行,init fileobj = self.myfileobj = builtin .open(filename, mode or 'rb')
类型错误:强制转换为 Unicode:需要字符串或缓冲区,已找到文件
| 归档时间: |
|
| 查看次数: |
15861 次 |
| 最近记录: |