Frontend Labs
⋯

Part 1 — What is AI, really?

Environment set up, roadmap chosen — time to start the actual argument. Two words, program and model, are doing more work than they get credit for, and the distinction between them is the one idea the rest of this guide is built on.

Chapter 1 — Programs vs models: the one idea that starts everything

In one sentence

Normal software is a set of instructions you write; a machine-learning model is a set of instructions the computer figures out by looking at examples.

The problem

Imagine your boss asks you to write a program that decides whether a photo contains a cat.

You start writing rules:

def is_cat(photo):
    if has_pointy_ears(photo) and has_whiskers(photo) and has_fur(photo):
        return True
    return False

Immediately you're stuck. How do you write has_pointy_ears? You'd need to detect ears, which needs to detect edges and shapes, which changes with lighting, angle, breed, a cat lying down, a cat behind a chair, a cat that is mostly tail... After 5,000 lines you have something that works on your test photos and fails on everyone else's.

You know what a cat looks like, but you cannot write down the rule. That is the core difficulty, and it is why AI exists.

The idea, in plain language

Instead of writing the rule, you write a program with adjustable knobs and then let the computer turn the knobs until it gets the answers right on examples you already have labelled.

TRADITIONAL PROGRAMMING              MACHINE LEARNING
---------------------------          ----------------------------
you write:  the RULES                you provide: EXAMPLES + ANSWERS
computer:   applies them             computer:    finds the RULES

  data  ---+                            data  ---+
           +--> [ your rules ] --> answers       +--> [ LEARNING ] --> RULES
  rules ---+                          answers ---+       (a "model")

Then later:  new data --> [ model ] --> answer
  • The "adjustable knobs" are called parameters (or weights).
  • The process of turning the knobs is called training.
  • The finished set of knob settings is called a model.
  • Using the model on new data is called inference (or "prediction").

A modern LLM is exactly this, with roughly 8 billion to 2 trillion knobs.

How it actually works (the shape of it)

1. Collect examples:      (photo_1, "cat"), (photo_2, "not cat"), ... 50,000 of them
2. Start with random knobs: the model guesses randomly -> ~50% correct
3. Measure how wrong it is: a number called the LOSS (lower = better)
4. Nudge every knob a tiny bit in the direction that reduces the loss
5. Repeat steps 3-4 millions of times
6. Stop when the loss stops improving
7. Test on photos it has NEVER seen. If it works -> you have a model.

Step 4 is the only magical-sounding one, and it's just calculus done automatically (Chapter 15). Everything else is bookkeeping.

Worked example: 2 knobs, by hand

Let's predict a person's weight from their height, with a model weight = a * height + b. Two knobs: a and b.

Three examples:

height (m) true weight (kg)
1.6 55
1.7 65
1.8 75

Start with random knobs a = 10, b = 0:

height 1.6 -> predicts 10*1.6 + 0 = 16 kg    (true 55, off by 39)
height 1.7 -> predicts 17 kg                  (true 65, off by 48)
height 1.8 -> predicts 18 kg                  (true 75, off by 57)
Loss (average error) = (39 + 48 + 57) / 3 = 48 kg    <- terrible

The training procedure would nudge a up (bigger a -> bigger predictions). After many nudges it lands near a = 100, b = -105:

height 1.6 -> 100*1.6 - 105 = 55 kg   (true 55, off by 0)
height 1.7 -> 65 kg                    (true 65, off by 0)
height 1.8 -> 75 kg                    (true 75, off by 0)
Loss = 0                                <- learned!

The computer discovered the rule "weight ≈ 100 × height − 105" from data. It was never told. Now scale that from 2 knobs to 8 billion and from heights to every sentence on the internet, and you have an LLM.

Practice (10 min)

Run this and watch a model learn:

import numpy as np

heights = np.array([1.6, 1.7, 1.8])
weights = np.array([55.0, 65.0, 75.0])

a, b = 10.0, 0.0          # random starting knobs
lr = 0.1                  # how big each nudge is ("learning rate")

for step in range(2000):
    pred = a * heights + b
    error = pred - weights
    loss = (error ** 2).mean()

    # the nudges (this is calculus; Chapter 15 explains it)
    grad_a = 2 * (error * heights).mean()
    grad_b = 2 * error.mean()

    a -= lr * grad_a
    b -= lr * grad_b

    if step % 400 == 0:
        print(f"step {step:4d}  loss {loss:8.2f}  a={a:7.2f}  b={b:8.2f}")

print(f"\nLearned rule: weight = {a:.1f} * height + {b:.1f}")
print("Predict for 1.75m:", a * 1.75 + b)

Now change things and observe:

  1. Set lr = 2.0. What happens? (The loss explodes — the nudges overshoot.)
  2. Set lr = 0.0001. What happens? (It barely learns — nudges too small.)
  3. Add a 4th data point (1.9, 200) — an outlier. How does the learned rule change?

Write what you saw in notes.md. You have just discovered why learning rate is the most important setting in all of machine learning.

Common confusions

  • "Is the model a program?" Yes — it's a program whose numbers were found by training rather than typed by a human. The surrounding code (how to multiply the numbers) is still written by people.
  • "Does the model understand?" It found a pattern that predicts well. Whether that is "understanding" is a genuinely open question; operationally, treat it as a very good pattern-matcher. We return to this in Chapter 31.
  • "Where does the model live?" It's a file — a big list of numbers. A 7-billion- parameter model is roughly a 14 GB file.

Check yourself

  1. In your own words, what is the difference between a program and a model?
  2. What is a "parameter"/"weight"?
  3. In the height/weight example, what was the loss measuring?
  4. Why did lr = 2.0 break training?

(Answers: Appendix F.)

Further reading

  • Video (12 min): "But what is a neural network?" — 3Blue1Brown. Watch just the first 5 minutes now; the rest will make more sense after Part 4.
  • Article: Google's Machine Learning Crash Course, "Framing" and "Descending into ML" modules — free, ~40 min, excellent for exactly this chapter.
  • Book chapter: Hands-On Machine Learning (Géron), Chapter 1 — "The Machine Learning Landscape". The best single chapter introduction in print.
  • Video (10 min): "Machine Learning Explained" — Zach Star or StatQuest's "Machine Learning Fundamentals: Bias and Variance" for a friendly overview.

Generated from real-life-ai-example-v1.md · 8 Oct 2026 16:36