Value Vector
A value vector is the information a transformer actually carries forward after attention decides what to look at. If attention is a librarian: queries state what is needed, keys label each book, and values contain the passages copied into the answer.
How attention uses valuesFor every input position, a transformer creates three learned projections of its representation: a query (Q), a key (K), and a value (V). A query is compared with every allowed key using a dot product. After scaling and a softmax, those comparison scores become attention weights. The output is a weighted sum of value vectors:
Attention(Q, K, V) = softmax(QKᵀ / √dₖ) V
Keys determine where attention goes; values determine what content comes back. A position with a high attention weight contributes much more of its value vector to the output.
Why separate keys and values?Keeping keys and values separate lets the model learn different representations for matching and for communication. A token can expose one set of features to help other tokens find it through its key, while storing different useful features in its value. In multi-head attention, each head has its own value projection, so different heads can collect different kinds of information from the same positions. The heads’ outputs are concatenated and mixed by another learned linear layer.
Training and practical consequencesValue vectors are learned through backpropagation along with the query and key projections. Poor value representations limit the information attention can transmit even when the model attends to the right places. Conversely, good values are wasted when query–key scores route attention incorrectly. In a PyTorch attention module, the value projection is commonly a learned Linear layer producing a tensor shaped like [batch, heads, positions, value_dim]. Attention’s major cost comes from comparing every query with every key; values add the weighted aggregation step. Causal or padding masks change which keys can receive weight, and therefore which value vectors are allowed into each output.
A value vector is the content representation attached to each token in an attention layer. Attention weights, computed from query–key similarity, determine how strongly each value vector contributes to the output; the output is their weighted sum. Values carry the information selected by attention, so their learned projections determine what context a network can retrieve and combine.
Imagine reading a recipe and highlighting the parts that matter for the dish you are making. The highlighted words tell you where to look, but the useful information is the actual ingredient details: “two eggs,” “bake for 20 minutes,” and so on.
In an AI language model, a value vector is like those useful details. When the model decides that one word or phrase is relevant to another, it takes information from that word’s value vector and blends it into its understanding of the current text. This helps it connect “she” with the right person, or use an earlier fact when finishing a sentence.