2024-04-24 02:44:50 发布
网友
我正在尝试实现word2vec模型并获取属性错误
AttributeError: type object 'Word2Vec' has no attribute 'load_word2vec_format'
下面是代码:
wv = Word2Vec.load_word2vec_format("GoogleNews-vectors-negative300.bin.gz", binary=True) wv.init_sims(replace=True)
请告诉我这个问题?
gensim.models.KeyedVectors.load_word2vec_format("GoogleNews-vectors-negative300.bin.gz", binary=True)
如果仍有以下错误,请尝试升级gensim的所有依赖项(例如smart_open)
pip install --upgrade gensim
文件“/home/liann/PythonProjects/DeepRecommendation/Algorithm/Word2Vec.py”,第18行,在init中 self.model=gensim.models.KeyedVectors.load\u word2vec\u格式(w2v\u path,binary=True)
文件“/home/liann/PythonProjects/venvLiang/lib/python2.7/site packages/gensim/models/keyedvorts.py”,第191行,以加载word2vec_格式,utils.smart_open(fname)作为fin:
文件“/home/liann/PythonProjects/venvLiang/lib/python2.7/site packages/smart-open/smart-open-lib.py”,第138行,smart-open 返回文件_smart_open(解析的_uri.uri_路径,模式)
文件“/home/liann/PythonProjects/venvLiang/lib/python2.7/site packages/smart-open/smart-open-lib.py”,第642行,在文件“smart-open”中 返回压缩包装(打开(fname,mode),fname,mode)
文件“/home/liann/PythonProjects/venvLiang/lib/python2.7/site packages/smart-open/smart-open-lib.py”,第630行,压缩包装中 返回make_closing(gzip文件)(文件_obj,模式)
文件“/usr/lib64/python2.7/gzip.py”,第94行,在init中 fileobj=self.myfileobj=内置。打开(文件名、模式或“rb”)
类型错误:强制使用Unicode:需要字符串或缓冲区,找到文件
您是如何安装gensim的,安装了什么版本?
gensim 1.0中的API更改将load_word2vec_format()移动到名为KeyedVectors的helper类。
load_word2vec_format()
KeyedVectors
此时(2017年2月),您可能不想使用预发行版,除非您是经验丰富的gensim用户,并严格遵循发行说明[CHANGELOG.md][1]。
[CHANGELOG.md][1]
如果有意将更高版本的gensim与此API更改一起使用,则应使用:
KeyedVectors.load_word2vec_format("GoogleNews-vectors-negative300.bin.gz", binary=True)
gensim.models.KeyedVectors.load_word2vec_format("GoogleNews-vectors-negative300.bin.gz", binary=True)
如果仍有以下错误,请尝试升级gensim的所有依赖项(例如smart_open)
pip install --upgrade gensim
文件“/home/liann/PythonProjects/DeepRecommendation/Algorithm/Word2Vec.py”,第18行,在init中 self.model=gensim.models.KeyedVectors.load\u word2vec\u格式(w2v\u path,binary=True)
文件“/home/liann/PythonProjects/venvLiang/lib/python2.7/site packages/gensim/models/keyedvorts.py”,第191行,以加载word2vec_格式,utils.smart_open(fname)作为fin:
文件“/home/liann/PythonProjects/venvLiang/lib/python2.7/site packages/smart-open/smart-open-lib.py”,第138行,smart-open 返回文件_smart_open(解析的_uri.uri_路径,模式)
文件“/home/liann/PythonProjects/venvLiang/lib/python2.7/site packages/smart-open/smart-open-lib.py”,第642行,在文件“smart-open”中 返回压缩包装(打开(fname,mode),fname,mode)
文件“/home/liann/PythonProjects/venvLiang/lib/python2.7/site packages/smart-open/smart-open-lib.py”,第630行,压缩包装中 返回make_closing(gzip文件)(文件_obj,模式)
文件“/usr/lib64/python2.7/gzip.py”,第94行,在init中 fileobj=self.myfileobj=内置。打开(文件名、模式或“rb”)
类型错误:强制使用Unicode:需要字符串或缓冲区,找到文件
您是如何安装gensim的,安装了什么版本?
gensim 1.0中的API更改将
load_word2vec_format()
移动到名为KeyedVectors
的helper类。此时(2017年2月),您可能不想使用预发行版,除非您是经验丰富的gensim用户,并严格遵循发行说明
[CHANGELOG.md][1]
。如果有意将更高版本的gensim与此API更改一起使用,则应使用:
相关问题 更多 >
编程相关推荐