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

How Context Affects Language Models' Factual Predictions

Fabio Petroni, Patrick Lewis, Aleksandra Piktus, Tim Rocktäschel, Yuxiang Wu, Alexander H. Miller, Sebastian Riedel

Abstract

While large language models (LMs) like BERT store a surprising amount of factual knowledge within their weights, they are limited by fixed capacity and the risk of hallucinations. This paper explores whether off-the-shelf, pre-trained LMs can be transformed into powerful "open-book" question-answering systems without any additional supervised fine-tuning. By providing retrieved context as a second input segment, we demonstrate that BERT’s internal Next Sentence Prediction (NSP) mechanism acts as a natural relevance filter, allowing the model to significantly improve factual accuracy while remaining robust to noisy or adversarial information.

Introduction

Pre-trained language models have often been characterized as "closed-book" knowledge bases. However, their internal knowledge can be outdated or incomplete. Traditional "Retrieval-Augmented" architectures address this by combining search engines with machine-reading models, but these typically require expensive supervised training. This research investigates a "zero-shot" approach: can we achieve state-of-the-art factual prediction using purely unsupervised, off-the-shelf LMs? Furthermore, how do these models handle irrelevant or misleading context if they haven't been explicitly trained to ignore it?

Methodology

The researchers employed a zero-shot approach using the LAMA (Language Model Analysis) probe, which includes datasets like Google-RE, T-REx, and SQuAD. Cloze-style queries (e.g., "Dante was born in [MASK]") were augmented with four types of context:

  1. Oracle (ORA): Wikipedia snippets known to contain the answer.
  2. Retrieved (RET): Context found using a standard TF-IDF retrieval system.
  3. Generated (GEN): Context produced by a large autoregressive LM.
  4. Adversarial (ADV): Irrelevant context from a different entity but the same relation type.
Recall accuracy of the TF-IDF retrieval system across the Google-RE, T-REx, and SQuAD datasets as the number of retrieved paragraphs (k) increases.

A critical technical nuance was the input formatting. For BERT, the researchers used two segments separated by a [SEP] token, allowing them to analyze the utility of the Next Sentence Prediction (NSP) head—a component often dismissed in recent literature.

Key Insights: NSP as a Relevance Filter

The most striking finding is that BERT's NSP pre-training task makes it naturally robust to noise. When the NSP score for a (query, context) pair is low, BERT effectively "ignores" the context and relies on its internal knowledge. This provides a functional advantage over models like RoBERTa, which were trained without the NSP objective.

As shown in the performance analysis, the "Two-Segment" formatting is vital. In adversarial setups (ADV), BERT’s performance only dropped by 0.5% compared to the context-free baseline when using two segments. However, if the query and adversarial context were merged into a single segment (disabling NSP-style processing), performance plummeted by 12.4%.

P@1 difference across various context types (Adversarial, Generated, Retrieved, Oracle) comparing BERT and RoBERTa under different input segment configurations.

Key Results and Performance

  • Massive Accuracy Gains: Adding retrieved context (B-RET) improved BERT's mean precision (P@1) from 30.5% to 42.8% across all LAMA tasks.
  • Oracle Potential: With "Oracle" Wikipedia snippets, accuracy jumped to 63.6%, suggesting that the primary bottleneck for these systems is the retrieval mechanism rather than the LM's reading ability.
  • Unsupervised Parity: A purely unsupervised BERT combined with a simple retriever matched or outperformed the supervised DrQA baseline on several benchmarks, highlighting the power of pre-trained representations.

Conclusion and Future Work

This study suggests the NLP community should re-evaluate the utility of the Next Sentence Prediction task. While often overlooked in standard benchmarks, NSP provides structural benefits for multi-segment reasoning and robustness. Future work remains to address the single-token constraint of the LAMA probe and to explore dense retrieval methods to further close the gap between retrieved and oracle performance.

Summary updated

BibTeX
@inproceedings{petroni2020how,
  author = {Fabio Petroni and Patrick Lewis and Aleksandra Piktus and Tim Rocktäschel and Yuxiang Wu and Alexander H. Miller and Sebastian Riedel},
  title = {{How Context Affects Language Models' Factual Predictions}},
  booktitle = {AKBC},
  year = {2020},
  url = {https://openreview.net/forum?id=B24bqyrw0-5},
}
Figure