[PYTHON] [Word2Vec: Warning Action] DeprecationWarning: Call to deprecated `__getitem__` (Method will be removed in 4.0.0, use self.wv.__getitem__ () instead).

Deprecation Warning was issued, so a remedy memo

cofirm.py


from gensim.models import word2vec

model = word2vec.Word2Vec.load("hoge.model")
vec = model["queen"]
print(len(vec.tolist()))
$ python3 confirm.py
confirm.py:7: DeprecationWarning: Call to deprecated `__getitem__` (Method will be removed in 4.0.0, use self.wv.__getitem__() instead).
  vec = model["queen"]
300

A warning will appear, so Change the program as follows.

confirm.py


from gensim.models import Word2Vec

model = Word2Vec.load("hoge.model")
vec = model.wv['queen']
print(len(vec.tolist()))
$ python3 confirm.py
300

The warning has disappeared. (´ ▽ `)

Recommended Posts

[Word2Vec: Warning Action] DeprecationWarning: Call to deprecated `__getitem__` (Method will be removed in 4.0.0, use self.wv.__getitem__ () instead).
How to use the __call__ method in a Python class
Config value:'pages'. Warning: The'pages' configuration option has been deprecated and will be removed in a future release of MkDocs. Use'nav' instead.