Welcome :)

Workshop materials QR code Discord QR code

Wi-Fi

Name: FAC

Pass:

StochasticParrots27

Materials

Discord

Starting at 18:10

Attention is all you need

How to build a transformer from scratch

Next-character prediction

Text generation loop

The text-generation loop

Tokenisation

Characters to integers, and the hallo example

A line of text and its integer encoding

The bigram model

The bigram table: current, next, probability

The bigram table: current, next, probability

This model trains and generates. What can no amount of training fix?

Embeddings

Each character's id looks up a learned vector

Each character becomes a learned vector

The integers carried no meaning. So where does meaning come from?

Bag of characters

A bag of characters and its next-character probabilities

Predicting the next character from a bag

The attention table

An attention table over positions

How much to attend to each earlier character

Here every earlier character counts equally. When is that the wrong thing to do?

Similarity vs relevance

Similarity search versus relevance

Not how alike, but how well they fit

Why isn't similarity what we want here?

Queries and keys

every token's query scored against every earlier key

Every query, weighed against the keys before it

A query and a key are two different vectors, not one compared to itself. What is their dot product measuring?

Values

Weighted values blended into the output

A token's output: a weighted blend of values

The key and the value are two different vectors. Why separate what a token advertises from what it hands over?

Self-attention

Every position attends at once, with position folded in

Every position attends at once, its slot baked in

Attention sees the tokens as a set, with no built-in order. So what stops the model reading `hallo` the same as any anagram of it?

Multiple heads

Several heads in parallel, each attending differently

Several heads, each hunting something different

One head can only chase one kind of relationship at a time. How does the model track several at once?

The transformer block

One transformer block, attention and feed-forward

Attention communicates, feed-forward computes

Attention let each token gather information from all the others. What still hasn't happened to what it gathered?

Emergent structure

Text samples at falling loss

Output samples at loss 4.4, 2.5, and 1.5

Nobody programmed speaker names, line breaks, or iambic rhythm. Where did they come from?

Scaling up to ChatGPT

Three model cards at growing scale

The same architecture at 0.2M, 124M, and 175B

Whiteboard

  1. For h, a, l, l, draw each character's integer looking up its row in the embedding table to become a vector, then draw a position vector added onto each
  2. Draw the triangular attention table over positions h, a, l, l: each row spreads weight over itself and the positions before it, upper triangle empty (no future); then say what multiplying this flat table by the character vectors does
  3. Give each of h, a, l, l a query and a key; draw the causal links from each query to the keys it may see, making a couple thicker to show stronger relevance
  4. Add a value to each token; for the last l, blend the four values in proportion to its link strengths to build its output vector
  5. Draw one transformer block: a residual spine with two sublayers, attention (communication, cross-token) then feed-forward (computation, per-token), each normalised on the way in and added back; label which is which

Build it yourself

The full build, code included, on the platform

Let's Build

Workshop materials QR code

One more thing...

Machine Learning Apprenticeship

52 in-person workshops format
Fully funded funding
Peer-led discussion every session cohort
Projects tied to real work outcomes

Eligibility

Employed or own company employed
Resident for 3+ years residency
Apply QR code