r/LargeLanguageModels • • 5d ago

Discussions 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.

Video: https://www.youtube.com/watch?v=Cli-YmdFmnY

1 Upvotes

0 comments sorted by