0

I import a text file from the desktop to do with gensim model on jupyter notebook. However, it return that:

"AttributeError Traceback (most recent call last) in ----> 1 model = word2vec.load(r'C:\Users\qlm\Desktop\globalwarming.txt')

AttributeError: module 'gensim.models.word2vec' has no attribute 'load'"

How can I fix this problem

import numpy as np
import pandas as pd
import gensim
from matplotlib import pyplot as plt
from gensim.models import word2vec
from collections import defaultdict
from sklearn.cluster import KMeans

model = word2vec.Text8Corpus(r'C:\Users\qlm\Desktop\globalwarming.txt')
model = word2vec.load(r'C:\Users\qlm\Desktop\globalwarming.txt')
abiratsis
  • 7,051
  • 3
  • 28
  • 46
NewBiecoder
  • 13
  • 1
  • 3

1 Answers1

0

There is a module named word2vec and inside it a class named Word2Vec, since the Word2Vec class is imported in __init__.py of gensim.models you can import it as you tried before:

from gensim.models import Word2Vec

Then you'll have access to the load method.

You can also use the full namespace too.

So:

# Will work as long as models.__init__ keep it available
from gensim.models import Word2Vec

But:

# Will always work as long as the namespace is not altered
from gensim.models.word2vec import Word2Vec

I personally prefer the second choice.

lee-pai-long
  • 2,147
  • 17
  • 18