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 Positional Encoding?
LLMs

What is Positional Encoding?

Updated September 26, 2026 Read 3 min

Positional encoding is the method transformers use to represent the order of tokens in a sequence, because the attention mechanism by itself treats input as an unordered set.

Contents 11
  1. 01Key takeaways
  2. 02Positional encoding explained in simple terms
  3. 03Sinusoidal positional encoding
  4. 04Main approaches
  5. 05A worked example
  6. 06Absolute vs relative position
  7. 07Positional methods and long context
  8. 08Limitations
  9. 09Common Use Cases
  10. 10Frequently Asked Questions
  11. 11Related Terms

Positional encoding is the method transformers use to tell the model where each token sits in a sequence. Self-attention compares tokens with each other but has no built-in sense of order, so without positional information “the dog bit the man” and “the man bit the dog” would look identical. Positional encoding injects order into the model.

Key takeaways

  • Attention is order-blind, so position must be added explicitly.
  • The original transformer used fixed sinusoidal encodings added to token embeddings.
  • Later models used learned absolute positions, then relative positions.
  • Most recent LLMs use rotary positional embedding (RoPE) or similar methods.
  • Positional methods strongly affect how well a model handles long context.

Positional encoding explained in simple terms

Imagine receiving a sentence as a bag of loose word cards. You can see which words are present but not their order. Positional encoding is like stamping a position marker on each card before dropping it in the bag, so the reader can reconstruct the sequence.

Sinusoidal positional encoding

The 2017 transformer paper used fixed sine and cosine waves of different frequencies. Each position gets a unique pattern across the embedding dimensions, added to the token embedding. Because it is a formula rather than learned parameters, it can in principle extend to positions longer than those seen in training, though quality often degrades.

Main approaches

ApproachHow it worksUsed in
Sinusoidal (absolute)Fixed wave patterns added to embeddingsOriginal transformer (2017)
Learned absoluteA trainable vector per positionBERT, GPT-2
RelativeEncodes the distance between tokens in attention scoresTransformer-XL, T5
RoPERotates query and key vectors by an angle based on positionLlama, Qwen, many modern LLMs
ALiBiAdds a distance-based penalty to attention scoresSome long-context models
NoPENo explicit encoding; causal models can infer some orderResearch setting

A worked example

Consider “Ravi paid Meera” and “Meera paid Ravi”. The token embeddings are identical sets. Without position information, attention would compute the same relationships and the model could not tell who paid whom. With positional encoding, the representation of “Ravi” at position 1 differs from “Ravi” at position 3, so the model can learn that the earlier name is the payer.

Absolute vs relative position

Absolute methods say “this is token 7”. Relative methods say “this token is three places before that one”. Relative approaches often generalise better to longer inputs, because language patterns usually depend on distance rather than exact index.

Positional methods and long context

Extending a model beyond its training length is mainly a positional problem. Techniques such as RoPE scaling, including NTK-aware scaling and YaRN, stretch positional patterns so a model trained on shorter sequences can handle longer ones after light fine-tuning. Choice of positional method is one reason models differ in how well they use long context.

Limitations

  • Performance usually degrades beyond the trained length.
  • Learned absolute encodings cannot extend past their table size.
  • Position handling interacts with attention in ways that are hard to predict.
  • Models often use position unevenly, attending more to the start and end of long inputs.

Common Use Cases

01

Language modelling

Give transformers a sense of word order in text.

02

Code models

Track line and token order in source files.

03

Long-context extension

Apply RoPE scaling so models handle longer inputs.

04

Time-series transformers

Encode time steps in forecasting models.

05

Vision transformers

Encode the position of image patches.

06

Speech models

Represent the order of audio frames.

Frequently Asked Questions

A way of representing the order of tokens in a transformer, since attention alone treats input as unordered.

Self-attention compares tokens without any notion of sequence, so word order must be added explicitly.

Absolute marks each token's index; relative encodes the distance between token pairs, which often generalises better.

Most use rotary positional embedding (RoPE) or a related relative method.

Only to a limited extent, and usually with positional scaling techniques plus some fine-tuning.

Related Terms

  • RoPE
  • Self-Attention
  • Transformer
  • Context Window
  • Embedding
  • Attention Mechanism

Related AI Terms

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 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 Self-Attention?Self-attention is a mechanism where each position in a sequence attends to every other position in the same…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. 02Positional encoding explained in simple terms
  3. 03Sinusoidal positional encoding
  4. 04Main approaches
  5. 05A worked example
  6. 06Absolute vs relative position
  7. 07Positional methods and long context
  8. 08Limitations
  9. 09Common Use Cases
  10. 10Frequently Asked Questions
  11. 11Related Terms

AI Topic

  • LLMs

Related Terms

  • What is Multi-Head Attention?
  • What is Prefix Tuning?
  • What is an Attention Mechanism?
  • What is Self-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}