Masked-Token Prediction Uses Corrupted Inputs

Masked-token prediction separates clean text, corrupted model input, and selected targets. Distinguish input corruption from attention masking and calculate a selected-token loss with bidirectional context.

Masked-token prediction creates targets by hiding or changing selected input tokens. An encoder reads the corrupted sequence with left and right context, then predicts the original token at selected positions.

Separate Clean Text, Model Input, and Target

Start with the clean token sequence:

A B C

Select position 2 and present the corrupted input:

A <mask> C

The target at position 2 is B. If the vocabulary logits at that position are z2:(V)z_2:(V), the selected loss is

logp(BA,<mask>,C).-\log p(B\mid A,\texttt{<mask>},C).

The model is permitted to use both A and C because its self-attention is not causal.

Loss Selection Is Not Attention Masking

The selected prediction position still participates in attention. “Masked” in masked-token prediction describes input corruption and target selection; it is not the same operation as filling an attention-score entry with -\infty.

Keep three ledgers:

LedgerExample
clean tokensA B C
model inputA <mask> C
supervised targetposition 2 → B

This separation also exposes accidental leakage, such as leaving B unchanged while treating the prediction as if it had been hidden under every corruption policy.

BERT Is One Historical Design, Not the Family Definition

BERT used a particular corruption procedure and combined masked-language-model pretraining with a next-sentence objective in its reported experiments. Later encoder models changed objectives, corruption, data, and training. Encoder-only means the architecture retains the encoder information flow; it does not mean every model must reproduce all BERT training choices.

A Small Loss Calculation

If the model assigns target probability p(B)=0.25p(B)=0.25, the selected-token loss is

log(0.25)1.3863-\log(0.25)\approx1.3863

using natural logarithms. Unselected positions contribute nothing under a selected-only mean, though another implementation may report additional diagnostics.

Q1. Distinguish two kinds of masking

Does replacing B with <mask> by itself forbid the query at position 2 from attending to position 3?

Answer it first, then check.

Hint
Ask whether the encoder uses bidirectional self-attention.
Solution
No. Position 2 may still read position 3 unless a separate attention mask forbids it.
Not attempted
Review

Not marked done.

Reference

Pause and reflect

In your own words, note what you understood, what remains unclear, or what you want to revisit. The note stays with this lesson.

0 of 1 exercises marked done

Review

Not marked done.

LLM PrimerMasked-Token Prediction Uses Corrupted Inputshttps://llmprimer.com/transformers/transformer-architecture-families/masked-token-prediction-uses-corrupted-inputs© 2026 LLM Primer