NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

Context Aware Document Embedding

Zhaocheng Zhu, Junfeng HuarXiv 2017

Abstract: Recently, doc2vec has achieved excellent results in different tasks. In this paper, we present a context aware variant of doc2vec. We introduce a novel weight estimating mechanism that generates weights for each word occurrence according to its contribution in the context, using deep neural networks. Our context aware model can achieve similar results compared to doc2vec initialized by Wikipedia trained vectors, while being much more efficient and free from heavy external corpus. Analysis of context aware weights shows they are a kind of enhanced IDF weights that capture sub-topic level keywords in documents. They might result from deep neural networks that learn hidden representations with the least entropy.

Introduction: The Limitation of Equal Attention

In Natural Language Processing (NLP), representing a document as a single mathematical vector—an embedding—is a foundational task. One of the most popular methods for this is doc2vec, specifically the Distributed Bag of Words (DBOW) variant. However, DBOW suffers from a significant logical flaw: it treats every word occurrence with equal weight.

In reality, human language processing is selective. In a sentence like "There are many activities including but not limited to running, jumping, and swimming," the words "running" and "swimming" carry far more semantic weight than functional phrases like "including" or "limited to." While global techniques like TF-IDF attempt to address this by down-weighting common words across a corpus, they fail to account for local context—the specific importance of a word within its immediate surroundings.

Methodology: The Context Aware (CA) Framework

The authors propose a "Context Aware" (CA) variant of doc2vec called w-dbow (weighted DBOW). This approach moves beyond global frequency to estimate the "contribution" of a word based on its specific context through a three-step process:

  1. Initial Training: A standard doc2vec model is trained on the target corpus to establish baseline document vectors.
  2. Weight Estimation via Auxiliary Models: This is the core innovation. The researchers train an auxiliary neural network—either a Convolutional Neural Network (CNN) or a Gated Recurrent Unit (GRU)—to predict the document vector based on the sequence of word vectors.
  3. Weighted Re-training: The document embeddings are re-trained, but the influence of each word is scaled by the weights calculated in the previous step.
CNN architecture used as an auxiliary model to estimate word weights based on local context.

To determine a specific word's weight, the model uses a "replacement shift" method: a word is replaced with a random word, and the resulting shift (cosine distance) in the predicted document vector is measured. A large shift indicates a critical word, while a tiny shift suggests a filler word that is easily inferred from context. To maintain training stability, a "global temperature softmax" is applied to ensure the average word weight remains 1.0.

Key Insights: Enhanced IDF and Entropy

The weights learned by the CA models provide several theoretical and practical insights:

  • "Enhanced IDF": The learned weights correlate with Inverse Document Frequency (IDF) but are more nuanced. They capture "sub-topic level keywords"—words that might be common generally but are vital to the specific topic at hand.
  • Entropy Minimization: The authors suggest that deep neural networks naturally learn hidden representations with the "least entropy." The initial layers of these networks effectively learn to filter noise and focus on high-information signals.
  • Asymmetric Context: Unlike standard bag-of-words models, the CNN and GRU auxiliary models can extract asymmetric features, recognizing that a word's importance may depend more heavily on preceding or succeeding text.
Visualization of context-aware weights assigned to words in sample sentences, highlighting key semantic contributors.

Results and Evaluation

The model was evaluated on the Semantic Textual Similarity (STS) tasks from SemEval (2012–2015) across five domains: answers-forums, headlines, answers-students, belief, and images.

  • Performance vs. Baselines: The CA models (both CNN and GRU versions) consistently outperformed standard doc2vec across all domains.
  • Efficiency vs. Scale: Remarkably, the CA(CNN) model achieved results comparable to, and in some cases better than, doc2vec models pre-initialized with massive external datasets like English Wikipedia (WIKI). For example, in the "answers-students" category, CA(CNN) achieved a score of 0.683, surpassing the WIKI-initialized model's 0.654.
  • Qualitative Representation: t-SNE visualizations indicated that while standard DBOW is effective for broad clustering, the Context Aware models provide a more fine-grained representation, which is critical for distinguishing subtle differences in sentence meaning.

Conclusion and Future Directions

Context Aware Document Embedding offers a powerful way to generate high-quality embeddings using only a specific, smaller dataset, bypassing the need for massive external corpora. While the method introduces some computational overhead due to the auxiliary model training and weight calculation, the gains in efficiency and accuracy are significant.

Future work may address the computational cost through more efficient sampling methods and explore the performance of these context-aware weights in other downstream NLP tasks, such as sentiment analysis or document classification. Additionally, the sensitivity of the "temperature" hyperparameter suggests that automated tuning methods could further stabilize the training process.

Summary updated

BibTeX
@misc{zhu2017context,
  author = {Zhaocheng Zhu and Junfeng Hu},
  title = {{Context Aware Document Embedding}},
  year = {2017},
  eprint = {1707.01521},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/1707.01521},
}
Figure