liveBook · Manning

Value

As explained in Build a Large Language Model (From Scratch)

The attention content vector combined according to attention weights to form the context output.

A value vector carries transformed input content into self-attention. Multiplying each input vector by W_value produces values, which attention weights combine into a context vector. section 3.4.1

Follow the value-vector flow:

  • Project every input with W_value; for six inputs and d_out = 2, values has shape [6, 2]. section 3.4.1
  • Compute attention weights from query–key scores, then multiply those weights by values to form the context vector. section 3.4.1

Single-query computation

For the second input, compute value_2 = x_2 @ W_value. After obtaining all values and the attention weights for x_2, calculate context_vec_2 = attn_weights_2 @ values, producing a two-dimensional context vector. section 3.4.1

Figure 3.14 In the first step of the self-attention mechanism with trainable weight matrices, we compute query (q), key (k), and value (v) vectors for input elements x. Similar to previous sections, we designate the second input, x(2), as the query input. The query vector q(2) is obtained via matrix multiplication between the input x(2) and the weight matrix Wq. Similarly, we obtain the key and value vectors via matrix multiplication involving the weight matrices Wk and Wv.
figure

Trace how W_value transforms input elements into value vectors alongside the corresponding query and key projections. section 3.4.1

How Build a Large Language Model (From Scratch) covers it

How deep it goes
Explains W_value projection, tensor shapes, and weighted combination, stopping at a single-query example rather than multi-head construction.
Examples
Uses the six-word sentence “Your journey starts with one step,” second-input query x_2, and PyTorch tensors shaped [6, 2].
What it assumes
Assumes embedded input vectors and matrix multiplication while introducing the value projection through concrete tensor operations.
What you can do after
Build it from scratch in PyTorch by projecting inputs with W_value and combining values with attention weights.
How it connects
Connects value vectors to query, key, attention weights, context vectors, causal attention, and multi-head attention.

Also explained in

Compare how 8 books explain value →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Build a Large Language Model (From Scratch). The section links point to the parts of the book it draws on.