Doc2Vec — Document Embeddings

Machine Learning
Introduced by
Quoc V. Le & Tomas Mikolov
Year
2014
Type
Document-embedding representation learning

What does it do?

Doc2Vec, also known as Paragraph Vector, is a representation-learning method introduced by Le and Mikolov (2014) that maps whole documents to fixed-length dense vectors.

Documents with similar content tend to receive vectors that lie close together, which supports document comparison and classification. The method is aimed at cases where a single vector per document is needed rather than one vector per word.

The intuition behind the method

A document is made of many words of varying length, but most models need each document expressed as one fixed-size set of numbers. Doc2Vec learns a single dense vector for each document by training it, alongside its words, to predict the text it contains. Documents that talk about similar things end up with similar vectors, so the geometric distance between two vectors becomes a usable measure of how related the documents are.

History

Doc2Vec, or Paragraph Vector, was introduced by Quoc Le and Tomas Mikolov in their 2014 ICML paper Distributed Representations of Sentences and Documents. It extended the idea of learning dense word vectors to whole sentences and documents, giving each piece of text its own learned fixed-length representation.

When to use it

Choose Doc2Vec when you need one dense vector per document for similarity search, comparison, clustering or classification, and when you have a reasonably large collection of documents of meaningful length that can be preprocessed consistently. As a practical guideline, aim for at least about 100 documents; this figure is a rule of thumb rather than a formal requirement. Do not choose it for a handful of documents or for very short texts: each document vector is fitted from that document's own words, and a small corpus gives too little material to fit them reliably. If the collection is small, a simpler weighted bag-of-words representation such as TF-IDF may be easier to inspect and justify.

Limitations and considerations

  • Document vectors are learned together with word parameters from the training corpus, so they are meaningful within the model trained on that corpus; representing a new document requires an inference step rather than a lookup.
  • Each document vector is fitted from that document's own words, so small corpora or very short documents give unreliable embeddings.
  • Results depend on consistent text preprocessing before training and on training choices such as vector size and the number of epochs.

Source conditions do not replace independent scientific review or validation by an analysis engine.

Strengths

  • Gives each document a single fixed-length dense vector, whatever its original length.
  • Similar documents tend to receive nearby vectors, so comparison and similarity search can be done by distance.
  • The vectors can be passed directly as features to classifiers and relationship analyses.

Applications

  • Document similarity search and retrieval over a text collection.
  • Using document vectors as input features for text classification.
  • Clustering a corpus by semantic proximity between documents.
  • Comparing documents and exploring relationships among them after learning their vectors.

How it works

How it works

1

The corpus is cleaned and tokenised into the units the model will learn from. Preprocessing must be applied consistently across all documents, because inconsistent tokenisation makes the learned document vectors hard to compare.

2

Each document is paired with a unique tag (identifier). The model associates this tag with a learned vector, so every document keeps its own representation throughout training.

3

The model is trained over the tagged documents for several passes (epochs). In the distributed-memory variant described by Le and Mikolov, the document vector is combined with word vectors from a context window to predict the next word, so the document vector is updated as the model learns to predict the text it contains. The chosen vector size sets the dimensionality of the resulting embeddings.

4

After training, each document is represented by its fixed-length dense vector. These embeddings can be compared directly, for example by distance or similarity, or passed as input features to downstream classification or relationship analysis. A document that was not part of training is represented through an inference step, which fits a new vector while the learned word and model weights are held fixed.

Common pitfalls

  • Training on a small collection of documents produces noisy, unstable vectors, because the document vectors are fitted from the same limited text.
  • Applying preprocessing inconsistently across documents makes the learned vectors hard to compare.
  • Very short documents contain too few word co-occurrences to place them reliably in the vector space.
  • Keeping default vector size and epoch settings without checking how the embeddings behave on your own corpus.

Frequently asked questions

How is Doc2Vec different from word embeddings?

Word-embedding methods learn a vector for each word. Doc2Vec learns an additional vector for each whole document, so you get one fixed-length representation per document rather than having to combine word vectors yourself.

How many documents do I need?

The method needs a reasonably large collection of documents of meaningful length. As a practical guideline, aim for at least about 100 documents; this is a rule of thumb and should not be read as a formal requirement. With few documents, or with very short ones, the learned vectors become unreliable, because each document vector is fitted from its own words.

Do I need to preprocess the text first?

Yes. The corpus should be cleaned and tokenised consistently before training, otherwise the learned document vectors are hard to compare.

What can I do with the resulting vectors?

Each document becomes a fixed-length dense vector that you can compare by distance or similarity, or use directly as input features for classification and relationship analysis.

Related methods

Sources

  1. Le, Q. V. & Mikolov, T. (2014). Distributed Representations of Sentences and Documents. Proceedings of the 31st International Conference on Machine Learning (ICML), 1188-1196.

    Open publication reference