我正在尝试实现 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)
请让我知道这个问题?
请您参考如下方法:
gojomo的回答是对的
gensim.models.KeyedVectors.load_word2vec_format("GoogleNews-vectors-negative300.bin.gz", binary=True)
尝试升级gensim的所有依赖(例如smart_open),如果仍然报错如下
pip install --upgrade gensim
init 中的文件“/home/liangn/PythonProjects/DeepRecommendation/Algorithm/Word2Vec.py”,第 18 行 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, 模式)
文件“/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_closing(GzipFile)(file_obj, 模式)
init 中的文件“/usr/lib64/python2.7/gzip.py”,第 94 行 fileobj = self.myfileobj = 内置.open(文件名、模式或'rb')
类型错误:强制转换为 Unicode:需要字符串或缓冲区,已找到文件
