An Empirical Evaluation of doc2vec with Practical Insights into Document Embedding Generation

Jey Han Lau, Timothy Baldwin

Abstract

Recently, Le and Mikolov (2014) proposed doc2vec as an extension to word2vec (Mikolov et al., 2013a) to learn document-level embeddings. Despite promising results in the original paper, others have struggled to reproduce those results. This paper presents a rigorous empirical evaluation of doc2vec over two tasks. We compare doc2vec to two baselines and two state-of-the-art document embedding methodologies. We found that doc2vec performs robustly when using models trained on large external corpora, and can be further improved by using pre-trained word embeddings. We also provide recommendations on hyper-parameter settings for general purpose applications, and release source code to induce document embeddings using our trained doc2vec models.

Introduction

The introduction of doc2vec (also known as Paragraph Vector) promised a powerful unsupervised method for learning embeddings of arbitrary-length word sequences. However, the initial excitement was tempered by widespread reports of difficulty in replicating the original state-of-the-art results. This study serves as a rigorous "sanity check," addressing confusion over model architectures (dbow vs. dmpv), baseline comparisons, and hyperparameter sensitivity.

Methodology

The authors evaluate two primary versions of doc2vec:

  • dbow (Distributed Bag of Words): A simpler model that ignores word order and predicts words in a document given a document ID.
  • dmpv (Distributed Memory): A more complex model that considers word order by concatenating document and word vectors to predict the next word.

These models were compared against several baselines, including simple word vector averaging (using Skip-gram and CBOW), an n-gram baseline using Jensen-Shannon divergence, and state-of-the-art methodologies like skip-thought vectors and paragram-phrase.

A key methodological contribution is the exploration of external training. Instead of limiting training to the task-specific dataset, the authors trained doc2vec on massive general-purpose corpora: English Wikipedia (~2 billion tokens) and AP-NEWS (~0.9 billion tokens). This allows for testing whether doc2vec can function as an effective "off-the-shelf" feature extractor.

The evaluation spanned two distinct tasks to capture the effect of document length:

  1. CQADupStack (Forum Question Duplication): 12 subforums from StackExchange with an average document length of 130 words.
  2. STS (Semantic Textual Similarity): Short sentences from SemEval 2015 with an average length of 13 words.

Results and Discussion

The empirical results provide a clear "sanity check" for the algorithm. Most notably, the simpler dbow variant was the clear winner in almost every test, despite the theoretical advantages of the more complex dmpv model.

Performance of doc2vec and baselines on CQADupStack subforums.

As shown in Table 1, dbow achieved near-perfect AUC scores on several subforums (e.g., 1.00 on Gaming and Stats), consistently outperforming word averaging and n-gram baselines. The study also found that doc2vec is particularly robust when trained on large external corpora like Wikipedia, performing nearly as well as models trained on in-domain data.

However, document length is a critical factor. While doc2vec is a powerhouse for longer forum posts, its advantage over simple word vector averaging diminishes significantly on short sentences, such as those in the STS task. For such short texts, the authors suggest that specialized word averaging methods like paragram-phrase might still be preferable.

Qualitative Analysis: The Negative Sampling Effect

A fascinating qualitative insight emerged from t-SNE visualizations of the embeddings. The authors observed that doc2vec document embeddings naturally distance themselves from high-frequency "function words" like the, to, and in.

t-SNE visualization of doc2vec (dbow) embeddings showing document vector proximity to content words.

This phenomenon is attributed to the negative sampling mechanism used during training. Because frequent words are often selected as negative samples, the training process forces the document vector to align more closely with rare, high-information "content words" (e.g., tech, bangalore). This effectively results in an automatic weighting of words based on their semantic importance.

Conclusion and Practical Recommendations

This paper clarifies much of the confusion surrounding doc2vec. For practitioners looking to generate document embeddings, the authors provide several key recommendations:

  • Prefer dbow: It is simpler, faster to train, and generally more accurate than dmpv.
  • Use Pre-training: Initializing dbow with pre-trained word2vec embeddings significantly boosts performance and speeds up convergence.
  • Tune Hyperparameters: dbow favors larger window sizes (around 15) and requires fewer epochs (20-400) compared to dmpv, which may need up to 1000 epochs to converge.
  • External Corpora: Using models pre-trained on large datasets like Wikipedia is a viable and effective strategy for general-purpose applications.

The authors have released their source code and pre-trained models to facilitate future research and provide a standardized baseline for document embedding tasks.

Summary updated

Abstract

Recently, Le and Mikolov (2014) proposed doc2vec as an extension to word2vec (Mikolov et al., 2013a) to learn document-level embeddings. Despite promising results in the original paper, others have struggled to reproduce those results. This paper presents a rigorous empirical evaluation of doc2vec over two tasks. We compare doc2vec to two baselines and two state-of-the-art document embedding methodologies. We found that doc2vec performs robustly when using models trained on large external corpora, and can be further improved by using pre-trained word embeddings. We also provide recommendations on hyper-parameter settings for general purpose applications, and release source code to induce document embeddings using our trained doc2vec models.
BibTeX
@inproceedings{lau2016empirical,
  author = {Jey Han Lau and Timothy Baldwin},
  title = {{An Empirical Evaluation of doc2vec with Practical Insights into Document Embedding Generation}},
  booktitle = {Rep4NLP @ ACL},
  year = {2016},
  url = {https://openreview.net/forum?id=OO4o-Af5J4K},
}
Figure