by mikewarot · 2y ago · 0 comments
It's my understanding that the delta between two word embeddings, gives a direction, and the magic is from using those directions to get to new words. The oft cited example is King-Man+Woman = Queen [1]
When did this view fall from favor?
[1] https://www.technologyreview.com/2015/09/17/166211/king-man-...
Uncommon words have more information content than common words. So, common words having larger embedding scale is an issue here.
If you want to measure similarity you need a scale free measure. Cosine similarity (angle distance) does it without normalizing.
If you normalize your vectors, cosine similarity is the same as Euclidean distance. Normalizing your vectors also leads to information destruction, which we'd rather avoid.
There's no real hard theory why the angle between embeddings is meaningful beyond this practical knowledge to my understanding.
If you normalize your vectors, cosine similarity is the same as dot product. Euclidean distance is still different.
If all the vectors are on the unit ball, then cosine = dot product. But then the dot product is a linear transformation away from the euclidean distance:
https://math.stackexchange.com/questions/1236465/euclidean-d...
If you're using it in a machine learning model, things that are one linear transform away are more or less the same (might need more parameters/layers/etc.)
If you're using it for classical statistics uses (analytics), right, they're not equivalent and it would be good to remember this distinction.
> It's my understanding that the delta between two word embeddings, gives a direction, and the magic is from using those directions to get to new words... it's the directions and distances to nearby objects that matters most
Cosine similarity is a kind of "delta" / inverse distance between the represenation of two entities, in the case of these models.
A vector is just a list of n numbers. Embedded into a n dimensional space, a vector is a distance in a direction. It isn’t ’the point you get to by going that distance in that direction from the origin of that space’. You don’t need as space to have an origin for the embedding to make sense - for ‘cosine similarity’ to make sense.
Cosine similarity is just ‘how similar is the direction these vectors point in’.
The geometric intuition of ‘angle between’ actually does a disservice here when we are talking about high dimensional vectors. We’re talking about things that are much more similar to functions than spatial vectors, and while you can readily talk about the ‘normalized dot product’ of two functions it’s much less reasonable to talk about the ‘cosine similarity’ between them - it just turns out that mathematically those are equivalent.
I think people skip over that the vectors are the result of the minimization of the objective.
That objective is roughly the same since word2vec. GLoVe is mathematically equivalent. LLMs are also equivalent.
For a LM, the objective function is still roughly the same. Maximizing probability of the next token conditional on previous tokens.
This means the embedding vector of a token minimizes distance to tokens that come before it often, and maximizes distance to those that don't.
Another thing you have to keep in mind is that these embeddings are in n dimensional space. Intuitions about the real world does not apply there
https://github.com/tmikolov/word2vec/blob/master/questions-w...
https://github.com/tmikolov/word2vec/blob/master/questions-p...
and you could see how much better LLMs do on the same 20k examples.
The training process from the original Mikolov et al. paper only uses the analogy examples (questions-words.txt and questions-phrases.txt) to measure accuracy after training: https://github.com/tmikolov/word2vec/blob/20c129af10659f7c50...
A direction can be given in terms of an angle measure, such as cosine.