liveBook · Manning

Linear layer

As explained in Grokking AI Algorithms, Second Edition

A linear layer is a neural-network layer that computes an affine or linear transformation of its input using learned weights and usually a bias.

A linear layer transforms an input vector by multiplying it with learned weights and usually adding a bias. The weights reshape information; the bias shifts each output up or down, giving the network more flexibility. section 11.25

In a Transformer feed-forward block, a projection layer expands or transforms normalized token representations so later operations can learn richer features. Because these operations are linear, a nonlinear activation such as ReLU is applied afterward. section 11.25

From a token vector to a prediction

A final linear layer, called the language model head, multiplies the last Transformer output by a weight matrix whose second dimension equals the vocabulary size. Its outputs are logits—raw, unnormalized scores for possible next tokens. Softmax converts those scores into probabilities; choosing the largest score gives a predicted token. section 11.29

Table 11.27 Random weights for the project up layer

0.1

-0.2

0.3

0.4

-0.5

0.6

0.7

-0.8

0.9

0.8

-0.7

0.6

0.5

-0.4

0.3

0.2

-0.3

0.2

0.1

-0.9

0.8

0.7

-0.6

0.5

0.5

-0.6

0.7

0.8

-0.9

0.1

0.2

-0.3

Inspect the sample weights used to illustrate how a project-up transformation combines input values into output dimensions. section 11.25

How Grokking AI Algorithms, Second Edition covers it

How deep it goes
Traces matrix multiplication, bias addition, ReLU, logits, softmax, and argmax, but avoids deeper parameter-learning internals.
Examples
Uses NumPy projection code, sample weight tables, token vectors, a logit calculation, and vocabulary probability tables.
What it assumes
Assumes familiarity with vectors and matrices while explaining weights, bias, logits, and softmax through concrete calculations.
What you can do after
Build a simple NumPy projection and interpret its logits as scores for selecting a next token.
How it connects
Connects projection layers with learned weights, bias, ReLU, Transformer blocks, logits, softmax, vocabulary, and token prediction.

Also explained in

Compare how 13 books explain linear layer →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Grokking AI Algorithms, Second Edition. The section links point to the parts of the book it draws on.