Cross-Domain Generalization Through Memorization: A Study of Nearest Neighbors in Neural Duplicate Question Detection

Yadollah Yaghoobzadeh, Alexandre Rochette, Timothy J. HazenarXiv 2020

TL;DR

This paper demonstrates that a simple $k$-nearest neighbors ($k$-NN) retrieval approach, paired with domain-adapted BERT representations, can outperform standard cross-entropy classifiers for cross-domain Duplicate Question Detection (DQD). By "memorizing" labeled question pairs from a source domain in a rich embedding space, $k$-NN provides remarkably robust generalization to new target domains, especially under severe distributional shifts.

What Problem Does This Paper Address?

Duplicate Question Detection (DQD) is vital for community forums like StackExchange or automated FAQ systems. It identifies when two differently phrased questions share the same underlying intent, helping to reduce redundancy and surface existing answers quickly.

However, training effective DQD models requires large amounts of labeled data. While a few popular forums have plenty of metadata to harvest labels from, newly created or niche forums suffer from severe data sparsity. A common workaround is to train a model on a data-rich source domain (e.g., Quora) and deploy it on a data-scarce target domain (e.g., AskUbuntu). Unfortunately, standard neural classifiers generalize poorly across domains due to shifts in vocabulary, syntax, and even the underlying criteria used to define a "duplicate."

Methods

The authors propose a two-step approach that combines unsupervised domain adaptation with instance-based learning ($k$-NN):

  1. Domain-Adaptive Pre-training (DAPT): Before looking at any labeled DQD data, the authors take a standard pre-trained BERT model ($BERT_{BASE}$) and fine-tune it on unlabeled text from the target domain using self-supervised objectives (Masked Language Modeling). This tailors the model's embedding space to the specific vocabulary and semantics of the target domain, resulting in $BERT_{DAPT}$.
  2. Question Pair Representation: To represent a pair of questions, they concatenate them into a single sequence separated by a [SEP] token. The embedding of the final layer's [CLS] token serves as the joint representation of the pair.
  3. $k$-NN Retrieval & Scoring: Instead of training a classification layer (CLF) with cross-entropy loss on the source domain, they encode all labeled source domain pairs into the $BERT_{DAPT}$ embedding space. To classify a new target domain pair, they find its $k$-nearest neighbors ($k=100$) among the source pairs using cosine distance and aggregate their labels, weighting closer neighbors more heavily.
Figure 1: An illustration of our k−NN. Question pairs from both Source and Target domains are encoded by in a common representation space, which is the result of unsupervised adaptation of BERT on Target data. The top k similar items from Source are then aggregated based on their label and distance to provide a final confidence.

Datasets

The experiments evaluate cross-domain generalization targeting AskUbuntu as the evaluation set. The models are trained on four different source datasets:

  • AskUbuntu: In-domain baseline (9,106 training pairs).
  • SuperUser: A tech forum highly similar to AskUbuntu (9,106 training pairs).
  • Sprint: A tech FAQ dataset with low lexical similarity to AskUbuntu (9,106 training pairs).
  • Quora: A general-domain duplicate question dataset (9,100 training pairs) with a significantly different distribution and negative sampling strategy.

Unsupervised text from 33 StackExchange domains (approx. 1.5M questions) was also leveraged for large-scale DAPT.

Key Insights and Ideas

  • The Power of Memorization under Extreme Shift: The most striking "aha moment" occurs when training on Quora and testing on AskUbuntu. Standard classifiers fail miserably here because they overfit to Quora's specific data-distribution quirks. In contrast, $k$-NN handles this massive distributional shift gracefully by mapping the target pairs into a well-structured domain-adapted space and finding the closest logical equivalents from the source data.
  • $k$-NN is Highly Sensitive to Embedding Quality: While a standard classifier can dynamically alter its internal representations during task-specific training, $k$-NN relies entirely on a fixed embedding space. Consequently, performing Domain-Adaptive Pre-training (DAPT) on the target domain is absolutely critical for $k$-NN to succeed. Without it (using vanilla $BERT_{BASE}$), $k$-NN actually underperforms standard classification on closely related domains.
  • Diverse Unsupervised Data is Complementary: Pre-training BERT on a broad mix of 33 StackExchange domains yielded better downstream $k$-NN performance than pre-training solely on the target domain itself, proving that exposure to diverse technical vocabularies creates a more robust embedding space.

Key Results

Performance is measured using the normalized Area Under the Curve metric, specifically AUC(.05), to focus on low false-positive rates.

  • Massive Gains on Distant Domains: When using Quora as the source domain and AskUbuntu as the target, $k$-NN with $BERT_{DAPT}$ achieved an AUC(.05) of 0.800, drastically outperforming the standard cross-entropy classifier (CLF) at 0.609.
  • Consistent Wins on Related Domains: Even when training on the closely related SuperUser forum, $k$-NN outperformed CLF (0.908 vs 0.870).
  • The Impact of Pre-training Scale: As shown in the paper's ablation studies, moving from no adaptation (vanilla BERT) to multi-domain adaptation (33 SE domains) boosted $k$-NN performance from 0.755 to 0.917 when transferring from SuperUser to AskUbuntu.

Limitations and Future Work

A key limitation is that the text representations are frozen during the $k$-NN phase; the embedding space is never explicitly optimized to minimize distance for the DQD task itself.

For future work, the authors plan to explore whether these promising results hold true for other sentence-matching and NLP tasks. They aim to investigate methods that explicitly train neural networks to build embedding spaces optimized specifically for robust, cross-domain $k$-NN memorization.

Summary updated

BibTeX
@misc{yaghoobzadeh2020cross,
  author = {Yadollah Yaghoobzadeh and Alexandre Rochette and Timothy J. Hazen},
  title = {{Cross-Domain Generalization Through Memorization: A Study of Nearest Neighbors in Neural Duplicate Question Detection}},
  year = {2020},
  eprint = {2011.11090},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2011.11090},
}
Figure