Position Embeddings: Learned, Sinusoidal, Relative | The attention family series - Lecture 9

Vizuara
5,572 views •

This is Lecture 9 of The Attention Family. Attention by itself does not know the order of words: "All dogs are animals" and "All animals are dogs" give every word the same output. In this lecture we see four ways to give attention the position of each word, and where each one enters the attention computation. In this lecture I cover: - The problem: nothing in Q, K, V or the softmax uses the position of a token, so reordering the words only reorders the outputs - Does adding a position vector make "dogs" look like a different word? Measured on the real GPT-2 weights: in 99.999% of cases the closest word vector is still the same word - The big picture: position can enter at the input, at the key, or at the score (and in lecture 10, by rotating the query and the key) - Method 1, learned absolute positions (GPT, BERT, GPT-2): one learned row per position, and why the table stops at the training length - Method 2, sinusoidal positions (Attention Is All You Need, 2017): the formula worked out number by number for position 2, and why each dimension changes at a different speed - Why adding position to the input makes the score depend on the two positions separately, not on how far apart they are - Method 3, relative positions (Shaw et al., 2018): a learned vector for each clipped distance, added to the key inside the score - Method 4, relative bias (T5 = Text-to-Text Transfer Transformer, 2019): one learned number per distance bucket, added to the attention score, and how this moves the attention weights Slides for this lecture: https://lecture9-attention-mechanisms.vercel.app Colab notebook (a small GPT trained twice on short stories, once without and once with position vectors, comparing the loss and the stories they write): https://colab.research.google.com/drive/1TKmSTApZEahX6CMY3oyY-FU7DY--qVmp?usp=sharing Next lecture: RoPE, ALiBi, and how a model trained on short text is made to read 128K tokens. Dr. Sreedath Panat MIT PhD, IIT Madras BTech, Co-founder, Vizuara AI Labs

Keyboard shortcuts

On. Switch them off if they collide with your assistive tools; ? still opens this sheet.

Go to

Press g then the letter.

  • gh Latest
  • gs Sources
  • gm Media
  • gv Videos
  • gp Podcasts
  • gc Calendar
  • gd Decoder
  • gz Dataviz
  • ga Datasets
  • gb Blog
  • gk Markets
  • gj Careers
  • gn Prompt Notebook

On this page

  • / Focus search, where there is one
  • t Back to top
  • ? This list
  • Esc Close