AI 101: It's All Just Curve Fitting

Modern AI is one idea done at a huge scale: guess a function, measure how wrong it is, adjust it to be less wrong, and repeat. Neural networks, gradient descent, embeddings and transformers: the main ideas in one post.

Takumi Yamada
· 9 min read
aimachine-learningneural-networksllmfundamentals

Modern AI is often described as a kind of mind, something that reasons, understands or knows things the way a person does. I think a smaller description fits better and is more useful.

Modern AI is one idea, done at a very large scale: find a function that fits your data. It's the same kind of thing you did in a school science lab, when you drew a line through a few measured points. The difference is the size. An AI model has billions of adjustable numbers instead of two, and it was fitted to a large part of the text on the internet instead of ten points.

That can sound too small an idea. I think everything else in the field depends on it. Once you see image recognition, chatbots and code completion as the same act of fitting a function to examples, the field becomes much easier to follow. You can predict what a model will be good at, why it makes things up, and where it will fail.

This post builds that picture step by step. There is no math beyond arithmetic and no programming tutorial, only the ideas, in the order they depend on each other.

The problem: some functions can't be written by hand

Normal programming means writing functions yourself, such as if temperature > 30: wear_shorts(). You know the rule, so you type it.

Now try to write a function that looks at a photo and answers whether there is a cat in it. Its input is a few million numbers between 0 and 255, one for each colour of each , and its output is yes or no. What is the rule? Pointy ears? Then you have to describe pointy ears as pixel values, at every angle, in every kind of light, and half hidden behind a sofa.

Nobody can write that rule. The rule does exist, because cat photos really are different from other photos. But it can't be written as anything a person could type. That gap is why machine learning exists.

Machine learning is what you use when the function exists but can't be written by hand, only learned from examples.

So instead of writing the function, you do three things.

  1. Collect examples of inputs together with the correct outputs, such as photos labelled "cat" or "not cat".
  2. Choose a very flexible kind of function, with a huge number of adjustable numbers. Picture each number as a knob.
  3. Turn the knobs until the function's outputs match the examples.
WRITTENyou know the ruleif temperature > 30the rule, typed by youFUNCTIONLEARNEDyou have examplesphoto → catphoto → not catphoto → catTRAININGturns the knobsFUNCTION
A rule you can type, and a rule that has to be learned from examples.

Steps 2 and 3 are the whole field. are the usual answer to step 2. is the answer to step 3.

Neural networks: a very bendy function

Neural networks are named after the brain, but I would leave that comparison aside, because it mostly misleads. A neural network is a function built from layers, and each layer repeats the same small calculation.

input numberslayer 1layer 2outputevery line is one weight, and every node adds up what arrives and bends it
Three inputs, two layers and one output.

Each layer takes a list of numbers and multiplies them by a grid of weights. It adds up the results, and then bends them with a simple rule. One common rule just replaces every negative number with zero.

That bend is the important part. Without it, stacking many layers would still only give you a straight line. With it, you can stack layers until the function is flexible enough to follow any shape, including the very complicated line between cat photos and all other photos.

When you hear that a model has 7 billion parameters, that number counts its . A large language model is this same diagram, with very wide layers and very many of them.

A black and white figure from a 1960 manual: a room-sized cabinet full of wiring panels, with a camera on a tripod in front of it. Labels point to the camera, the switches, the plugboard and the panels.
The Mark I Perceptron, in a figure from its 1960 operator's manual. It was one of the first neural networks, built as a machine at the Cornell Aeronautical Laboratory. The camera saw a picture through 400 light sensors, and the weights were real knobs, turned by electric motors during training.Figure: John C. Hay and Albert E. Murray, public domain, via Wikimedia Commons (original). Changes: converted to grayscale JPEG.

Here is what a neural network is not. It's not a of the examples it was trained on, and it doesn't follow rules of logic. It's one fixed chain of arithmetic. Everything it knows is stored in the values of its weights, and nowhere else.

Training: how the knobs get turned

A new network starts with random weights, so its answers are no better than guessing. Training makes it less wrong, in five steps.

  1. Show it an example. For instance, a photo of a cat.
  2. Measure how wrong it is. It said 31% cat, and the right answer was 100%. The size of that gap is the loss, a single number that scores how bad the answer was.
  3. Work out which way each knob should turn. The whole network is arithmetic, so calculus can work out, for every knob at once, whether turning it up or down would make the loss smaller. This calculation is called backpropagation.
  4. Turn every knob a tiny step in the direction that makes the loss smaller.
  5. Repeat with the next example, millions of times.
1234EXAMPLEa cat photoNETWORKsays 31% catLOSSshould be 100%BACKPROPAGATIONwhich way to turnevery weight is nudged a tiny step5and again, with the next example
The five steps as a loop. One lap changes the weights by a tiny amount.

This is called gradient descent. Each example moves the weights one small step in the direction that reduces the loss. One step on its own changes almost nothing. After an enormous number of steps, the weights contain detectors for whiskers and ear shapes. Nobody designed those detectors, and it's usually very hard for a person to find them in the weights afterwards.

Two facts about training explain most of the AI behaviour you read about in the news.

A model only learns what is in its data. Train it on ten years of unfair hiring decisions and it learns the unfairness too, because it fits the examples, and the unfairness is in the examples.

A model fills in between its examples. It doesn't understand. It learned a shape that passes through its training data. Close to those examples, it works very well. Far from them, nothing holds the shape in place, so the answers can be wrong while sounding certain. This comes back two sections later as hallucination.

inputoutputwhere the examples are, the fit is goodno examples here: any of these fits just as well
A function fitted to ten examples. Inside the examples the fit is good. Outside them, both dashed continuations fit the data equally well.

Embeddings: turning meaning into geometry

Networks need numbers as input. Pixels are already numbers. But what about words, products or songs? The answer is one of the best ideas in the field.

An embedding gives every word a list of a few hundred numbers, which you can think of as a point in space. Training then moves the points around, with one rule: words that appear in similar sentences should end up close together. After billions of sentences, the positions start to mean something.

manwomankingqueenParisFranceTokyoJapanthe same step takes man to woman and king to queenanother step takes a capital to its country
Four pairs of words and two directions.

"King" ends up near "queen". The direction from "man" to "woman" is roughly the same as the direction from "king" to "queen", so the difference between male and female became a direction in space. "Paris" relates to "France" the way "Tokyo" relates to "Japan", so "capital of" became a direction too. Nobody programmed any of this. It came from fitting the function to which words appear near which other words.

Embeddings are why search can find a document that shares none of your words, because the document and your question land on nearby points. They are also why recommendations got so accurate in the last decade. You are a point, and the things you will probably like are the points near you. A vector database is a database that stores these points and finds the nearest ones quickly.

Transformers and LLMs: autocomplete, scaled past a threshold

A language model is a function with one small job.

Given some text, predict the next word.

That's the whole training goal. Take a sentence from the internet, hide the last word, let the model guess, score the guess, adjust the weights, and repeat for trillions of words. Writing text is the same function run in a loop. The model predicts one word, adds it to the end, and predicts the next one.

the capital of Australia isthe text so farMODELweights fixedone more wordadded to the end, then predict again
Generating text is this loop, run once for every word.

The design that made this work at a large scale is the transformer. It's the T in GPT (Generative Pre-trained Transformer). Its key part is attention. Before predicting, every word in the text can look at every other word and pick out the ones that matter for it. Take the sentence "the trophy did not fit in the suitcase because it was too big". Attention is what lets the model connect "it" with "trophy" rather than "suitcase". Older designs read text one word at a time and forgot the early words. Transformers look at the whole text at once. That also means the work can be split across many (Graphics Processing Units), which is why they could be trained on so much text at all.

thetrophydidnotfitinthesuitcasebecauseitwastoobigweighed morewhat it refers toweighed lessthe wordbeing handled
The example sentence. While the model handles the word it, attention weighs trophy over suitcase.

Here is what surprised researchers. To predict the next word well, a model needs to model almost everything else. To finish "the capital of Australia is", you need geography. To continue a Python function, you need to know Python. Facts, writing style, reasoning and code all ended up stored in the weights. Nobody asked for them directly. They were learned because they made the predictions better. Make the model and its data a thousand times bigger, and the autocomplete starts writing legal summaries.

The other side follows from the same goal. The model is trained to continue text in a likely way, not to say what is true. Ask it about something that was rare in its training data, and it does exactly what it was trained to do. It writes text that looks like a correct answer. When it gives a confident, well-formatted reference to a paper that doesn't exist, the model isn't broken. It's filling in a place where it had no data. This is called hallucination. It comes directly from the training goal, so it can be reduced, by giving the model real documents to read and by more training with feedback, but it can't simply be switched off.

One more difference is worth knowing. It explains pricing and speed, and why models don't learn from your chats.

Training is turning the knobs. It takes months on thousands of GPUs, and it happens rarely. It's where the model's knowledge comes from, and why that knowledge stops at a certain date.

Inference is running the finished function on your input. Every chat message you send is inference. The weights don't change, so the model isn't learning from your conversation. It reads the whole conversation again for every message, and the context window is the limit on how much text it can read at once.

TRAININGhappens rarelytrillions of wordsthe training textWEIGHTSbeing changedmonths, onthousands of GPUsINFERENCEevery messagethe whole chat so farread again each timeWEIGHTSnot changednext word
The weights only change during training. A chat only reads them.

What to actually keep

Six sentences hold the whole post.

  1. Machine learning is fitting a function, used when the rule exists but can't be written by hand.
  2. A neural network is a very flexible function. Its parameters are the knobs, and there are billions of them.
  3. Training means measuring how wrong the model is and turning every knob a little to reduce it. That's gradient descent.
  4. A model is its data. What is in the data, good or bad, ends up in the model, and far from the data its answers are confident guesses.
  5. Embeddings turn meaning into geometry. Similar things are close, and relationships are directions.
  6. Language models predict the next word. That goal made them learn a lot about the world, and the same goal causes hallucination where they had no data.

None of this makes these systems less impressive. Fitting a function with billions of numbers produces behaviour that nobody fully predicted, and researchers are still working out what those functions contain.

But when products are described in big words, this description keeps making correct predictions. It tells you what a system will be good at: anything that appears a lot in its training data. It tells you where it will fail: at the edges of that data. And it tells you what the system is: a function fitted to data, and a very useful one.

Check yourself

3 questions · nothing is saved
  1. 1.When is machine learning the right tool, according to this post?
  2. 2.What does an embedding do?
  3. 3.Why do language models hallucinate?

Who wrote this

Author profile and background

Takumi Yamada

Takumi Yamada

· Backend Engineer

Backend engineer building services, databases, Linux tooling, and NEGEN SYSTEMS. Writing about low-level mechanics, distributed systems, and real-world security.

End of post
NEGEN SYSTEMS
Receipt · post 24 of 31
Written
Jun 28, 2026
Length
1,936 words · 9 min
Built
…
Served by
…
Delivered
…
Over the wire
…
Go's share
…
Next up the stack · L7 Math, AI & vision

OpenCV 101: Every Image Is a Grid of Numbers

A photo is a rectangle of numbers, and everything OpenCV does is arithmetic on that rectangle. Mat, BGR, convolution, thresholds, contours and perspective warps: the ideas that make the library's 2,500 functions easier to find your way around.

12 min read
From other series