What is positional encoding and why is it needed?hard
Answer
Positional encoding injects word-order information into token embeddings, since self-attention on its own treats input as an unordered set of tokens.
Explanation
Without it, “dog bites man” and “man bites dog” would look identical to the model. Common approaches include sinusoidal encodings (original Transformer), learned position embeddings, and rotary position embeddings (RoPE) used in most modern LLMs.
Follow-upHow does RoPE differ from absolute positional encoding?