liveBook · Manning

Key

As explained in Deep Learning with R, Third Edition

A key vector is an attention representation used to compute compatibility with a query.

A key vector is an attention representation compared with a query to measure compatibility. Attention uses those scores to select and combine corresponding value vectors. section 15.3.1

A database lookup analogy

Imagine searching a photo database: the query is the search term, keys are photo tags matched against it, and values are the retrieved photos. Attention performs a comparable lookup over source vectors. section 15.3.1

In parameterized attention, learned Dense layers project query, key, and value inputs into useful spaces. Dot products between each query and the keys produce scores; softmax turns them into weights for combining values. With causal attention, a position compares its query with previous key vectors while a causal mask blocks future positions. section 15.3.1 section 16.2.3

Key vectors also support efficient Transformer generation:

  • Past key vectors remain unchanged because past input is fixed and causal attention prevents looking ahead. section 16.2.3
  • Caching key and value vectors at every Transformer layer lets generation process one new position at a time, potentially producing a thousandfold speedup for long sequences. section 16.2.3

How Deep Learning with R, Third Edition covers it

How deep it goes
Explains key vectors through lookup, projection, dot-product scoring, causal masking, and caching, without deriving attention mathematically.
Examples
Illustrates key vectors through photo-tag retrieval, parameterized attention code, and cached key-value vectors in mini-GPT generation.
What it assumes
Assumes attention terminology and vector operations while establishing query, key, and value roles through a search analogy.
What you can do after
Apply key vectors via dot-product attention and implement key-value caching for efficient causal generation.
How it connects
Connects key vectors to queries, values, attention, softmax, causal masks, Transformers, and recurrent neural network state.

Also explained in

Compare how 8 books explain key →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Deep Learning with R, Third Edition. The section links point to the parts of the book it draws on.