I have three documents in a df:
id author document
12X john the cat sat
12Y jane the dog ran
12Z jane the hippo ate
These documents are converted into a corpus of TaggedDocuments with the tags being the typical practice of semantically meaningless ints:
def read_corpus(documents):
for i, plot in enumerate(documents):
yield gensim.models.doc2vec.TaggedDocument(gensim.utils.simple_preprocess(plot, max_len=30), [i])
train_corpus = list(read_corpus(df.document))
This corpus is then used to train my Doc2Vec model:
model = gensim.models.doc2vec.Doc2Vec(vector_size=50, min_count=2, epochs=55)
model.build_vocab(train_corpus)
model.train(train_corpus, total_examples=model.corpus_count, epochs=model.epochs)
The resulting vectors of the model are accessed like this:
model.docvecs.vectors_docs
How would I tie the original df to the resulting vectors? Now that all the documents are trained and vectors are identified for each one, I want to query the set of vectors by author. For example, if I want to return a set of vectors only for Jane, how would I do so?
I think the basic idea is to identify the int tags that correspond to Jane and then do something like this to access them:
from operator import itemgetter
a = model.docvecs.vectors_docs
b = [1, 2]
itemgetter(*b)(a)
How would I identify the tags though? They are only meaningful to the model and the tagged documents, so they don't join back to my original df.