Learn / AI / AI: One Course / What Is AI? What Is an LLM?

AI: One Course · Lesson 1 of 20

What Is AI? What Is an LLM?

AI, machine learning, deep learning and large language models, explained with a next-word game you can run.

  • Beginner
  • 22 min read
  • 3 objectives

What you will learn

  • Explain how an LLM predicts the next token
  • Tell AI, ML, deep learning and LLM apart
  • Describe pre-training, fine-tuning and RLHF

Your Progress

0 of 20 lessons 0%

  • Lessons0 / 20
  • Completed0
  • Est. time left~ 9 hours

Create a free account to keep your progress on every device.

Welcome to the whole course in one sentence: a large language model is a machine that has read a huge part of the internet and got very, very good at guessing what word comes next. Everything else you will meet, from chatbots to agents to the scary word "hallucination", grows out of that one idea. So we start there, and we make it concrete by building a (very tiny) one together.

Start with the map: AI, ML, deep learning, LLM

These four terms get thrown around as if they mean the same thing. They do not. Think of Russian nesting dolls: each one sits inside the previous.

+--------------------------------------------------------------+
|  AI  - any machine doing something that looks intelligent    |
|  +--------------------------------------------------------+  |
|  |  Machine Learning - learns patterns from data,         |  |
|  |  instead of being given hand-written rules             |  |
|  |  +--------------------------------------------------+  |  |
|  |  |  Deep Learning - ML with many-layered neural nets |  |  |
|  |  |  +--------------------------------------------+  |  |  |
|  |  |  |  LLM - a giant neural net that predicts    |  |  |  |
|  |  |  |  the next token of text                    |  |  |  |
|  |  |  +--------------------------------------------+  |  |  |
|  |  +--------------------------------------------------+  |  |
|  +--------------------------------------------------------+  |
+--------------------------------------------------------------+
  • AI is the broad goal. A chess engine, a spam filter and a chatbot are all "AI". A thermostat with an if statement barely counts; a self-driving car definitely does.
  • Machine learning (ML) is the approach where you do not write the rules. You show the computer thousands of examples and it works out the rules itself. Show it 100,000 emails labelled spam / not spam and it learns what spam looks like.
  • Deep learning is ML using neural networks with many layers, loosely inspired by the brain. It is what made image recognition, speech recognition and language models possible.
  • An LLM (large language model) is a deep-learning model trained on text at enormous scale. "Large" means billions (sometimes trillions) of adjustable numbers called parameters. GPT, Claude, Gemini and Llama are LLMs.

The one trick: predict the next token

An LLM does exactly one thing, over and over: given some text, it produces a probability for every possible next piece of text (a token, which you will meet properly in the next lesson), picks one, appends it, and repeats. That is the entire engine. Answering questions, writing code and translating languages are all "what comes next?" in disguise.

Let us build the smallest possible version. This bigram model reads a few sentences, counts which word tends to follow which, and then generates text by rolling weighted dice. It is a real language model, just a microscopic one.

from collections import defaultdict, Counter

corpus = """the cat sat on the mat . the cat ate the fish .
the dog sat on the rug . the dog ate the bone .
the cat chased the dog . the dog chased the cat ."""

words = corpus.split()
follows = defaultdict(Counter)
for a, b in zip(words, words[1:]):
    follows[a][b] += 1

# What does this tiny "model" believe comes after "the"?
total = sum(follows["the"].values())
for word, n in follows["the"].most_common():
    print(f"after 'the' -> {word:<5} {n}/{total} = {n/total:.0%}")
Output
after 'the' -> cat   4/12 = 33%
after 'the' -> dog   4/12 = 33%
after 'the' -> mat   1/12 = 8%
after 'the' -> fish  1/12 = 8%
after 'the' -> rug   1/12 = 8%
after 'the' -> bone  1/12 = 8%

Those percentages are the model. It has no idea what a cat is. It only knows that in its training text, "the" was followed by "cat" 4 times out of 12. Now let it write, by repeatedly sampling from those probabilities:

import random
from collections import defaultdict, Counter

corpus = """the cat sat on the mat . the cat ate the fish .
the dog sat on the rug . the dog ate the bone .
the cat chased the dog . the dog chased the cat ."""
words = corpus.split()
follows = defaultdict(Counter)
for a, b in zip(words, words[1:]):
    follows[a][b] += 1

def generate(start, length, seed):
    rng = random.Random(seed)
    out = [start]
    for _ in range(length):
        options = follows[out[-1]]
        choices, weights = zip(*options.items())
        out.append(rng.choices(choices, weights=weights)[0])
    return " ".join(out)

for seed in (1, 2, 3):
    print(generate("the", 8, seed))
Output
the cat . the cat ate the dog chased
the bone . the cat . the dog ate
the cat chased the dog . the cat .

Three different "stories", all built from the same probabilities. Some read almost like real sentences, some are nonsense. A real LLM is the same machine with three differences: it looks at thousands of previous tokens instead of one word, it has billions of parameters instead of a table of counts, and it was trained on a big slice of the internet, so its guesses are astonishingly good.

How does a model get this good? Three training stages

  • 1. Pre-training. The model reads trillions of tokens (web pages, books, code) and plays the next-token game billions of times, nudging its parameters after each guess. This costs millions of dollars and produces a base model: brilliant at continuing text, but not yet a helpful assistant. Ask a base model "What is the capital of France?" and it might continue with three more quiz questions, because that is what a quiz page looks like.
  • 2. Fine-tuning (instruction tuning). The base model is trained further on thousands of hand-written examples of good conversations: a question, then a helpful answer. Now it behaves like an assistant instead of an autocomplete.
  • 3. Alignment (RLHF and friends). Humans (or other models) compare pairs of answers and say which is better. The model is nudged toward the preferred style: helpful, honest, harmless, and willing to say "I do not know". This stage shapes personality and safety.

What is inside: a peek at the architecture

Modern LLMs use the transformer architecture (2017). You do not need the math to work with them, but one idea is worth knowing: attention. When the model predicts the next word, attention lets it look back at every earlier word and decide which ones matter most. In "The trophy did not fit in the suitcase because it was too big", attention is how the model works out that "it" means the trophy.

input tokens ->  [embedding] -> [transformer layer x N] -> [scores for every token] -> pick one
                                 |
                        each layer: attention ("look back at relevant words")
                                  + feed-forward network ("think about it")

What LLMs are good at, and what they are not

Strong at: writing and rewriting text, summarising, translating, explaining, brainstorming, writing and reviewing code, extracting structured data from messy text, classifying, answering questions about text you provide.

Weak or risky at: exact arithmetic without a calculator, facts after its training cut-off date, obscure facts (it may invent them), counting letters, anything needing a guarantee of correctness, and knowing what it does not know.

A tour of the model landscape

  • Closed (API) models: GPT (OpenAI), Claude (Anthropic), Gemini (Google). You call them over the internet and pay per token. Easiest to start, generally the most capable.
  • Open-weight models: Llama (Meta), Mistral, Qwen, DeepSeek, Gemma. You can download and run them yourself (on a GPU server or laptop), fine-tune them and keep data private. You trade convenience for control.
  • Sizes: small models (1–8B parameters) are fast and cheap and run on a laptop; large ones (hundreds of billions) are smarter but slower and costlier. Pick the smallest model that does the job.
  • Modalities: many models are now multimodal, accepting images, audio and video as well as text.

Vocabulary you will hear constantly

  • Prompt: the text you send to the model.
  • Completion / response: what it sends back.
  • Inference: running a trained model (as opposed to training it).
  • Parameters / weights: the learned numbers inside the model.
  • Context window: how much text the model can consider at once (next lesson).
  • Hallucination: a fluent but false or made-up answer (lesson 4).

Common misconceptions

  • "It looks things up." No. It predicts. Unless you give it a search tool or documents (RAG), everything comes from its training.
  • "It understands like a human." It models patterns in text extremely well. Whether that equals understanding is a philosophical debate; practically, treat it as a powerful pattern engine with no built-in truth check.
  • "It learns from our chats." By default no. The weights are frozen after training. "Memory" features are text saved and re-inserted into prompts.
  • "Bigger is always better." Not for every job. A small tuned model is often faster, cheaper and good enough.
# Write your solution here
Up next · Lesson 2Tokens, Context Windows and CostWhy models read tokens not words, what a context window really is, and how to estimate cost and latency.