# Key Matrix

- **Canonical URL:** https://getaimath.com/dictionary/key-matrix/
- **Topics:** [Transformer Architecture](https://getaimath.com/dictionary/category/transformer-architecture/)
- **Last updated:** 2026-11-25

## What is Key Matrix?

**In one sentence:** The key matrix is a grid of learned weights that turns each word's numbers into its key.

Just like the query matrix, it is multiplied with each token's embedding, but it produces the "name tag" that others search. Training shapes it so related words produce keys that match each other's queries.

![Transformers & Attention: The Smart Highlighter — Simple cartoon diagram showing how a Transformer reads a whole sentence at once and shines a bright highlighter beam from the word "IT" back to "trophy" so it knows what "IT" means.](https://getaimath.com/diagrams/transformer-architecture.png)
*Napkin Diagram (Transformer Architecture): Older AI read word-by-word and often lost track of earlier words; a Transformer highlights which words connect to which.*

## What is an example of Key Matrix?

The key matrix learns to give words like "she" and "Sara" keys that match well when they refer to the same person.

## Why does Key Matrix matter?

Together with the query matrix, it decides where attention goes.

## Related Concepts

- [Query Matrix](https://getaimath.com/dictionary/query-matrix/): The query matrix is a grid of learned weights that turns each word's numbers into its query.
- [Value Matrix](https://getaimath.com/dictionary/value-matrix/): The value matrix is a grid of learned weights that turns each word's numbers into the value it shares.
- [Value (V)](https://getaimath.com/dictionary/value-v/): In attention, a value is the actual information a word passes along when another word pays attention to it.
- [Attention Scores](https://getaimath.com/dictionary/attention-scores/): Attention scores are numbers that show how much each word should focus on every other word.
- [Key (K)](https://getaimath.com/dictionary/key-k/): In attention, a key is a list of numbers that describes what a word offers, so queries can find it.
- [Scaled Dot-Product Attention](https://getaimath.com/dictionary/scaled-dot-product-attention/): Scaled dot-product attention is the standard math recipe for attention: compare queries and keys, scale the results, softmax them, and mix the values.

---
Source: The AI Math Dictionary (https://getaimath.com/dictionary/key-matrix/)
