Repository navigation
Transformer Concepts Positional Encoding
Because transformers process all tokens simultaneously (in parallel), they inherently have no concept of word order. "The cat chased the dog" and "The dog chased the cat" look identical to the Attention mechanism. Positional Encoding solves this by injecting spatial information into the embeddings.
Without positional encoding, language models would be bags-of-words classifiers. They wouldn't understand syntax, grammar, or causality.
There are two main types of positional encoding:
- Absolute (Learned/Sinusoidal): Found in GPT-2. A separate embedding vector is looked up based purely on the token's index (0, 1, 2) and added to the word embedding.
- Relative (RoPE): Found in modern models (Llama, Qwen). Applied during attention rather than at the embedding layer.
When TokenPrint detects an older model like gpt2, the HUD displays the formula for Absolute Positional Embeddings:
For modern models, TokenPrint ignores absolute embeddings and instead highlights RoPE during the Attention phase.
flowchart LR
Token[Word Embedding] --> Add[+]
Pos[Positional Embedding] --> Add
Add --> Output[Contextualized Vector]
subgraph "GPT-2 Style (Absolute)"
Token
Pos
end
| Previous | Home | Next |
|---|---|---|
| Embeddings | Home | RoPE |
TokenPrint Wiki | Home | Getting Started | User Guide | Concepts | Architecture | API | GitHub
TokenPrint is an interactive 3D visualization platform for exploring transformer architectures, tensors, and real-time LLM inference.
- User Guide
- Architecture Explorer
- Live Inference
- Tensor Inspector
- Camera Controls
- HUD
- Timeline
- Scene Navigation
- Transformer Concepts
- Tokenization
- Embeddings
- Positional Encoding
- RoPE
- Multi-Head Attention
- KV Cache
- LayerNorm
- Feed Forward Network
- Residual Connections
- Logits
- Softmax
- Sampling
- Autoregressive Generation
- Visualization System
- Scene Graph
- Geometry
- Materials
- Animation System
- Color Mapping
- Camera System
- Interaction Model
- Architecture
- Overall Architecture
- Frontend
- Backend
- WebSocket Protocol
- Data Pipeline
- Renderer
- Event System