Please enable JavaScript to use CodeHS

AI Explained

Everything is numbers

Before an AI can “think,” the world has to become math. Photos, sound waves, and sentences are turned into lists of numbers. A model is just a function with knobs. Learning is the search for the right knob positions.

AI ~12 min High school
The big idea

Everything is numbers

Your brain sees a picture of a dog and thinks, dog. A computer cannot see a dog. It only sees numbers. An AI system converts the world into numbers, runs those numbers through a function, and turns the result back into something useful — a label, a sentence, or a command.

Core idea: AI does not understand images, sounds, or words the way you do. It understands numbers that represent them.

Here are three familiar kinds of data, each turned into numbers. Click a tab to see how the computer reads it.

A photo is a grid of colored dots called pixels. Each pixel is stored as three numbers: red, green, and blue.

Hover over a pixel to see its RGB numbers.

R: — G: — B: —

Sound is numbers over time. A microphone samples the wave thousands of times per second.

First two samples: —

Text is split into tokens (words or pieces of words). Each token gets a number ID from a vocabulary list.

First two token IDs: —

Function output

Waiting for input…
score = w1·x1 + w2·x2 + b

Loss: try to make the score match the target.


Functions

A model is a machine with knobs

Once the world is numbers, the model runs them through a function. You can think of that function as a machine with knobs. Each knob is a number called a weight or a bias. Twisting a knob changes what the machine outputs.

model.py
def model(x1, x2, w1, w2, b):
    # multiply each input by its weight, then add the bias
    return w1 * x1 + w2 * x2 + b

# example: first two pixel brightness values from an image
x1 = 0.70
x2 = 0.55
score = model(x1, x2, w1=1.2, w2=-0.4, b=0.1)
print(score)  # 0.62

That single line — w1*x1 + w2*x2 + b — is the heart of most modern AI. It looks too simple to be useful, but modern models repeat this calculation billions of times, with more inputs and more knobs. The result can recognize faces, translate languages, or drive a conversation.


Optimization

Learning means turning knobs

The real question is: how do you set the knobs? A human could not tune billions of them by hand. Instead, the computer learns by trial and error.

Here is the loop:

  1. Pick an example (an image, a sound clip, a sentence).
  2. Run it through the function with the current knob settings.
  3. Compare the output to the target (the correct answer).
  4. Measure the loss — how far off you are.
  5. Nudge each knob a tiny bit in the direction that would reduce the loss.
  6. Repeat millions of times.

Use the widget above to feel it. Choose an input, adjust the weights and bias, and watch the loss change. When you press Take one learning step, the widget does step 5 for you: it computes the gradient and nudges the knobs. If you press it enough times, the score should slide toward the target.

Why this matters: Modern AI does not contain a human-written list of rules. It contains a giant function and a way to automatically tune its knobs using examples. That process is called gradient descent.


Check yourself
?

Think of something that is not obviously numbers

Pick one thing from your day — a song, a photo, a sentence you sent, or even your mood. How could a computer turn it into numbers? Name at least two number representations.

Example: a song. A computer can represent a song as a list of sample amplitudes (the height of the sound wave at each tiny time step). It can also represent it as a list of frequencies, or as token IDs for the lyrics. Each representation is just a list of numbers.


Quick quiz

Three questions

1. What does an AI model actually receive as input?

2. In the function score = w1·x1 + w2·x2 + b, what do w1, w2, and b represent?

3. What is the goal of one gradient-descent step?

Keep learning

Now that you know AI sees numbers and uses a function with knobs, the next step is to see how it searches for the best knob positions. That search is called optimization.

Part of the AI Explained tutorial series.