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 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
A left-to-right decoder-only layer uses
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 causal matrix, then cross-attention can use a
matrix:
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 above, how many source positions can query row 2 read?
Compute it first, then check your number.
Hint
Solution
Reference
- Ashish Vaswani et al., Attention Is All You Need, 2017.