AI for All
Online BA · Sem 6
0% complete
0/11 lessons
Lesson 4 of 11
Generative AI and LLMs Explained
AI for All
About the video
20 AI Concepts Explained in 40 Minutes
Gaurav Sen
Study notes
A large language model (LLM) is a neural network trained to predict the next token of an input sequence. LLMs work by tokenizing text, mapping tokens to meaning-carrying vectors, and using attention to resolve meaning from context; they are trained cheaply at scale with self-supervised learning and then specialised through fine-tuning.
Processing input: tokens and vectors
- LLM: a neural network trained to predict the next token, e.g. 'All that glitters' -> 'is not gold'.
- Tokenization breaks input text into discrete tokens; it is smarter than splitting on spaces.
- Subword tokens such as 'ers' or 'ing' carry meaning (e.g. 'ing' marks an ongoing action), which helps the model understand language.
- Vectorization maps each token to a coordinate in an n-dimensional space.
- In that space, words with similar meanings sit close together and opposite meanings sit far apart.
Attention
- The same word can mean different things: 'tasty apple' (fruit), 'Apple's revenue' (company), 'apple of my eye' (a loved person).
- Attention uses the vectors of nearby words to push an ambiguous word's vector toward its meaning in context.
- Example: 'revenue' pushes 'apple' toward Google and Microsoft; 'tasty' pushes it toward banana and guava.
- Attention was introduced in 2017 and became widely known with GPT models around 2022.
- The attention operation has O(n^2) cost in sequence length.
Self-supervised learning
- Supervised learning needs humans to label input/output pairs, which is expensive.
- Self-supervised learning uses the structure of existing text: each prefix of a sentence becomes a 'predict the next token' task, with no human labelling needed.
- Wrong predictions increase the loss, and the network weights are updated; correct predictions need no change.
- This makes LLM training highly scalable.
- Image and video models use the same idea by masking patches and predicting them.
Transformers
- A transformer is a specific architecture for next-token prediction. The LLM is the product (the car); the transformer is the engine.
- Structure: input tokens -> attention block -> feed-forward neural network, repeated over many stacked layers (12 to hundreds).
- Early layers disambiguate words; deeper layers capture complex relations such as sarcasm and implication.
- Other architectures, such as state space or diffusion models, could replace the transformer inside an LLM.
Fine-tuning and few-shot prompting
- A base model is first trained self-supervised, then fine-tuned on question/answer pairs.
- Fine-tuning penalises plausible but undesirable answers (evasive or unhelpful ones) so the model answers as expected.
- One base model (e.g. Llama) can be fine-tuned into many specialised models, such as medical, financial or customer-support models.
- Few-shot prompting augments a query with extra information or examples before sending it to the model.
Contribute
Was this lesson helpful?
We read every rating and fix the weakest lessons first.