I am trying to implement word2vec model and getting Attribute error
AttributeError: type object 'Word2Vec' has no attribute 'load_word2vec_format'
Below is the code :
wv = Word2Vec.load_word2vec_format("GoogleNews-vectors-negative300.bin.gz", binary=True)
wv.init_sims(replace=True)
Please let me know the issue ?
gensim.models.KeyedVectors.load_word2vec_format("GoogleNews-vectors-negative300.bin.gz", binary=True)
try to upgrade all dependencies of gensim(e.g. smart_open), if you still have errors as follows
pip install --upgrade gensim
File "/home/liangn/PythonProjects/DeepRecommendation/Algorithm/Word2Vec.py", line 18, in init self.model = gensim.models.KeyedVectors.load_word2vec_format(w2v_path, binary=True)
File "/home/liangn/PythonProjects/venvLiang/lib/python2.7/site-packages/gensim/models/keyedvectors.py", line 191, in load_word2vec_format with utils.smart_open(fname) as fin:
File "/home/liangn/PythonProjects/venvLiang/lib/python2.7/site-packages/smart_open/smart_open_lib.py", line 138, in smart_open return file_smart_open(parsed_uri.uri_path, mode)
File "/home/liangn/PythonProjects/venvLiang/lib/python2.7/site-packages/smart_open/smart_open_lib.py", line 642, in file_smart_open return compression_wrapper(open(fname, mode), fname, mode)
File "/home/liangn/PythonProjects/venvLiang/lib/python2.7/site-packages/smart_open/smart_open_lib.py", line 630, in compression_wrapper return make_closing(GzipFile)(file_obj, mode)
File "/usr/lib64/python2.7/gzip.py", line 94, in init fileobj = self.myfileobj = builtin.open(filename, mode or 'rb')
TypeError: coercing to Unicode: need string or buffer, file found
How did you install gensim, and what version is installed?
API changes in (currently pre-release) gensim 1.0 move load_word2vec_format()
to a helper class called KeyedVectors
.
At this point (February 2017) you probably don't want to be using a pre-release version unless you're an experienced gensim user and closely follow the release-notes [CHANGELOG.md][1]
.
If intentionally using a later version of gensim with this API change, you would instead use:
KeyedVectors.load_word2vec_format("GoogleNews-vectors-negative300.bin.gz", binary=True)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With