Attention: Learning the Similarity
Part III’s decoder received source information through the encoder’s final state. We now retain the states at every source position and form a separate weighted summary for each output. Choosing which stored states to use for an output is a search over those states. Weighting every stored state by its similarity to a query replaces the discrete choice and makes the search differentiable. The parameters of the comparison can then be learned by gradient descent. The weighted search is a classical statistical method, kernel regression: compare a query with stored keys, normalize the similarities, and combine the associated values. We then learn the representations used for comparison and the content being combined.
In self-attention, every position supplies a query, a key, and a value, so each output is a weighted summary of the positions it may draw on. The comparison depends on the contents of the positions, not on where they occur. Without further information, permuting the inputs only permutes the outputs, and order is lost. Positional representations supply information about order, while masks specify which positions may contribute to each output. Together with residual connections, normalization, and position-wise networks, these operations form the Transformer. The test-time-regression interlude examines the memory computation from another angle: how do the choices of regression model, kernel, and update rule determine what must be retained and what can be reconstructed?
We then turn from the operator to its training. Self-supervised pretraining produces representations that can be adapted to new tasks, and patch embeddings allow the same encoder structure to process images. The comparisons lead to scaling: how should model size, data, and training compute grow together? Empirical scaling laws guide that allocation within their measured regimes. They do not determine how cheaply the resulting model can be deployed or adapted, which becomes the next part’s question.