Lesson 1 of 12 · What Is Generative AI?
What Is Generative AI?
Generative AI explained simply: what it is, how tools like ChatGPT, Claude and Gemini produce text by predicting the next word, and what they can and cannot do.
- 6 min read
- Beginner
- Reviewed
- What generative AI is and how it differs from earlier AI
- The core trick behind chat assistants: predicting what comes next
- What a large language model (LLM) is
- The strengths and limits you should know before using one
AI that creates
For many years, most AI systems sorted or scored things. Is this email spam? Is there a cat in this photo? How much will this house sell for?
Generative AI does something different. It creates new content: an essay, a picture, a song, a piece of computer code. You describe what you want in ordinary language, and it produces it.
| Earlier AI | Generative AI |
|---|---|
| "Is this review positive or negative?" | "Write a polite reply to this review." |
| "Which of these photos shows a dog?" | "Draw a dog wearing a space suit." |
| Chooses from fixed answers | Produces something new |
Well-known examples are ChatGPT, Claude and Gemini for text, and image tools such as Midjourney and Stable Diffusion.
The core trick: predict what comes next
Here is the surprising part. A chat assistant does one simple thing, again and again: it predicts the next piece of text.
Finish this sentence in your head:
The capital of France is ...
You thought "Paris" straight away, because you have seen those words together many times. A language model does the same thing with numbers. It has read an enormous amount of text and learned which words tend to follow which.
To write a whole answer, the model predicts one word, adds it to the text, then predicts the next, and repeats.
Build a tiny text generator
The program below is a miniature version of that idea. First it learns which word follows which in three short sentences. Then it generates new text by repeatedly picking a next word.
import random
text = "the cat sat on the mat . the dog sat on the rug . the cat saw the dog ."
words = text.split()
# Learn: for every word, remember which words came after it
next_words = {}
for current, following in zip(words, words[1:]):
next_words.setdefault(current, []).append(following)
print("Words seen after 'the':", next_words["the"])
# Generate: start with one word, then keep choosing a next word
random.seed(3)
word = "the"
sentence = [word]
for _ in range(8):
word = random.choice(next_words[word])
sentence.append(word)
print("Generated:", " ".join(sentence))Change the number in random.seed(3) and run it again to get a different sentence. Some will be sentences that never appeared in the original text. The program has generated something new from patterns it learned.
Real models are vastly bigger. Ours looks at one previous word and learned from about twenty words. A modern model considers thousands of previous words at once and learned from a large part of the public internet. The principle is the same.
What is a large language model?
A large language model, or LLM, is the kind of model behind chat assistants.
- Large: it has billions of adjustable numbers, called parameters.
- Language: it is trained on text.
- Model: it is the result of training, exactly as in machine learning.
Models read text in small pieces called tokens, which are words or parts of words. You can see how text is split in the Token Counter.
What generative AI is good at
- Drafting and rewriting text
- Summarising long documents
- Explaining ideas at any level
- Translating between languages
- Writing and explaining code
- Brainstorming
What to be careful about
- Its knowledge has a cut-off date. A model knows nothing after its training ended unless it is given a search tool.
- It can reflect bias found in its training data.
- It does not know you. It only sees what you type in the conversation.
- Private information needs care. Check a tool's privacy terms before pasting in sensitive data.
A language model gives every possible next word a probability. Print the word with the highest probability.
# A model has calculated these chances for the next word after
# "The cat sat on the ..."
chances = {"mat": 0.62, "sofa": 0.27, "moon": 0.11}
# Print the most likely next word. Output must be exactly: mat
How does a large language model produce an answer?
Summary
- Generative AI creates new content such as text, images, audio and code.
- Chat assistants are powered by large language models.
- An LLM works by predicting the next token, repeatedly.
- It is very capable, but it can hallucinate, so check important facts.
Next: a short history of how we got here.
Finished reading? Tick it off to track your progress.