﻿# The next-token label shift: which position predicts which target

Next-token training shifts reference labels relative to input positions. Learn how to align causal logits, boundary tokens and ignored targets without a double shift.

Author: Retrivium editorial team
Updated: 2026-11-03
Canonical URL: https://retrivium.ai/journal/causal-label-shift-next-token/
Language: en

Input and label tensors can look identical in a language-model training example while still describing next-token prediction. Some model interfaces perform the shift internally. Other pipelines require an explicit shift. Understanding the alignment prevents both learning to copy the current token and accidentally training against a token farther ahead.

## Name the state and its prediction separately

In a causal decoder, the hidden state at a position is computed with the current token and permitted preceding context. Its output scores are used to predict the token following that position. The input position and the predicted target position therefore have different identities even when tensors are stored with similar shapes. A diagram should label both. Saying that every position predicts itself erases the essential causal distinction and can hide a training objective that admits a trivial copy shortcut.

## Walk a short sequence through the loss

Take the input sequence begin, red, kite, end. The state for begin is compared with red; red is compared with kite; kite is compared with end. There is no following reference token for the final state inside this example unless the data contract provides one. Writing these pairs before batching makes the intended task explicit. The ending symbol can itself be a prediction target; its role differs from an artificial padding entry used only to equalize tensor lengths for storage.

## Locate the single shift in the pipeline

A collator may copy input identifiers into a labels field because the model’s loss function slices logits and labels into the required offset. If that collator already shifts the labels and the model shifts again, the reference alignment changes. Conversely, omitting both shifts compares incompatible positions. Inspect the documented model forward contract or its source and test a tiny known token sequence. Do not infer the shift from variable names alone: labels can denote an unshifted storage format rather than already aligned events.

## Boundary and masking rules complete the mapping

Ignored labels should remove the intended prediction events after alignment. For example, excluding a prompt from supervised answer loss requires checking which states predict the first answer token and the later answer tokens. A mask drawn over input words can be off by a position when interpreted as target events. Keep an explicit table of input identifier, prediction position, reference identifier and included-loss flag. This table provides a stronger debugging artifact than a single aggregate loss and exposes boundary behavior before a large training run.

## Primary research and implementation references

- [Attention Is All You Need](https://arxiv.org/abs/1706.03762).

- [PyTorch: CrossEntropyLoss](https://docs.pytorch.org/docs/2.15/generated/torch.nn.CrossEntropyLoss.html).

- [Hugging Face Transformers: Causal Language Modeling](https://huggingface.co/docs/transformers/tasks/language_modeling).

## Related engineering context

[Reproducible inference stacks: preserving a GPU pilot’s result](/journal/software-stack-reproducibility/); [A GPU inference benchmark you can trust](/journal/inference-benchmark-method/).
