r/deeplearning • u/Rajucg • 11d ago
I animated what an embedding actually is, using one token (strawberry) in GPT-2's table: the row, cosine similarity, a 2D map, king − man + woman, and why "bank" needs the layers (6.5 min video)
I made this explainer for my small channel and would like feedback from people learning this, especially if anything is wrong. Every number in it comes from my own Colab runs.
- In GPT-2 small, " strawberry" is token 41236. That number picks row 41236 of the embedding table: 50,257 rows of 768 numbers. The table holds 38,597,376 numbers, about 31% of the model.
- Cosine similarity compares the direction of two rows. Strawberry's closest rows: Strawberry 0.78, strawberries 0.77, tomato 0.62, raspberry 0.60, peach 0.59. "car" scores 0.25, and 40,830 rows are closer than car.
- A PCA map of 20 words (it keeps only 28% of the spread). In the full 768 numbers, 19 of 20 words have their nearest neighbour in their own group. The exception: bicycle's nearest is horse.
- The numbers start random and are nudged during training, so words that fit the same sentences end up close.
- king − man + woman: queen wins at 0.71, but only because the standard method skips the three input words. Skip nothing and king itself is closest (0.78). Same in GloVe and word2vec. Queen is still 2nd of 50,257, so the direction is real (Nissim et al. 2020 discuss this).
- The table gives "bank" one row everywhere. In BERT's last layer, two money banks score 0.82 and river vs money banks score 0.49 and 0.44.
- Back to search: with all-MiniLM-L6-v2, "forgot my password" vs "can't log in" scores 0.52, vs "forgot my umbrella" 0.34. But "The flight was cancelled" still ranks "The flight was wonderful" (0.58) above "My plane isn't leaving today" (0.54).
The narration is an AI voice reading my own script. Sources are in the description.
1
Upvotes
1
u/EffectiveCounty2313 10d ago
the 2d map visualization is clean, but I'd love to see how the embeddings moves during training, like if you could show the same token drifting toward related concepts over epochs.
1
u/AgitatedTumbleweed65 2d ago
It's ok, but I feel that that's just generic way how everyone discribe it and imo it is just a numerical view, disconnected from the underlying topology and geometry of the learned, underlying manifold(assuming you believe in this hypothesis).
I think it would be much cooler to show that language as a whole can be approximated as lower dimensional manifold of certain topology, where certain concepts lie together along a certain dimension , this would also allow for visual demonstration of cosine similarities and other mateics.
But nevertheless, really neat animation style wise , good job!👍