NEW
Also known as: Absolute Positional Encoding
Deterministic sine and cosine functions encode absolute positions for transformer inputs without learned parameters.
DESCRIPTION
Sinusoidal positional encoding injects order information into transformer models via fixed sine–cosine functions across dimensions. It enables the model to discern relative and absolute positions without learning position parameters. The design supports extrapolation to longer sequences due to periodic structures. Alternatives include learned, relative, and rotary positional schemes with different trade-offs. Sinusoidal encoding remains a baseline choice for many transformer implementations.
ALTERNATIVE DEFINITIONS
Vaswani et al.
We add positional encodings to the input embeddings at the bottoms of the encoder and decoder stacks. We use sine and cosine functions of different frequencies.
Original description combining embeddings with sinusoidal functions for position.
Harvard NLP
To make use of sequence order, we add positional encodings to the input embeddings; here we use a sinusoidal function.
Educational overview emphasizing sinusoidal as a simple, effective choice.
Hugging Face
Positional encodings provide information about the position of tokens in sequences; sinusoidal encodings use fixed sine and cosine functions.
Clarifies positional role and fixed functions in implementations.
RELATED TERMS
Transformer Model Attention Mechanism Positional Encoding Relative Positional Encoding Sequence Modeling Token Embedding BERT Vision Transformer Natural Language Processing
COMPETING TERMS
Learned Positional Embeddings Rotary Positional Embeddings
RELATIONS
- Broader: Positional Encoding
KNOWLEDGE AREAS
TARGET AUDIENCE
AI Engineer Data Scientist MLOps Engineer Software Developer
EXTERNAL SOURCES
- Wikipedia - Transformer (machine learning model)
- arXiv - Original Transformer paper
- Harvard NLP - Annotated Transformer tutorial
- Hugging Face - Transformer library documentation
TOP QUESTIONS
Why use Sinusoidal Positional Encoding instead of learned positions?
It has no parameters, supports extrapolation, and is simple. Learned positions may fit training lengths better but can struggle with unseen lengths.
Category: Opinion
How does Sinusoidal Positional Encoding work?
Each embedding dimension encodes position using sine or cosine at different frequencies, added to token embeddings before attention.
Category: Concept
What are alternatives to Sinusoidal Positional Encoding?
Learned, relative, and rotary positional encodings (RoPE) are common. They offer different generalization and inductive bias properties.
Category: Alternatives
Does Sinusoidal Positional Encoding help long-sequence modeling?
Its periodic structure aids extrapolation, but attention memory and scaling dominate limitations. Long-context architectures and RoPE may help more.
Category: Opinion
What is a common mistake with positional encodings?
Forgetting to align embedding dimensions or scaling factors, causing mismatch or degraded training stability.
Category: Mistakes
How is it implemented in practice?
Precompute the positional matrix and add to embeddings, or compute on-the-fly based on sequence length and model dimension.
Category: HowTo
Is Sinusoidal Positional Encoding still relevant?
Yes, it remains a strong baseline in many transformer implementations and educational materials.
Category: Relevancy
How does it interact with attention?
By embedding positions, attention can distinguish token order when computing relevance across the sequence.
Category: Concept
Can positional encoding be normalized?
Some models scale or layer-norm after adding positions to stabilize training, depending on architecture.
Category: Technique