Dr. Mark Humphrys

School of Computing. Dublin City University.

Online coding site: Ancient Brain

 

Search:


Large Language Models


  


Intro: Large Language Models explained

Intro: Large Language Models explained.
  


Pre-training for Generating text. Learning probabilities of next word as weights.

  

Chapter 5: Transformers, the tech behind LLMs

Chapter 5: Transformers, the tech behind LLMs.
  

"Predicting" an entire story from seed text. Predict one word. Feed back in. Predict another word. Feed back in.
I like the way he says it feels like this should not really work, but it can.
  

Attention mechanism is used for nearby tokens to update the numbers (i.e. the meaning) of the vector of a token.
Here the vector for "model" ends up entirely different in the two situations.
  

An embedding matrix is a trainable lookup table that converts tokens into high-dimensional numeric vectors.
  

To find the female equivalent of "uncle", we can look at the vector difference between "man" and "woman", and add it to the vector for "uncle" and then see what word is nearby.
Learning encoded information on sex into one of the dimensions.
  

In GPT-3 there are 50,257 tokens (not exactly words) and vector length is 12,288 numbers.
That is a matrix of 617 million weights.



Chapter 6: Attention in transformers

Chapter 6: Attention in transformers.
  


The word "mole" in 3 different sentences with 3 different meanings.
In the first step of the transformer, the word "mole" starts with the same embedding vector.
In the next step, the surrounding vectors pass information into the "mole" vector.



Query vector (also encoded as a vector of numbers) asks: "What information is relevant to me?"



Query matrix WQ is a matrix with learned weights to implement a query.
WQ times (each token embedding vector) = Query vector for that token



Key matrix WK represents answers to query.
WK times token vector = Key vector for that token



The two multiplications map the token vector into a lower dimensional space.
A match is when the key (answer) for some tokens closely matches the query (question) for the first token.



Dot product shows where queries and keys align. Result is large positive number.
The embeddings of fluffy and blue "attend to" the embedding of creature.
Softmax along column normalises values from 0 to 1. Like probability.
Get the Attention pattern for the context window.
In this version, size is square of context size.



Earlier words (tokens) are meant to predict later words.
We do not want later words to influence earlier words because that breaks the prediction problem.
So we force below the diagonal here to be zero.



Update the embeddings.
Words relevant to other words pass information to them by adding a vector to shift their position in n-dimensional space.
Value matrix WV times token embedding = Value vector
Value vector is added to target token embedding to move it in the space.



Value vector expresses: "If this token is relevant to this other token, how much should the other token be moved?"
Some tokens are part relevant, some not relevant at all.
Solution is to multiply value vector by the normalised number in the attention pattern.
Here only "blue" and "fluffy" really shift the embedding for "creature".



Each column shows a sum of changes (many probably near zero) to shift the vector in n-dimensional space.



The above was for adjectives updating nouns.
For each type of contextual updating possible, we have different valued W matrices.
And what the contextual updating is is normally hard to define. The matrices are learned through training. Their function is to achieve whatever the model needs to achieve in order to predict the next token.
Multi-headed attention: Run these updates in parallel, each with its own WQ, WK and WV.
GPT-3 uses 96 attention heads inside each "attention block".



When a token vector gets updated (with extra meaning), those updates should themselves be factored in to the updates for other tokens.
So we do repeated rounds of all this. Multiple attention blocks.
Each token/word gradually takes in more meaning, in many different directions.
GPT-3 has 96 layers like this.


  

Chapter 7: How might LLMs store facts

Chapter 7: How might LLMs store facts
  

He considers how a LLM can store the fact that Michael Jordan plays basketball.
He starts by imagining that one dimension in the high dimensional space represents the idea of "First Name Michael" and another dimension represents the idea of "Last Name Jordan" and another dimension represents the idea of "basketball".
For an input string "Michael Jordan plays the sport of ...", the Attention mechanism finds "Michael" beside "Jordan", and eventually encodes into the "Jordan" vector that "Michael" is combined with it.



If input vector to the MLP encodes first name "Michael" and last name "Jordan" then the output of the MLP will be a vector that includes the "basketball" direction, which will be added to the original vector.



Input vector is multipled by a massive model matrix.
Each row of this essentially asks a question about the vector.
Dot product will give the answer.
In GPT-3 this has 49,152 rows.



Rectifier function generates lots of zero values.
He shows where "Michael" plus "Jordan" generates 1, but one of them on their own, or neither, will generate 0.
We end up with a "Michael Jordan neuron" that is active or inactive.



The next layer: Again multiply by a massive model matrix.
Each column can represent a set of features, like "basketball" but also other features.
If "Michael Jordan neuron" value = 1, we add this "basketball" (and other things) column to final result.
Else it = 0 and we add zero times the column to final result. i.e. No effect.

  

Feature recognition is unlikely to be just one neuron.


  
ancientbrain.com      w2mind.org      humphrysfamilytree.com

On the Internet since 1987.      New 250 G VPS server.

Note: Links on this site to user-generated content like Wikipedia are highlighted in red as possibly unreliable. My view is that such links are highly useful but flawed.