Skip to content
Query Feedz
  • News
  • Business
    • Digital Marketing
      • Marketing & Sales
      • SEO
      • Content Marketing
      • AEO and GEO
    • Startups
      • Founder Stories
      • Funding & VC
      • Product & Growth
    • Money
      • Investing
      • Markets & Economy
      • Saving & Budgeting
  • AI & Technology
    • Technology
      • Consumer Tech
      • CRM
      • Cyber Security
      • Software Engineering
      • WordPress
      • Hardware
    • Artificial IntelligenceAI Glossary
      • LLMs
      • Machine Learning
      • AI Fundamentals
      • Generative AI
      • Deep Learning
    • AI Use Cases
      • Automation
      • Content
      • Customer Support
      • Finance
      • Marketing
      • View All
  • Tools & Software
  • Account
    • Submit Guest Post
    • Submit a tool
    • My listing
  • Contact
QueryFeedz
  • News
  • Business
    • Digital Marketing
      • Marketing & Sales
      • SEO
      • Content Marketing
      • AEO and GEO
    • Startups
      • Founder Stories
      • Funding & VC
      • Product & Growth
    • Money
      • Investing
      • Markets & Economy
      • Saving & Budgeting
  • AI & Technology
    • Technology
      • Consumer Tech
      • CRM
      • Cyber Security
      • Software Engineering
      • WordPress
      • Hardware
    • Artificial IntelligenceAI Glossary
      • LLMs
      • Machine Learning
      • AI Fundamentals
      • Generative AI
      • Deep Learning
    • AI Use Cases
      • Automation
      • Content
      • Customer Support
      • Finance
      • Marketing
      • View All
  • Tools & Software
  • Account
    • Submit Guest Post
    • Submit a tool
    • My listing
  • Contact
QueryFeedz
  1. Home /
  2. AI Glossaries /
  3. LLMs /
  4. What is Self-Attention?
LLMs

What is Self-Attention?

Updated September 26, 2026 Read 3 min

Self-attention is a mechanism where each position in a sequence attends to every other position in the same sequence, using queries, keys and values to decide how much information to take from each.

Contents 11
  1. 01Key takeaways
  2. 02Self-attention explained in simple terms
  3. 03Queries, keys and values
  4. 04How self-attention is computed
  5. 05A worked example
  6. 06Why scale by √dₖ?
  7. 07Self-attention vs recurrence
  8. 08Limitations
  9. 09Common Use Cases
  10. 10Frequently Asked Questions
  11. 11Related Terms

Self-attention is a mechanism in which every position in a sequence attends to every other position in the same sequence. Each token produces a query, a key and a value. Queries are matched against keys to produce relevance scores, and the scores are used to take a weighted mix of values. Self-attention is the core operation inside every transformer layer.

Key takeaways

  • “Self” means the sequence attends to itself, rather than to a separate input.
  • The formula is: softmax(QKᵀ ÷ √dₖ) × V.
  • Dividing by the square root of the key dimension keeps scores in a stable range.
  • Every position is computed in parallel, which makes training fast on GPUs.
  • Causal self-attention masks future positions so generation stays left to right.

Self-attention explained in simple terms

Imagine everyone in a meeting writing a short note saying what they need (the query) and what they can offer (the key), plus the actual information they hold (the value). Each person reads all the offers, decides who is most relevant to their need, and combines those people’s information. Do this for everyone at once, and every participant ends up better informed about the whole discussion. That is one self-attention layer.

Queries, keys and values

ElementMeaningHow it is made
Query (Q)What this token is looking forToken vector × learned matrix W_Q
Key (K)What this token offersToken vector × learned matrix W_K
Value (V)The information passed onToken vector × learned matrix W_V

How self-attention is computed

  1. Turn each token’s embedding into Q, K and V vectors.
  2. Compute scores: the dot product of each query with every key.
  3. Scale: divide the scores by √dₖ, where dₖ is the key dimension.
  4. Mask (if causal): set scores for future positions to negative infinity.
  5. Softmax: convert scores into weights that sum to 1.
  6. Output: multiply weights by values and sum.

A worked example

Sentence: “The bank raised rates.” When processing “bank”, its query is compared with all keys. Suppose scaled scores are: The 0.2, bank 1.5, raised 2.1, rates 1.8. Softmax turns these into weights of roughly 0.07, 0.25, 0.37 and 0.31. The output for “bank” is dominated by “raised” and “rates”, so the model’s representation of “bank” leans towards the financial meaning rather than a riverbank. The next layer builds on that.

Why scale by √dₖ?

With large dimensions, dot products can become very large, pushing softmax into a region where one weight is near 1 and gradients almost vanish. Dividing by √dₖ keeps the scores in a moderate range so training stays stable.

Self-attention vs recurrence

AspectSelf-attentionRNN
Path between distant tokensOne stepMany steps
Parallel trainingYesNo
Cost per layerGrows with the square of lengthGrows linearly
Memory during generationGrows with context (KV cache)Constant

Limitations

  • Quadratic compute and memory in sequence length.
  • Needs positional encoding, since attention alone ignores order.
  • A single attention operation captures one pattern, which is why multi-head attention is used.

Common Use Cases

01

Language modelling

Build context-aware token representations inside LLMs.

02

Pronoun resolution

Link words like "it" and "they" to the right nouns.

03

Code understanding

Relate variables and functions across a file.

04

Vision transformers

Let image patches attend to other patches.

05

Audio models

Relate frames across a speech sequence.

06

Long document analysis

Connect claims and evidence across paragraphs.

Frequently Asked Questions

A mechanism where each word in a sentence looks at all the other words and takes information from the most relevant ones.

Three vectors made from each token: queries express what a token needs, keys what it offers, and values the information it shares.

To keep dot-product scores in a stable range so softmax gradients do not vanish.

Self-attention with future positions masked, so each token only attends to earlier tokens, as needed for text generation.

Self-attention is one type of attention, where a sequence attends to itself rather than to another sequence.

Related Terms

  • Attention Mechanism
  • Multi-Head Attention
  • Transformer
  • Attention Head
  • Positional Encoding
  • Causal Language Model

Related AI Terms

What is an Attention Head?An attention head is a single attention unit inside a transformer layer, with its own query, key and…What is Prefix Tuning?Prefix tuning is a parameter-efficient fine-tuning method that learns trainable vectors inserted into the attention keys and values…What is an Attention Mechanism?An attention mechanism is a technique that lets a neural network focus on the most relevant parts of…What is Multi-Head Attention?Multi-head attention runs several attention operations in parallel, each with its own learned projections, so a model can…What is RoPE (Rotary Positional Embedding)?RoPE (rotary positional embedding) encodes a token's position by rotating its query and key vectors by an angle…What is an Encoder-Decoder Model?An encoder-decoder model, also called a sequence-to-sequence model, uses one component to read and understand the input and…

Contents

  1. 01Key takeaways
  2. 02Self-attention explained in simple terms
  3. 03Queries, keys and values
  4. 04How self-attention is computed
  5. 05A worked example
  6. 06Why scale by √dₖ?
  7. 07Self-attention vs recurrence
  8. 08Limitations
  9. 09Common Use Cases
  10. 10Frequently Asked Questions
  11. 11Related Terms

AI Topic

  • LLMs

Related Terms

  • What is an Attention Head?
  • What is Prefix Tuning?
  • What is an Attention Mechanism?
  • What is Multi-Head Attention?
  • What is RoPE (Rotary Positional Embedding)?
  • What is an Encoder-Decoder Model?

Quick Navigation

  • Common Use Cases
  • Frequently Asked Questions
  • Related Terms
  • Back to top

Details

Updated
September 26, 2026
Read
3 min
  • Forum
  • Submit a tool
  • Submit Guest Post
  • List Your Startup
  • Privacy Policy
  • Editorial Policy
  • Account
  • Contact
  • AI Productivity
  • AI Video
  • AI Coding
  • AI Chatbots
  • Sales
  • AI Business
  • View All Tools

Subscribe our Newsletter

Get weekly exclusive content - No spam.

Copyright © 2026 -  Query Feedz

Manage Consent
To provide the best experiences, we use technologies like cookies to store and/or access device information. Consenting to these technologies will allow us to process data such as browsing behavior or unique IDs on this site. Not consenting or withdrawing consent, may adversely affect certain features and functions.
Functional Always active
The technical storage or access is strictly necessary for the legitimate purpose of enabling the use of a specific service explicitly requested by the subscriber or user, or for the sole purpose of carrying out the transmission of a communication over an electronic communications network.
Preferences
The technical storage or access is necessary for the legitimate purpose of storing preferences that are not requested by the subscriber or user.
Statistics
The technical storage or access that is used exclusively for statistical purposes. The technical storage or access that is used exclusively for anonymous statistical purposes. Without a subpoena, voluntary compliance on the part of your Internet Service Provider, or additional records from a third party, information stored or retrieved for this purpose alone cannot usually be used to identify you.
Marketing
The technical storage or access is required to create user profiles to send advertising, or to track the user on a website or across several websites for similar marketing purposes.
  • Manage options
  • Manage services
  • Manage {vendor_count} vendors
  • Read more about these purposes
View preferences
  • {title}
  • {title}
  • {title}