liveBook · Manning

Query

Also called Q

In an attention mechanism, a query is a vector representation of a sequence position that is compared with keys to determine relevance and weight associated values.

How 14 Manning books explain it

Build a DeepSeek Model (From Scratch)

A query vector is an attention representation that specifies what information a token seeks from other tokens.

How it is used
Uses queries to select token information for context vectors and motivate efficient autoregressive inference.
How deep it goes
Works through projection shapes, attention scores, causal weights, and new-token computation, including a compressed key-value variant.
Examples
Traces “The next day is” through a four-token projection and computes attention for the newly appended token “bright.”
What you can do after
Understand how to trace a query from an embedding projection through attention scores to a context vector.

Read how Build a DeepSeek Model (From Scratch) explains query →

Timeless Algorithms, The Foundational Ideas

In an attention mechanism, a projected representation of an element that is compared with keys to determine which information to attend to.

How it is used
Uses queries to construct context through weighted relationships between tokens.
How deep it goes
Works through projections, dot products, scaling, softmax, and weighted values, while simplifying the behavior of a complete transformer.
Examples
Illustrates queries with pronoun resolution, semantic association, factual recall, and autoregressive generation.
What you can do after
Evaluate how a query affects attention weights and the resulting contextual representation in a simplified example.

Read how Timeless Algorithms, The Foundational Ideas explains query →

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 input positions contribute to each attention output.
How deep it goes
Explains query roles and scaled dot-product computation, with simplified single-head and multihead implementations.
Examples
Illustrates a query with “The movie was not bad” and computes attention over four toy embeddings.
What you can do after
Understand how query–key comparisons determine the weights used to combine 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 →

Rearchitecting LLMs

A query vector is an attention representation used to determine how strongly a position should attend to available keys.

How it is used
Uses a token’s query to determine how strongly it attends to information represented by other tokens’ keys and values.
How deep it goes
Works through query-key dot products and softmax-weighted values without detailing the query projection’s implementation.
Examples
Uses the query for “spring” searching for contextual clues, including alignment with the key for “mountain.”
What you can do after
Understand how query-key scores determine the contributions of values to a token’s enriched embedding.

Read how Rearchitecting LLMs explains query →

Learn Generative AI with PyTorch

How it is used
Uses a position’s query to score its relevance to sequence elements and weight their values in self-attention.
How deep it goes
Works through query-key scoring, scaling, softmax, and value weighting, then situates the vectors in multihead attention.
Examples
Uses a library search query and English-to-French Transformer translation to illustrate retrieval and sequence attention.
What you can do after
Build self-attention by projecting input embeddings into query, key, and value vectors and calculating their weighted output.

Read how Learn Generative AI with PyTorch explains query →

CUDA for LLMs

A query is an attention representation compared with keys to determine attention scores.

How it is used
Determines how strongly each token position attends to others by scoring its query against keys.
How deep it goes
Traces query projection through scaled dot-product attention and the resulting value-weighted output.
Examples
Uses a PyTorch attention head with query and key projections, causal masking, and a 16 × 64 × 128 model configuration.
What you can do after
Apply it via PyTorch to compute query-key attention scores and produce value-weighted outputs.

Read how CUDA for LLMs explains query →

Build AI Drug Discovery Pipelines

A query vector is an attention representation that specifies the information sought from a set of keys and values.

How it is used
Guides a decoder toward encoder information relevant to its current prediction step.
How deep it goes
Explains query-key scoring, softmax weighting, and value aggregation, without detailing a specific scoring formula.
Examples
Uses decoder steps and a cross-attention diagram for protein-sequence information retrieval.
What you can do after
Understand how a decoder selects targeted encoder information through query-key comparisons and weighted value aggregation.

Read how Build AI Drug Discovery Pipelines explains query →

Applied Reinforcement Learning

A query is an attention vector representing the information an input element seeks from other elements.

How it is used
Represents the information a zone seeks from other zones when coordinating policy decisions.
How deep it goes
Defines queries as transformed zone representations and explains their dot-product comparison with keys, without detailing vector construction.
Examples
Uses zones seeking relevant information from other zones to illustrate query-key comparisons.
What you can do after
Understand how query-key similarity determines which zones contribute information to a zone’s output.

Read how Applied Reinforcement Learning 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 →

Machines that Think

A query is an attention vector representing the relationship sought by a sequence element when retrieving information from other elements.

How it is used
Represents what a token seeks from its sequence context when attention retrieves relevant information.
How deep it goes
Traces learned projections and query-key dot-product comparisons, without detailing numerical calculations or projection training.
Examples
Uses “rises” seeking useful context from “sun” and a decoder seeking “east” from the input representations.
What you can do after
Understand how queries match keys to identify relevant information in self-attention and cross-attention.

Read how Machines that Think explains query →

Deep Learning with Python, Third Edition

How it is used
Uses a target-position representation to score source keys and select information from associated values during decoding.
How deep it goes
Explains query-key scoring, value aggregation, learned projections, and a photo-search analogy, with code for parameterized attention.
Examples
Uses photo search to illustrate queries, keys, and values, and relates queries to target words during decoding.
What you can do after
Build it from scratch using Dense projections, dot-product scores, softmax weighting, and value aggregation.

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 →

Also covered in

What to know first

Related concepts

Questions about query

What is query?

In an attention mechanism, a query is a vector representation of a sequence position that is compared with keys to determine relevance and weight associated values.

Which Manning books explain query?

Build a DeepSeek Model (From Scratch), Timeless Algorithms, The Foundational Ideas, Transformers in Action, Build a Text-to-Image Generator (from Scratch), Sutskever's List, Rearchitecting LLMs, Learn Generative AI with PyTorch, CUDA for LLMs and 6 more.

What should I know before learning query?

Manning books that teach query usually introduce transformer architecture, embedding, softmax and linear layer first.

What is query also called?

Query is also called Q.

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.