How Large Language Models Work
A large language model (LLM) is a neural network trained to predict the next token on a huge amount of text. Its parts, in order:
- Tokenise the prompt into tokens.
- Turn tokens into embeddings.
- Pass them through many layers (a transformer) whose attention mechanism lets every token look at the others to work out context.
- Output a score for every token in the vocabulary, apply softmax, and sample one token.
- Add it to the text and repeat.
Two consequences matter every day. The model produces plausible text, not looked-up facts, so it can state falsehoods fluently. And it only knows what was in its training data plus what you put in the prompt.
Examplepython
Quick check
Why can an LLM state something false while sounding confident?
Your turn: write the code
Print the vocabulary word with the highest probability after softmax.
Finish the quick check (and any code exercise) to complete this lesson, or mark it done yourself.
Tip: use the left and right arrow keys to move between lessons.