LLMs · Guide
Large Language Models (LLMs): A Complete Guide
How LLMs work — tokens, attention, context windows, prompting, function calling, fine-tuning.
A large language model (LLM) predicts the next token from patterns it learned across huge text corpora. This guide covers how LLMs work, tokenization and context windows, transformer attention, prompt engineering, function calling and structured output, and how to choose between fine-tuning, RAG, and prompting.
Generate your own lesson →What you'll learn
- How Do LLMs Work?
- Prompt Engineering Explained
- Transformer Attention Explained
- What Is Generative AI?
- Fine-Tune an LLM with LoRA
- Function Calling and Tool-Use Patterns
- How Large Language Models Work
- Pretraining and Scaling Laws
- Prompt Engineering Foundations
- Prompt Engineering: Full Course
- Quantization, Distillation, and Inference Optimization
- RLHF, DPO, and Preference Tuning
- Structured Outputs and JSON Schema
- Tokenization and Context Windows
Lessons in this guide (14)
How Do LLMs Work?
A large language model (LLM) works by predicting the next token — a word or word-piece — over and over, given all the text so far. It was trained on vast text to learn these patterns, storing them in billions of parameters. Generating one t
Prompt Engineering Explained
Prompt engineering is the practice of designing the text instructions given to a large language model so it produces accurate, useful, and consistent outputs. A strong prompt usually sets a role, a clear task, relevant context, examples, an
Transformer Attention Explained
Attention is the mechanism inside a transformer that lets the model weigh how much each token in the input should influence every other token when building meaning. For each token, attention creates a query, key, and value vector, scores th
What Is Generative AI?
Generative AI is a class of artificial intelligence that creates new content — text, images, audio, video, or code — by learning patterns from large amounts of training data and then producing original outputs that resemble it. Models like
Fine-Tune an LLM with LoRA
LoRA (Low-Rank Adaptation) is a parameter-efficient fine-tuning method that adapts a large language model by freezing its original weights and training small low-rank matrices injected into its layers. Because it updates only about 0.1 to 1
Function Calling and Tool-Use Patterns
Function calling lets a large language model request that your code run a defined function and then use the result, turning a text generator into something that can fetch data and act. Beyond the basic round trip, real systems rely on patte
How Large Language Models Work
A large language model works by turning text into tokens, converting those tokens into vectors, passing them through many transformer layers that use attention to build context, and predicting the probability of the next token — then sampli
Pretraining and Scaling Laws
Pretraining is the phase where a large language model learns language and knowledge by predicting the next token across a massive text corpus, producing the base model that later fine-tuning refines. Scaling laws are the empirical finding t
Prompt Engineering Foundations
Prompt engineering rests on a few durable principles rather than clever tricks: be specific about the task, show the model examples, tell it the exact output format, and give it room to reason before answering. Because a large language mode
Prompt Engineering: Full Course
Prompt engineering is the discipline of designing the instructions, context, and examples given to a large language model to get reliable, high-quality outputs. This course covers the core skills in order: the anatomy of a prompt, zero-shot
Quantization, Distillation, and Inference Optimization
Serving a large language model is dominated by inference cost, and three techniques cut it. Quantization stores weights in lower precision (16-bit to 8- or 4-bit), shrinking memory and speeding compute with minor accuracy loss. Distillation
RLHF, DPO, and Preference Tuning
Preference tuning aligns a language model with human preferences — helpfulness, harmlessness, and following instructions — after pretraining and supervised fine-tuning. RLHF (Reinforcement Learning from Human Feedback) trains a reward model
Structured Outputs and JSON Schema
Structured outputs make a large language model return data in a machine-readable format — usually JSON that conforms to a schema you supply — instead of free prose. Modern providers offer a structured-output mode that constrains the model's
Tokenization and Context Windows
A large language model does not read characters or words — it reads tokens, chunks of text (roughly four characters or three-quarters of a word in English) produced by a tokenizer. The context window is the maximum number of tokens the mode
Frequently asked questions
How do LLMs work?
An LLM is a transformer neural network trained to predict the next token. Given your prompt, it repeatedly predicts the most likely next token, building the response one token at a time from patterns learned in training.
What is a context window?
The context window is the maximum amount of text (measured in tokens) a model can consider at once — your prompt plus its response. Everything the model 'sees' for a request must fit inside it.
What is prompt engineering?
Prompt engineering is structuring your instructions, examples, and context so the model reliably produces the output you want — via clear tasks, few-shot examples, output format, and constraints.