Home / Generative AI / Lesson 1

Lesson 1 · Foundations

What is generative AI?

AI vs ML vs deep learning vs generative AI, in simple words, with moving pictures and code you can copy or download.

Lesson 1 video thumbnail
▶ Watch this lesson on YouTube

1The four circles

AI Machine learning Deep learning GenerativeAI

Think of your address. India holds Maharashtra, Maharashtra holds Mumbai, and Mumbai holds your street. These four words work the same way.

  • AI: any machine that does something that looks smart.
  • Machine learning: it learns from examples.
  • Deep learning: machine learning with many layers.
  • Generative AI: it creates new things.

All generative AI you use today is AI. But not all AI is generative AI.

2AI can be just rules

AI doesn't have to learn. Here a developer wrote the rule by hand: if the email says "free money", it's spam.

spam_filter.pyDownload
def is_spam(email):
    email = email.lower()
    if "free money" in email:
        return True
    return False

print(is_spam("FREE MONEY now!"))  # True
print(is_spam("Fr33 m0ney now!"))  # False

The rule works until a spammer writes Fr33 m0ney. Then you need another rule, and another, forever.

3Machine learning finds the rules

Rules+ Data Answers Data+ Answers Rules

Four students tell us how long they studied and what they scored. Nobody tells the machine the rule.

Hours studiedMarks
marks = 4.0 × hoursError: 30.0
  1. Guess a line.
  2. Check how far it is from the dots. That gap is the error.
  3. Fix the line a little.
  4. Repeat until the error stops shrinking.

It found the rule by itself: marks = 20 × hours.

learn_marks.pyDownload
from sklearn.linear_model import LinearRegression

hours = [[1], [2], [3], [4]]
marks = [20, 40, 60, 80]

model = LinearRegression()
model.fit(hours, marks)            # it learns here

print(model.predict([[5]]))        # [100.]

4Deep learning is just many layers

Hours and marks are easy. Now try writing rules for a cat in a photo: two ears, whiskers, lying down, half behind a sofa. It's impossible.

Deep learning passes the photo through layers, like a team on a factory line. Nobody tells each layer what to look for. It learns that from examples.

Photojust numbers
→
Layer 1finds edges
→
Layer 2finds ears and eyes
→
Answercat

5Generative AI creates

Predictive AI Photo "cat" Generative AI "cat" New photo

It can create text, images, code, audio and video.

6It writes one word at a time

A chatbot keeps asking one question: what word is likely to come next? Press the button and watch a tiny model do it.

Our tiny model has read only this: the cat sat on the mat the cat ran to the mat

the

Press it a few times. You'll often get a sentence that was never in its text, like the cat sat on the cat. That's generating.

7Build it yourself

Here's that tiny generator in Python. Copy it, run it, then change the text to your own sentences.

tiny_generator.pyDownload
import random

text = ("the cat sat on the mat "
        "the cat ran to the mat")
words = text.split()

# Training: write down which word came after which
next_words = {}
for a, b in zip(words, words[1:]):
    next_words.setdefault(a, []).append(b)

# Generating: keep picking a word that followed the last one
random.seed(7)
word = "the"
output = [word]

for _ in range(5):
    word = random.choice(next_words[word])
    output.append(word)

print(" ".join(output))  # the cat sat on the cat

A real chatbot uses the same idea at an enormous scale, with a large language model trained on huge amounts of text.

8What it is not

Not a search engine

It generates an answer. It doesn't look one up.

Not always right

It can sound sure and still invent things. That's a hallucination.

Not a person

It doesn't feel anything. It predicts likely words.

Not always up to date

It knows what it was trained on, unless it's connected to live tools.

Use it like a very fast junior: helpful, but check its work.

9Quick quiz

1. An app blocks emails using rules a developer wrote by hand. Is that machine learning?

No. Nobody learned anything. It's just rules.

2. Is all machine learning also AI?

Yes. Machine learning sits inside AI.

3. One model says if a photo is a cat. Another draws a new cat. Which one is generative?

The one that draws. It creates something new.

Up nextHow LLMs work: tokens, embeddings and how a model picks the next word
See all lessons