Gensim: AttributeError: 'ConcatenatedDoc2Vec' object has no attribute 'save'

Created on 4 Mar 2018  路  2Comments  路  Source: RaRe-Technologies/gensim

I have trained the doc2vec model models_by_name['dbow+dmm'].

I have made predictions with it an I am satisfied with its performance.

I want it to persist. I tried to save it with the command below.

models_by_name['dbow+dmm'].save('dbow+dmm.doc2vec')

I got the following wrror message.

AttributeError Traceback (most recent call last)
in ()
----> 1 models_by_name['dbow+dmm'].save('dbow+dmm.doc2vec')
2 # model = Doc2Vec.load(fname) # you can continue training with the loaded model!

AttributeError: 'ConcatenatedDoc2Vec' object has no attribute 'save'

How do I save a 'ConcatenatedDoc2Vec' doc2vec model?

Thanks!

Most helpful comment

Thanks! I should have checked out the code. Late last night I found a work around. Thought I would share.

I made the model with:

models_by_name['dbow+dmm'] = ConcatenatedDoc2Vec([simple_models[1], simple_models[2]])

I save the model with:

simple_models[1].save('toxic_1.doc2vec')
simple_models[2].save('toxic_2.doc2vec')

I loaded the model with:

model_1 = Doc2Vec.load('toxic_1.doc2vec')
model_2 = Doc2Vec.load('toxic_2.doc2vec')

I recreated the model with:

model_1_2 = ConcatenatedDoc2Vec([model_1, model_2])

It repeated my earlier predictions.

I wish to credit a great tutorial for doc2vec:
https://github.com/RaRe-Technologies/gensim/blob/develop/docs/notebooks/doc2vec-IMDB.ipynb

Thanks again for your support!

All 2 comments

Hello @stagOak, ConcatenatedDoc2Vec is wrapper-only class, this doesn't provide save/load functionality.

https://github.com/RaRe-Technologies/gensim/blob/916e423a1654d87646fc522d8862a81c7a7cb4fc/gensim/test/test_doc2vec.py#L465-L484

If you want to save it, you can try to use pickle (or save all models from self.models calling save attribute for each model & load all models & create ConcatenatedDoc2Vec again)

Thanks! I should have checked out the code. Late last night I found a work around. Thought I would share.

I made the model with:

models_by_name['dbow+dmm'] = ConcatenatedDoc2Vec([simple_models[1], simple_models[2]])

I save the model with:

simple_models[1].save('toxic_1.doc2vec')
simple_models[2].save('toxic_2.doc2vec')

I loaded the model with:

model_1 = Doc2Vec.load('toxic_1.doc2vec')
model_2 = Doc2Vec.load('toxic_2.doc2vec')

I recreated the model with:

model_1_2 = ConcatenatedDoc2Vec([model_1, model_2])

It repeated my earlier predictions.

I wish to credit a great tutorial for doc2vec:
https://github.com/RaRe-Technologies/gensim/blob/develop/docs/notebooks/doc2vec-IMDB.ipynb

Thanks again for your support!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

volj1 picture volj1  路  4Comments

johann-petrak picture johann-petrak  路  3Comments

menshikh-iv picture menshikh-iv  路  4Comments

jeradf picture jeradf  路  4Comments

simonm3 picture simonm3  路  3Comments