You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- **Contextual Awareness:** The model can differentiate between tokens based on their positions.
174
174
- **Sequence Understanding:** Enables the model to understand grammar, syntax, and context-dependent meanings.
175
175
176
+
## **Positional Embeddings in Modern LLMs**
177
+
178
+
### **Rotary Positional Embeddings (RoPE)**
179
+
180
+
RoPE encodes position by applying aposition-dependent rotation to pairs of dimensions in the query/key vectors, turning absolute positions into relative phase differences. This provides relative position information while keeping embedding dimensionality unchanged and is widely used in recent decoder-only LLMs.
181
+
182
+
For how token and positional embeddings are combined inside the model, see [the LLM architecture page](5.-llm-architecture.md).
183
+
184
+
### **Extending Context Windows in RoPE-Based Models**
185
+
186
+
Recent work shows that context length is often limited by the positional encoding scheme rather than the token embedding matrix itself.
187
+
188
+
- **Position Interpolation (PI):** Rescales position indices so longer sequences map into the range seen during training, enabling extension with minimal fine-tuning. Example:
189
+
190
+
```python
191
+
# Position Interpolation (PI) intuition
192
+
orig_ctx = 2048
193
+
new_ctx = 8192
194
+
scaled_pos = pos * (orig_ctx / new_ctx)
195
+
```
196
+
197
+
-**YaRN:** A compute-efficient RoPE extension strategy that modifies RoPE scaling/interpolation to extrapolate to longer contexts with fewer additional training steps.
198
+
176
199
## Code Example
177
200
178
201
Following with the code example from [https://github.com/rasbt/LLMs-from-scratch/blob/main/ch02/01_main-chapter-code/ch02.ipynb](https://github.com/rasbt/LLMs-from-scratch/blob/main/ch02/01_main-chapter-code/ch02.ipynb):
0 commit comments