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.
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.
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.
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.
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.
Related concepts
- attentionused by · Attention is a neural-network mechanism that computes input-dependent weights to combine information according to its relevance to a computation.
- inner productuses · An inner product is a scalar-valued operation on two vectors that combines their corresponding components, summing their products and, for complex vectors, using conjugation.
- scaled-dot product attentionused by · Scaled dot-product attention computes query-key dot products, divides them by the square root of the key dimension, applies softmax, and uses the resulting weights to combine value vectors.
- Rotary Position Embeddingused by · Rotary Position Embedding is a positional encoding method that represents token positions by applying position-dependent rotations to components of attention query and key vectors.
- keyuses · In attention, a key is a vector representation of an input element that is compared with a query to determine relevance and attention weights for its associated value.
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.






