One Block, Three Information-Flow Families

Hold the tokens and block vocabulary fixed while encoder-only, decoder-only, and encoder-decoder masks permit different routes. Construct exact visibility matrices and separate causal, padding, and source-availability masks.

An attention block does not decide by itself whether a model is an encoder or a decoder. The source of queries, keys, and values—and the visibility mask—set the information-flow contract.

Hold the Tokens Fixed

For A B C, write a visibility matrix VV whose row is the reading query and whose column is a possible source. A 1 means the route is allowed; it does not mean the model will assign that route a large attention weight.

An encoder-only self-attention layer can use

Vencoder=[111111111].V_{encoder}= \begin{bmatrix} 1&1&1\\ 1&1&1\\ 1&1&1 \end{bmatrix}.

A left-to-right decoder-only layer uses

Vdecoder=[100110111].V_{decoder}= \begin{bmatrix} 1&0&0\\ 1&1&0\\ 1&1&1 \end{bmatrix}.

Both layers may use the same self-attention equations and outer tensor shape. Their permitted computations differ.

For an encoder-decoder model, source A B C first uses encoder visibility. Target X Y uses a 2×22\times2 causal matrix, then cross-attention can use a 2×32\times3 matrix:

Vcross=[111111].V_{cross}= \begin{bmatrix} 1&1&1\\ 1&1&1 \end{bmatrix}.

Here the rows are target queries and the columns are encoded source positions.

Masks Have Separate Purposes

  • A causal mask blocks information from later target positions.
  • A padding mask blocks placeholder positions that are not content.
  • A source-availability mask may block source records that are absent or invalid for a particular example.

Combining masks by name alone is unsafe. Define their axes and boolean meaning, then combine them before softmax under one stated convention.

Family Names Do Not Fix Every Detail

“Encoder-only” does not determine the readout or training objective. “Decoder-only” does not determine the position method, normalization, or post-training. “Encoder-decoder” does not determine how input and output text are formatted. The family describes a major information-flow pattern, not the complete system.

Q1. Read a visibility matrix

In VdecoderV_{decoder} above, how many source positions can query row 2 read?

Compute it first, then check your number.

Hint
Count the 1s in the second row.
Solution
The row [1,1,0][1,1,0] permits two source positions.
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 PrimerOne Block, Three Information-Flow Familieshttps://llmprimer.com/transformers/transformer-architecture-families/one-block-three-information-flow-families© 2026 LLM Primer