Zubnet AIAprenderWiki › Positional Encoding
Fundamentos

Positional Encoding

Positional Embedding, RoPE, ALiBi
Un mecanismo que le dice a un modelo Transformer el orden de los tokens en una secuencia. A diferencia de los RNNs que procesan tokens secuencialmente (así la posición es implícita), los Transformers procesan todos los tokens en paralelo y no tienen sentido inherente del orden. Los positional encodings inyectan información de posición para que el modelo sepa que «dog bites man» y «man bites dog» son distintos.

Por qué importa

Sin información posicional, un Transformer trata una oración como una bolsa de palabras — el orden se pierde. La elección de positional encoding también determina qué tan bien un modelo maneja secuencias más largas que las vistas durante el entrenamiento, razón por la cual técnicas como RoPE y ALiBi son críticas para modelos de contexto largo.

Deep Dive

The original Transformer (2017) used fixed sinusoidal functions at different frequencies for each position and dimension. These had a nice theoretical property: the model could learn to attend to relative positions because the sinusoidal patterns create consistent offsets. But learned positional embeddings (a trainable vector for each position) quickly became the default because they performed slightly better, despite being limited to the maximum training length.

RoPE: The Modern Standard

Rotary Position Embeddings (RoPE, Su et al., 2021) encode position by rotating the query and key vectors in the attention mechanism. The angle of rotation depends on position, so the dot product between two tokens naturally encodes their relative distance. RoPE is used by LLaMA, Mistral, Qwen, and most modern LLMs. Its key advantage: it enables length extrapolation — models can handle sequences somewhat longer than those seen during training, especially when combined with techniques like YaRN or NTK-aware scaling.

ALiBi and Beyond

ALiBi (Attention with Linear Biases) takes a simpler approach: instead of modifying embeddings, it adds a linear penalty to attention scores based on distance between tokens. Farther tokens get penalized more. This requires no learned parameters and extrapolates well to longer sequences. Some architectures combine approaches or use relative position biases. The trend is toward methods that generalize beyond the training length, since context windows keep growing.

Conceptos relacionados

← Todos los términos
← Pooling Pre-training →