Large Language Models Tutorial
Understand tokens, attention, sampling and hallucination, then use LLMs through APIs with clear eyes
Beginner to Intermediate4 lessonsabout 23 min of reading
This course is for developers, students and analysts who use or plan to build on large language models and want a working mental model instead of folklore. You need basic Python; the code in the lessons runs with the standard library only, with no account, key or download.
You will be able to explain why a model counts tokens rather than words and what a context window really limits, describe in plain terms how a transformer produces text one token at a time, tune sampling settings and predict what they do, say why models hallucinate and which mitigations actually help, and estimate the cost and latency of an API-based feature before you build it.
The lessons follow the life of a request. First the input is split into tokens and fitted into a context window. Then the model processes it and predicts the next token. Then a sampler picks one, which is where randomness and invented facts come from. Finally you wrap the model in an application with budgets, retries and evaluation. For writing better inputs, see Prompt Engineering; for connecting a model to your own documents, see Retrieval-Augmented Generation.
Large Language Models lessons
- 1Large Language Models: Tokens and Context Windows ExplainedHow large language models read text as tokens, why a context window is a budget, and how to trim chat history in Python without losing your instructions.5 min read
- 2How LLMs Generate Text: Transformers, Attention and Next-Token PredictionHow LLMs generate text: next-token prediction, a bigram model you can run, and a worked attention example that shows what a transformer does at each step.6 min read
- 3LLM Sampling: Temperature, Top-p and Why Hallucinations HappenLLM sampling explained with a runnable toy: how temperature and top-p change the next-token choice, and why hallucination happens and what actually reduces it.6 min read
- 4Using LLMs via APIs: Latency, Cost Drivers and Choosing a ModelUsing LLMs via APIs: estimate cost and latency in Python, add safe retries, build an evaluation set and choose between models on evidence, not on hype.6 min read
Preparing for an interview? Practise Generative AI & LLMs interview questions
Learning Large Language Models to land a job? Browse open roles or check which skills are trending.