liveBook · Manning

Query

An attention query is a vector representation of the information sought by an input position, compared with key representations to determine which information to attend to.

How 7 Manning books explain it

Transformers in Action

In attention, a query is a vector representation that specifies the information for which relevance is being evaluated.

How it is used
Uses queries to determine which sequence positions matter when forming each self-attention output.
How deep it goes
Explains the query’s role and implements its projection and scaled dot-product scoring in simplified attention examples.
Examples
Uses a “not bad” sentence, a NumPy attention calculation, and a PyTorch multihead attention implementation.
What you can do after
Build it from scratch with projected queries, scaled query–key scores, softmax weights, and weighted values.

Read how Transformers in Action explains query →

Build a Text-to-Image Generator (from Scratch)

A query is an attention vector representing the information whose relevance to sequence elements is being evaluated.

How it is used
Uses queries to evaluate relationships among sequence elements in translation, vision transformers, and diffusion-model attention.
How deep it goes
Explains projections, scaled dot products, softmax, heads, and value aggregation, then stops short of training details.
Examples
Uses German-to-English translation, vision features such as texture and edges, and attention inside a denoising U-Net.
What you can do after
Build it from scratch in PyTorch by projecting inputs into queries, computing attention scores, and aggregating values.

Read how Build a Text-to-Image Generator (from Scratch) explains query →

Sutskever's List

An attention projection representing the information a sequence position seeks from other positions.

How it is used
Guides cross-attention by selecting which encoded input representations should influence each decoding step.
How deep it goes
Explains the query’s functional role in scoring relevance, without deriving its numerical construction.
Examples
Uses decoder cross-attention, encoded input representations, relevance scores, and context-guided token generation.
What you can do after
Evaluate how decoder positions select relevant encoded information during Transformer cross-attention.

Read how Sutskever's List explains query →

Learn Generative AI with PyTorch

How it is used
Uses queries to score relationships between sequence positions and determine how attention combines their value representations.
How deep it goes
Traces the query from an input-embedding projection through query-key scoring, softmax weights, and value combination.
Examples
Uses a library search for “machine learning in finance” to illustrate queries, keys, and values.
What you can do after
Understand how a query helps determine attention weights over values in a sequence.

Read how Learn Generative AI with PyTorch explains query →

Deep Learning with PyTorch, Second Edition

A learned projection of an input position used to score how relevant other positions are in attention.

How it is used
Uses queries to identify which sequence positions deserve focus during self-attention and contextual text generation.
How deep it goes
Explains query projections, query-key dot products, softmax weighting, and value aggregation, without detailing training or parameter learning.
Examples
Demonstrates query projections and attention scoring with a two-position, three-dimensional PyTorch tensor.
What you can do after
Build it from scratch by projecting inputs into queries and using them to compute normalized attention-weighted outputs.

Read how Deep Learning with PyTorch, Second Edition explains query →

Deep Learning with Python, Third Edition

How it is used
Uses queries to retrieve relevant information from source representations in attention.
How deep it goes
Defines queries through the search analogy and explains their role in parameterized dot-product attention.
Examples
Uses photo search and target-to-source sequence attention as examples.
What you can do after
Build attention from scratch by scoring queries against keys and using the scores to combine values.

Read how Deep Learning with Python, Third Edition explains query →

How Large Language Models Work

An attention query is a vector representing the information sought when an attention operation compares sequence elements.

How it is used
Uses a query to identify relevant information during attention in transformer layers.
How deep it goes
Defines query vectors and traces fuzzy matching, but stops short of deriving the attention equation.
Examples
Uses a Python dictionary analogy and next-token prediction with the current token as the query.
What you can do after
Evaluate how attention selects relevant preceding information using approximate query-key matches.

Read how How Large Language Models Work explains query →

Related concepts

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.