I've trained a model:
from gensim.models import Word2Vec
model = Word2Vec(master_sent_list,
min_count=5,
size=300,
workers=5,
window=5,
iter=30)
Saved it according to this post:
model.wv.save_word2vec_format("../moj_word2vec.txt")
!gzip ../moj_word2vec.txt
!python -m spacy init-model en ../moj_word2vec.model --vectors-loc ../moj_word2vec.txt.gz
Everything looks fine:
✔ Successfully created model
22470it [00:02, 8397.55it/s]j_word2vec.txt.gz
✔ Loaded vectors from ../moj_word2vec.txt.gz
✔ Sucessfully compiled vocab
22835 entries, 22470 vectors
I then load the model under a different name:
nlp = spacy.load('../moj_word2vec.model/')
Something goes wrong however, because I can't use common commands on nlp
; that I can on model
.
For example, these work:
model.wv.most_similar('police')
model.vector_size
But these don't:
nlp.wv.most_similar('police')
AttributeError: 'English' object has no attribute 'wv'
nlp.most_similar('police')
AttributeError: 'English' object has no attribute 'most_similar'
nlp.vector_size
AttributeError: 'English' object has no attribute 'vector_size'
So something seems to have broken in the loading, or perhaps the saving, could someone help please?