title: Gensim Doc2Vec Access Vectors by Document Author
body: <p>I have three documents in a df:</p>
  
  <pre><code>id    author    document
  12X   john      the cat sat
  12Y   jane      the dog ran
  12Z   jane      the hippo ate
  </code></pre>
  
  <p>These documents are converted into a corpus of <code>TaggedDocuments</code> with the tags being the typical practice of semantically meaningless ints:</p>
  
  <pre><code>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))
  </code></pre>
  
  <p>This corpus is then used to train my <code>Doc2Vec</code> model:</p>
  
  <pre><code>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)
  </code></pre>
  
  <p>The resulting vectors of the model are accessed like this:</p>
  
  <pre><code>model.docvecs.vectors_docs
  </code></pre>
  
  <p>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?</p>
  
  <p>I think the basic idea is to identify the int tags that correspond to Jane and then do something like this to access them:</p>
  
  <pre><code>from operator import itemgetter 
  a = model.docvecs.vectors_docs
  b = [1, 2]
  itemgetter(*b)(a)
  </code></pre>
  
  <p>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.</p>