Next-sentence prediction (NSP) is a binary pretraining objective in which a model receives two text segments and decides whether the second one actually follows the first in the original document or was drawn at random from elsewhere in the corpus. In language models and the wider field of artificial intelligence, NSP is best known as one of the two pretraining tasks of BERT, where it ran alongside masked language modeling to teach an encoder-only model about relationships between sentences rather than only relationships between tokens.
The objective was designed to help downstream tasks that compare two passages, such as question answering and natural language inference. Later research showed that NSP is a weak and partly redundant signal, so most successors either removed it or replaced it with harder sentence-level tasks. It remains a useful concept for understanding how encoder pretraining evolved.
How next-sentence prediction works during pretraining
Next-sentence prediction turns unlabeled text into a self-supervised classification task. The training pipeline samples a segment A from a document and then chooses segment B: in 50 percent of cases B is the segment that genuinely follows A, labeled IsNext, and in the other 50 percent B is a random segment from a different document, labeled NotNext.
The two segments are packed into one input sequence with special tokens: a classification token at the start, a separator token between and after the segments, and segment embeddings that mark every token as belonging to A or B. The final hidden state of the classification token feeds a small two-way classifier, and its cross-entropy loss is added to the masked language modeling loss so that both objectives update the same weights.
The following table summarizes the main components of the original NSP setup and the role each one plays.
| Component | Typical setting | Purpose |
|---|---|---|
| Segment pair | Two spans, often several sentences each | Provides the context to compare |
| Label balance | 50 percent IsNext, 50 percent NotNext | Prevents a trivial majority-class answer |
| Sequence length | Up to 512 tokens combined | Fits the encoder context window |
| Classification token | First position of the input | Pools the pair into one vector |
| Segment embeddings | Learned A and B vectors | Tells the model which span is which |
| Joint loss | NSP loss plus masked token loss | Trains both objectives at once |
The term sentence is used loosely. In practice a segment is a contiguous span of text that may contain several sentences, chosen so that the combined length stays within the token budget.
What NSP was meant to teach the model
The intended benefit of NSP was discourse-level understanding: knowing whether two passages belong together, share an argument or continue a narrative. Masked token prediction mostly captures local syntax and word meaning, so the designers added NSP to give the classification token a reason to encode cross-segment relationships.
Ablations in the original BERT work reported that removing NSP slightly hurt results on paired-input benchmarks such as question-answering inference and textual entailment. That finding made NSP a standard ingredient of many early encoder models, until better-controlled experiments challenged it.
Why later models dropped or replaced NSP
The central criticism is that NSP is too easy for the wrong reason. Because negative segments come from a different document, the model can often solve the task by detecting a topic mismatch instead of judging coherence. Training accuracy on NSP typically climbs above 95 percent early in pretraining, which suggests that little useful signal remains afterward.
Follow-up studies found that training on full contiguous sequences without NSP, with larger batches and more data, matched or exceeded the original results. Other work kept a sentence-level objective but made it harder, for example by asking whether two consecutive segments appear in the correct or swapped order. The table below compares NSP with its main alternatives.
| Objective | Negative examples | What the model must learn | Typical outcome |
|---|---|---|---|
| Next-sentence prediction | Random segment from another document | Topic match and some coherence | Easy task, limited benefit |
| Sentence-order prediction | Same two segments in swapped order | Discourse order and coherence | Harder task, better transfer |
| Three-way sentence structure | Previous, next or random segment | Direction and relatedness | Richer signal, more complex setup |
| No sentence objective | None | Only token-level prediction | Often equal or better with more data |
Modern decoder-only models do not use NSP at all. Their next-token prediction objective over long contiguous documents already exposes them to discourse structure, which makes a separate sentence classifier unnecessary.
Where NSP still matters in practice
Although rarely chosen for new pretraining runs, NSP remains relevant because many deployed BERT checkpoints still carry a trained NSP head. Practitioners meet it in several concrete situations, summarized in the following decision table.
| Situation | Recommended approach | Reason |
|---|---|---|
| Fine-tuning a BERT checkpoint | Reuse the pooled classification token | It was pretrained to summarize pairs |
| Pretraining a new encoder | Skip NSP or use order prediction | Better quality per compute budget |
| Zero-shot coherence scoring | Query the existing NSP head | Gives a cheap relatedness estimate |
| Reproducing a published baseline | Keep NSP exactly as described | Results depend on the original recipe |
| Long-document modeling | Use contiguous full-length inputs | Short segment pairs waste context |
The pretrained NSP head can serve as a lightweight relatedness detector, for example to flag a retrieved passage that has nothing to do with a query. Its scores should be treated as rough signals, not calibrated probabilities.
Limitations and common misconceptions
Several misunderstandings surround NSP, and they matter when engineers interpret old results or design new training pipelines.
- NSP does not generate text: it is a classifier, not a decoding method, and it is unrelated to how a chat model writes its next sentence.
- High NSP accuracy does not prove deep coherence understanding, because topic cues alone solve most cases.
- Short segment pairs reduce the effective context length seen during pretraining, which can hurt tasks that need long-range dependencies.
- Removing NSP is not automatically harmful: well-tuned models without it often perform equally well or better.
A non-technical view
Imagine a reading test. You see two short passages. You must say whether the second one comes right after the first. Sometimes it does. Sometimes it comes from a completely different book. Next-sentence prediction is this test, given to a computer model millions of times while it learns.
The goal was to teach the model how passages fit together. The problem is that the test is often too simple. A passage about cooking rarely follows one about football, so the model can guess from the topic alone. That is why newer models skip this test or use a harder version.
A concrete example
A search team at a mid-sized online retailer uses a BERT-based encoder to check customer help articles. Before publishing a merged article, an editor pastes in pairs of consecutive paragraphs. The team runs each pair through the checkpoint’s existing NSP head and flags pairs whose IsNext score falls below 0.5.
In a batch of 400 merged articles, the tool flags 31 pairs. On review, 24 of them are genuine errors where a paragraph about returns was pasted into an article about shipping times. The remaining 7 are false alarms caused by abrupt but correct topic shifts. The team keeps the check as a cheap first filter and leaves the final decision to human editors, which matches the limited reliability of NSP scores.