esc
  • WorkflowsPages
  • Case studiesPages
  • Machine Learning FoundationsLearn
  • AI EngineeringLearn
  • AI Guardrails & Red TeamingLearn
  • UI/UXLearn
  • Design SystemsLearn
  • Production System DesignLearn
  • AI papersPages
  • Interview KitPages
  • Book a callContact
  • Download ResumeContact
Let’s talk

I’ll build the agent for it.

Masked vs Causal Language Modelling

How masked and causal language models learn, which one reads both sides of a word, and which to pick for each job, explained simply for your AI interview.

In short

A masked model hides some words and predicts them from the words on both sides, which suits understanding text. A causal model predicts the next word from the words on its left only, which is how it writes text.

11 min readIntermediateCommon · estimateFacts checked 26 November 2026

Say it out loud

Read it once, then say it without looking. Start with the short one; use the long one when they ask you to go deeper.

A masked model is shown a sentence with some words hidden, and it guesses them from the words on both sides. BERT is the classic example, and it suits reading jobs like sorting claims or finding clauses. A causal model sees only the words to the left and predicts the next word. That is how GPT-style models write. When I pick one, I ask whether the job is to understand text, which means masked, or to write it, which means causal.

What is the difference, in plain words?

A language model learns by guessing words from real text. Masked and causal are two ways to set up that guessing game. The difference is what the model is allowed to look at when it guesses.

Picture a claims adjuster who gets a damaged-claim form with one word blacked out. She reads the lines above and below the gap, then fills it in. A second adjuster reads only the lines above a point and writes what comes next. The first is masked. The second is causal.

In AI, BERT is the classic masked model, introduced in 2018. GPT-style models are causal, and causal language models are frequently used for text generation.

Key words

Token
A small piece of text the model reads, often a word or part of one.
Masked language model
A model that hides some tokens in a text and predicts them from the rest.
Causal language model
A model that predicts the next token from the tokens before it.
Bidirectional
Reads in both directions, so a word sees the words on its left and its right.
Transformer
The neural network design behind most modern language models. It uses attention to weigh each word against the others.

What does each model get to see?

The chart shows what each model sees, and what it must produce, for one short claims note.

What each model sees while it learns

Masked

Claim note, word hidden

“water” is hidden on purpose

Causal

Claim note so far

“Claimant reports water”

Masked model

reads words on both sides

Causal model

reads only the words on its left

Fills the gap

guesses “water” from both sides

Next word

“damage”, then it goes on

  1. 1The masked model gets the note with one word hidden.
  2. 2It reads both sides of the gap and fills it in.
  3. 3The causal model gets only the words written so far.
  4. 4It predicts the next word from its left side alone.
The masked model reads the note with one word hidden and fills the gap from both sides. The causal model reads only the words written so far and predicts the next one.

The sources put the two ways in their own words:

  • “In order to train a deep bidirectional representation, we simply mask some percentage of the input tokens at random, and then predict those masked tokens.”

    BERT paper (Devlin et al., 2018)

  • “We also modify the self-attention sub-layer in the decoder stack to prevent positions from attending to subsequent positions.”

    Transformer paper (Vaswani et al., 2017)

  • “Causal language modeling predicts the next token in a sequence of tokens, and the model can only attend to tokens on the left.”

    Hugging Face docs

How does a masked model learn?

BERT hides a share of the tokens at random, then predicts only the hidden ones. Its experiments hid 15% of the tokens in each sequence. Because the model sees words on both sides of each gap, it learns rich context for every word.

Hiding is what makes the two-sided view safe. The BERT paper warns that bidirectional conditioning would allow each word to indirectly "see itself", and the model could trivially predict the target word.

Take a claims note that says "Claimant reports water damage since Tuesday." Hide the word water. The model reads Claimant reports on the left and damage since Tuesday on the right. Those clues point to water, and the guess is scored against the real word.

How does a causal model learn?

A causal model is trained to predict the next token from the tokens before it. It can only look left. Hugging Face's docs put it plainly: causal modelling predicts the next token, and the model can only attend (pay attention) to tokens on the left.

The Transformer paper handles this with a mask inside the decoder, the part of the model that writes output. Later positions are blocked, so training can't leak the answer.

  1. 1

    Read the text so far

    The model gets the first words of a note, such as the start of a claims note.

  2. 2

    Block everything after the point

    Words to the right of the current position are hidden, so the model can't copy them.

  3. 3

    Predict the next word

    The guess is scored against the real next word, and the model is nudged to do better.

  4. 4

    Repeat for every position

    One sentence gives many practice questions, one for each word.

Here is the same idea for one claims note, in plain Python. It makes one practice question per word, then the masked version with one word hidden.

Python
# Two ways to make practice questions from one claims note. Standard library only.
note = ["Claimant", "reports", "water", "damage", "since", "Tuesday"]

print("Causal: predict the next word from the words on its left")
for i in range(1, len(note)):
    print("  " + " ".join(note[:i]), "->", note[i])

print("Masked: hide one word, predict it from both sides")
hidden = 2  # picked by hand, so every run prints the same thing
masked = ["[MASK]" if i == hidden else w for i, w in enumerate(note)]
print("  " + " ".join(masked), "->", note[hidden])

Output

Causal: predict the next word from the words on its left
  Claimant -> reports
  Claimant reports -> water
  Claimant reports water -> damage
  Claimant reports water damage -> since
  Claimant reports water damage since -> Tuesday
Masked: hide one word, predict it from both sides
  Claimant reports [MASK] damage since Tuesday -> water

Which model fits which job?

The job decides the choice. Masked models suit jobs where the answer depends on the whole text at once, like sorting a claim or finding a clause. Hugging Face calls masked modelling "great for tasks that require a good contextual understanding of an entire sequence." Causal models suit jobs that write new text, one token at a time.

Pick the model by the job

Reading jobs

Sort claims by cause

needs the whole claim at once

Find clauses in contracts

matches on both sides of a term

Writing jobs

Draft a customer reply

writes new words, one by one

Masked model

reads both sides at once

Causal model

reads only the left side

Claim labelled

the right cause, from the whole claim

Reply drafted

a person checks it first

  1. 1The claim text goes to the masked model to be sorted.
  2. 2A contract search goes to the masked model too, to find the clause.
  3. 3A customer reply goes to the causal model, which writes it.
  4. 4The masked model's answer is a label for the claim.
  5. 5The causal model's answer is a draft that a person checks first.
Reading jobs go to the masked model and writing jobs go to the causal model. A person checks each drafted reply before it goes out.

Tip

In an interview, say masked for reading and classifying, and causal for writing and drafting. Then add that you would test the choice on your own data, not trust the model's name.

Large causal models can also read and classify when you prompt them, so treat this split as a starting point and test it on your own data.

How would you choose for a claims team?

Say the team wants two things: sort incoming claims by cause, and draft replies to customers. I would test a masked model on the sorting, since the label depends on the whole claim. I would test a causal model on the drafts, since each reply is written word by word.

Each choice gets its own test set, built from real past claims, and a cost check, because a larger model costs more on every call.

Tip

A masked model fills gaps. It is not built to write a long reply from start to finish, so do not use it for drafting.

What does the interviewer want to hear?

A strong answer covers

  • What each model sees: both sides for masked, the left side only for causal.
  • BERT is masked, and GPT-style models are causal.
  • Masked suits reading jobs. Causal suits writing jobs.
  • Why hiding matters: a model that sees the answer copies it.
  • The trade-off: masked training uses a [MASK] token that fine-tuning text never has.
  • Test each job on your own data, not on the model's name.

Common traps

  • Trap"Masked models can write long replies too."

    BetterThey fill gaps. Writing a reply from start to finish is the causal model's job.

  • Trap"BERT and GPT only differ in size."

    BetterThey differ in what they see during training. Size is a separate choice.

  • Trap"Causal models read the whole text before they answer."

    BetterA causal model reads only the words to the left. That is what lets it write one word at a time.

Can you spot the cheat?

Spot the cheat

A team trains a model to predict each word. Which setup lets the model cheat?

Quick check

A bank's support team wants an assistant that drafts replies to customers about disputed card charges. Which model type fits best?

Can you answer these from memory?

Flash cards · tap a card to flip it

1 / 6

What will they ask next?

  1. Q049Encoder-only vs decoder-only vs encoder-decoder?11 min
  2. Q050What is causal (masked) attention?10 min
  3. Q062How does BERT differ from GPT?11 min
  4. Q065Prefill vs decode phases?10 min
  5. Q068How does the final hidden state become the next token?9 min

Learn it in depth

Last updated on 26 November 2026

Building a search or assistant that has to read text well?

I design and build AI agents and products, including the UI and the system behind them. Book a short call and tell me what you need.