AttributeError: type object Word2Vec has no attribute load_word2vec_format

2024/10/11 10:21:29

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 ?

Answer
gojomo's answer is right

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 initself.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_openreturn 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_openreturn 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_wrapperreturn make_closing(GzipFile)(file_obj, mode)

File "/usr/lib64/python2.7/gzip.py", line 94, in initfileobj = self.myfileobj = builtin.open(filename, mode or 'rb')

TypeError: coercing to Unicode: need string or buffer, file found

https://en.xdnf.cn/q/69787.html

Related Q&A

Python - Core Speed [duplicate]

This question already has answers here:Getting processor information in Python(12 answers)Closed 8 years ago.Im trying to find out where this value is stored in both windows and osx, in order to do som…

App Engine, transactions, and idempotency

Please help me find my misunderstanding.I am writing an RPG on App Engine. Certain actions the player takes consume a certain stat. If the stat reaches zero the player can take no more actions. I start…

Speed differences between intersection() and object for object in set if object in other_set

Which one of these is faster? Is one "better"? Basically Ill have two sets and I want to eventually get one match from between the two lists. So really I suppose the for loop is more like:f…

Pandas.read_csv reads all of the file into one column

I have a csv file in the form "...","...","..."... with over 40 columns. When I used this simple code, it only gives me one massive key. Ive been messing with it for over …

Python lazy evaluation numpy ndarray

I have a large 2D array that I would like to declare once, and change occasionnaly only some values depending on a parameter, without traversing the whole array. To build this array, I have subclassed …

Python 2.7 NetworkX (Make it interactive)

I am new to NetworkX. Right now, I manage to connect all the nodes to this particular node. What I want to do next it to make it interactive e.g. able to make each of the node move by dragging using cu…

Normal Distribution Plot by name from pandas dataframe

I have a dataframe like below:dateTime Name DateTime day seconds zscore 11/1/2016 15:17 james 11/1/2016 15:17 Tue 55020 1.158266091 11/1/2016 13:41 james 11/1/2016 13:41 Tue 4926…

Change pyttsx3 language

When trying to use pyttsx3 I can only use English voices. I would like to be able to use Dutch as well. I have already installed the text to speech language package in the windows settings menu. But I …

pandas groupby dates and years and sum up amounts

I have pandas dataframe like this:d = {dollar_amount: [200.25, 350.00, 120.00, 400.50, 1231.25, 700.00, 350.00, 200.25, 2340.00], date: [22-01-2010,22-01-2010,23-01-2010,15-02-2010,27-02-2010,07-03-201…

Is Python on every GNU/Linux distribution?

I would like to know if is Python on every G/L distribution preinstalled or not. And why is it so popular on GNU/Linux and not so much on Windows?