Understanding Positional Embeddings in Modern LLMs (magazine.sebastianraschka.com)
190 points by vismit2000 12 hours ago
programjames 8 hours ago
This article is only about understanding the implementation of positional embeddings, but to really understand positional embeddings you have to understand the theory. Positional embeddings are group representations. This is how you find them, and this is also how you parameterize them to make them differentiable/learnable. To give a few examples:
1. Rotary positional embeddings are representations of the translation group. The n-dimensional translation group ℝⁿ is abelian, so its irreducible representations are all one-dimensional ρ: ℝⁿ → ℂ, specified by a momentum vector m: ρₘ(x) = exp(i⟨m, x⟩). You can get a multi-dimensional representation by choosing several m, which are your learnable parameters.
2. If you wanted RoPE embeddings to also preserve rotation (perhaps you have scenes viewed at arbitrary angles), you are looking for representations of the special Euclidean group. The irreducible representations in four dimensions are your familiar particles: electrons, protons, etc., and in general are parameterized by a momentum vector and a discrete spin vector. You would have to do some kind of annealing process to train the spin vector (or you could just make it constant).
3. If you want to do attention on quadtrees, well, what is the group? Suppose every node in the quadtree has local coordinates scaled to [0, 1]. Moving up/down/to a neighbor in the quadtree requires an affine transformation of the local coordinates, which compose, so we can label every node by its affine transformation to the root (x, d): y → x + 2⁻ᵈy, where x is the node's translation in the image and d is its depth in the tree. The finite-dimensional irreducible representations are parameterized by momentum vectors m as well as a modulus M and basis vectors {e₁, e₂, ..., eₖ} where k = ord₂(M) and look like ρₘ,ₑ(x, d) = DPᵈ where D is the diagonal matrix with entries Dⱼⱼ = exp(2πi⟨2ʲm, x⟩ / M) and P permutes the basis vectors.
nlitened 4 hours ago
As I understand, this is post-factum rationalization of what positional embedding is, not the actual theory used to build neural networks.
From what I usually see, ML researches just throw everything at the wall and see what sticks. Whatever approach turns out to work better, gets used more often, and sometimes theoretical background is developed for why it works. RoPE works not because it’s good math, just it turned out to work better than some other equally arbitrary approaches at some point, and then other approaches have also been developed that work better than RoPE.
Mabusto 2 hours ago
This is the most frustrating part of trying to understand machine learning. You can read a bunch of really great math books that rigorously build concepts from the ground up (calculus, linear algebra), then you start to get into the more hand wavey math (_some_ statistical concepts feel like this) and then you start getting into some of the theory behind machine learning systems and expecting the same amount of rigor and ability to understand _why_ something works and it’s always an unsatisfying explanation. I really wish there would be more disclosure like “this is what we tried and this seems to work, we think this is why” rather than present the method, give some mathematical formalization of the method, then go “it works great” and then move on. It leaves people like me wondering if there is something that I’m missing or some hole in my knowledge that is obvious to everyone else, OR does no one actually know why this works and just don’t want to say. Just give us a hint, make the shrug emoji or something, the more I learn about machine learning, the more I get that it really is more art than science.
programjames 2 hours ago
fc417fc802 3 hours ago
Both things can be true and useful. You can search for solutions in a fairly arbitrary manner, and when you find something that works you can attempt to develop a theory to explain it in the hope that said theory will enable more efficient search efforts going forward.
D-Machine 2 hours ago
This is exactly correct.
esafak 18 minutes ago
There is no enlightenment in this. Are you going to make the next breakthrough by throwing yet more mud at the wall, or are you going to take educated steps based on a "post-factum" analysis of what worked well so far?
mathisfun123 4 hours ago
> As I understand, this is post-factum rationalization of what positional embedding is, not the actual theory used to build neural networks
It's always like this because people can't admit ML is just spray and pray. So they superimpose theory.
programjames 3 hours ago
LudwigNagasena an hour ago
That seems to skip a few steps that explain why any of that is important for a positional encoding. I think the original author of RoPE explains the motivation behind it in his own blogpost quite well ( https://spaces.ac.cn/archives/8265 ). And it doesn’t seem to treat group theoretic understanding as something foundational. It mostly relies on engineering goals and geometrical intuition.
ankkalinna 3 hours ago
Here's a nice write-up on group theory and positional encodings: https://blog.janestreet.com/using-group-theory-to-explore-po...
senderista 2 hours ago
This is better than TFA, thank you!
tsimionescu 2 hours ago
> The irreducible representations in four dimensions are your familiar particles: electrons, protons, etc
Can you explain more what you mean here? What do electrons (elementary particles) have to do with protons (complex composite particles) and with general principles of four-dimensional spatial transformation? The electrical force is not a direct consequence of space-time geometry, and even less so the specific particles we happen to find in our universe.
programjames 2 hours ago
Oops, should say quarks not protons. I meant just the elementary particles. I cannot edit the comment anymore or I would fix that.
tsimionescu 2 hours ago
augment_me 7 hours ago
I dont think the target audience for the blog is abstract algebra grad students
However would be good to add that the solution can be structural(like in NoPE), then you dont need explicit representations and it just falls out of your architecture.
programjames 6 hours ago
When I see a title "Understanding..." I assume it will be about understanding theory not implementation or the theory of implementation. When I see a title "Surveying..." or "Understanding Implementation..." I assume it will be about surveying the implementation of that theory. There was just a title mismatch so I felt it was prudent to fill in the gap in understanding the blog did not cover.
Also, I expect the target audience of the blog is ML researchers, since he goes into some of the math, and umm... the kind of ML researcher that is not at least aware of the basics of abstract algebra is closer to an alchemist than a researcher.
monocasa 5 hours ago
empiricus 5 hours ago
At the quantum level, nature seems to use the half spin ireps, but I fail to see if they are useful for 2D images or maybe 3D shapes as inputs for LLMs. Any ideas?
fractorial 5 hours ago
This comment is precisely why I opened this article when it had 0 comments in a new tab to come back to.
mathisfun123 4 hours ago
It's wrong though lol
mathisfun123 4 hours ago
This is just basic lie theory shoe-horned where it doesn't belong lol.
programjames 3 hours ago
It is called representation theory, and once you have seen even the basics of representation theory it is obvious the authors of the original RoPE paper were trying to rederive a representation for the translation group.
The reason you want to know the general theory behind positional embeddings is it lets you work with other kinds of relative positions. For example, quad/octtrees are useful for faster attention on large images/videos, or a Gaussian splat might want 3D translation + rotation invariance.
I believe you can also go further and start adding in gauge groups and whatnot, but I just thought about that off the top of my head.