I want to use gensim to train a word2vec model
python 3.5.3
gensim 2.1.0
numpy 1.12.1+mkl
scipy 0.19.0
import gensim
import codecs
class MySentences(object):
def __init__(self,filename):
self.filename=filename
def __iter__(self):
with codecs.open(self.filename) as f:
for line in f.readlines():
wordlist=list()
for word in line:
wordlist.append(word)
yield wordlist
sentences=MySentences('D:/Documents/Data/icwb2-data-processed/pku_training.rmspace.utf8')
model=gensim.models.Word2Vec(sentences)
model.save('w.model')
I run this code, and i cause the error:
AttributeError: module 'gensim' has no attribute 'models'
I make this error due to i named this file 'gensim.py'
thank @BurhanKhalid !!!
from gensim.models import Word2Vec
, then replacemodel=gensim.models.Word2Vec(sentences)
withmodel=Word2Vec(sentences)
does it work then? - Lomtrurgensim.py
. - Burhan Khalid