To try out
Understanding artificial intelligence (AI)
“If you understand how a model learns, you also know where it goes wrong.”
How do models learn from data? From a language model in miniature to the oldest tool of statistics: three pieces to touch, explained simply. Everything is calculated in your browser; nothing is stored or sent.
Will it rain in the afternoon?
A decision tree asks the morning two questions. Learned from the last 365 days in Bergisch Gladbach.
Chart: Dr Benjamin Moritz, benjaminmoritz.de/en/ai/
Guess first
How many months after its launch did ChatGPT have an estimated 100 million users?
RevealGuess again
Two months after its launch at the end of 2022 (Reuters, after UBS and Similarweb). The methods behind it are much older.
When was the first learning artificial neuron presented?
RevealGuess again
In 1958, by Frank Rosenblatt. Neural networks became something everyone could use only around 2015, when computers were fast and cheap enough.
How old is the line through a cloud of points, the regression?
RevealGuess again
Legendre published the method of least squares in 1805, Gauss in 1809. Everyone could use it from the 1980s, with spreadsheets on the PC.
On how many of 100 days did it rain in the afternoon in Bergisch Gladbach over the last year?
RevealGuess again
On 46 of 100 days (167 of 365), counting at least 0.1 mm between 12 and 20 o'clock. The decision tree tries to tell from the morning.
First: AI in everyday life
What is behind the things you use every day.
Many things in everyday life run on exactly the methods you can try on this page:
- ChatGPT, ClaudeA language model predicts the next word, again and again, learned from huge amounts of text.Try it: Language model
- Alexa and other voice assistantsA neural network turns speech into text; newer assistants answer with a language model.Try it: Language model
- Driver assistance in the carLane keeping and emergency braking recognise lanes, cars and people in the camera image, today mostly with neural networks.Try it: Neural network
- Ads and suggestions while surfingFrom clicks, searches and purchases, models estimate what interests you, often many decision trees together with regressions.Try it: Decision tree
- Music and films suggestedSongs and films become numbers, like words; similar ones lie close together, as on the word map below.Try it: Words as numbers
- Loans and insuranceScores estimate from a few features how likely a loan is to be repaid, for decades with regressions, today also with trees.Try it: Regression
Simplified; providers rarely say exactly which method they use.
Old methods, new computing power
What you can try on this page, and why everyone can use it only now.
Artificial intelligence sounds new. The methods behind it are not: the line through a cloud of dots dates from 1805, the first decision tree from 1963, the first learning artificial neuron from 1958. What is new is computing power. Only when computers became fast and cheap enough could everyone use the methods: regression with the PC in the 1980s, when spreadsheets such as Lotus 1-2-3 calculated it at a command; decision trees and their forests with free software in the 2000s, such as the randomForest package for R in 2002. Neural networks were already at work in the 1990s, but small and for narrow tasks: in American banks they read several million checks a day. Deep networks with many layers could hardly be trained then, and between 1991 and 2015 computing power grew about a million-fold, mostly through graphics cards. In 2012 a deep network trained on two gaming graphics cards won the most important image-recognition contest; since 2015 at the latest, when Google released its TensorFlow software for free, anyone can train such networks. Since the mid-2010s they have been at work in speech recognition and translation; ChatGPT is only the best-known product: two months after its launch at the end of 2022 it had an estimated 100 million users.
1958 first learning neuron (Rosenblatt) · 1986 learning by working back through the errors (backpropagation) · 1990s small networks read checks in banks, deep ones can hardly be trained (Hochreiter 1991) · 2012 AlexNet, trained on two gaming graphics cards, wins the ImageNet contest (deep learning) · 2015 TensorFlow free for everyone · 2017 transformer, the design of today's language models · November 2022 ChatGPT, an estimated 100 million users two months later
1963 first tree (Morgan and Sonquist) · 1984 CART · 2001 random forests, many trees at once (Breiman) · 2002 free for everyone in the R package randomForest
1805 Legendre, 1809 Gauss · 1980s spreadsheets on the PC such as Lotus 1-2-3 calculate it at a command
inventedwaiting for computing power for everyone
Chart: Dr Benjamin Moritz, benjaminmoritz.de/en/ai/
Model 1 of 3
A language model in miniature
At their core, Claude or ChatGPT do the same: they predict the next word. Here with a few short texts that you can change or replace with your own, instead of a large part of the internet.
1 Read and learn
The model splits the texts into words and learns which word follows the two before. Each word becomes a row of numbers. Write as many sentences as you like, one below the other, or paste a whole paragraph: the model splits it into sentences and learns again.
Change how it learns:
2 A look inside the model
Type a beginning. On the left the last words, next to them their numbers, in the middle the neurons, on the right the most likely next words. Point at a box, a circle or a line, or tap it on a phone, to see what it stands for. Tap a next word to add it.
Change since learning again, in percentage points
3 Keep writing
The model picks word after word. Creativity sets how often it departs from the most likely word: low repeats the texts, high mixes them anew, and too high becomes nonsense. In the look inside the model above you can follow how it calculates word by word.
4 Words as numbers
Each word is a row of numbers. Shown on a map, words that are used in a similar way end up close together. Nobody told the model which words belong together.
What large models do differently
They learn from trillions of words instead of a few sentences and have billions of numbers instead of a few thousand. They look not only at the last two words but at a great deal of text before, often as much as a whole book, and weigh which parts matter right now (attention). Afterwards they are refined with feedback from people, so that they answer helpfully instead of merely continuing text. The principle stays the same: predict the next word.
The method, with formulas
Each word w gets a vector ew of d numbers (size: 4, 8 or 16). The last c words (memory: 1 to 3) are put one after another:
x = [ewt−c, …, ewt−1]
One layer of H neurons, each a weighted sum with a bend (tanh):
h = tanh(W1 x + b1)
For each of the V words a score, and from the scores, with softmax, probabilities that add up to 100%; T is the creativity when writing on, while learning T = 1:
z = W2 h + b2, pk = ezk / TΣj ezj / T
Learning means making the real next words likely. The error is the average over all N word pairs of the texts:
L = −1N Σi log pyi
The derivative of L with respect to every number θ (backpropagation) gives g, the direction to change it. Adam takes a step, averaged over the previous steps; η is the learning pace (0.005, 0.02 or 0.1), β1 = 0.9, β2 = 0.999, ε = 10−8, and m̂, v̂ are m and v corrected for the start:
m ← β1m + (1 − β1) g, v ← β2v + (1 − β2) g2
θ ← θ − η m̂√v̂ + ε
Number of parameters: V·d word numbers, H·c·d + H for the neurons, H·V + V for the scores. Large language models put many transformer layers with attention over thousands of words in place of the one layer and have billions of parameters; the principle, predicting the next word, the error via log p, derivatives and Adam, is the same.
Chart: Dr Benjamin Moritz, benjaminmoritz.de/en/ai/
Model 2 of 3
Decision tree: questions, one after another
A tree asks yes-or-no questions, one after another, until the groups are as pure as possible. In research I use trees to sort shares, for example.
Each dot is a real day in Bergisch Gladbach over the past year (the last 365 days): to the right the highest temperature, upwards the rain between 8 and 20 o'clock. Whether you went for a walk is set by your rule below. Teal: walk; plum: home. The tree does not know your rule, it only sees the days and has to find the rule again. More depth means more questions.
Your rule
You go for a walk when all three conditions hold. The scatter says on how many days you decide otherwise all the same, on a whim.
| Tree | Regression | |
|---|---|---|
| Matches your rule | ||
| Right on the learning data | ||
| Right on new data | ||
| Groups | 2 |
Try it yourself
Set your own values: the path through the tree lights up, and a ring marks the point in the picture of the learning days.
And the weather in Bergisch Gladbach?
Tap a day to see its path through the tree. Data basis: Deutscher Wetterdienst (opens in a new tab), own processing, CC BY 4.0 (opens in a new tab), via Bright Sky (opens in a new tab); as of 2026-11-23. The walks are set by your rule: an example, not a recommendation.
And today in Bergisch Gladbach?
Data basis: Deutscher Wetterdienst (opens in a new tab), own processing, CC BY 4.0 (opens in a new tab), via Bright Sky (opens in a new tab); as of 2026-11-23. The tree is an example, not a weather forecast.
The method, with formulas
A tree splits the cases with a question of the form “input j below threshold s?” into two groups, then each group again, and so on. The method is called CART (Breiman, Friedman, Olshen and Stone, 1984).
How mixed a group is, is measured by the Gini impurity; p is the share of yes cases in it:
G = 2 · p · (1 − p)
It is 0 for a pure group and 0.5 for half and half. For each possible question the impurity of both sides counts, weighted by their size:
G(j, s) = nLn GL + nRn GR
The tree tries every input and every threshold (halfway between two neighbouring values) and takes the question with the smallest G(j, s). Then it does the same in each of the two groups. It stops at the depth you set, below 6 cases, in a pure group or when no question makes the groups purer; each side keeps at least 3 cases.
Each leaf answers with the majority of its learning data. Written as a formula, a tree is a regression on yes-or-no questions: Rm are the boxes in the picture, cm their answers, 1[…] is 1 if the condition holds and 0 otherwise:
ŷ = Σm cm · 1[x ∈ Rm]
The tree is greedy: it picks each question as the best on its own, without looking ahead. With much depth it therefore learns the noise as well; random forests average many trees for that reason. The regression for comparison computes with 1 for yes and 0 for no by least squares (see Regression) and says yes from 0.5 on. All of it is computed in your browser, in a few dozen lines of JavaScript.
Chart: Dr Benjamin Moritz, benjaminmoritz.de/en/ai/
Model 3 of 3
Regression: a line through the cloud
The oldest tool of statistics, and still one of the most useful: how much does one thing change when another changes?
Each dot is a summer day at an ice-cream parlour: to the right the temperature, upwards the scoops sold. Tap to add a dot, drag a dot to move it. The line lies where the squares together are smallest: least squares (OLS).
The method, with formulas
We are looking for the straight line
ŷ = a + b · x
For each dot i the vertical distance to the line is its error:
ei = yi − (a + b · xi)
Least squares chooses a and b so that the sum of the squared errors, the squares in the picture, is as small as possible:
S(a, b) = Σi ei2 → minimal
Setting the derivatives to zero gives the answer in one step; x̄ and ȳ are the averages:
b = Σi (xi − x̄)(yi − ȳ)Σi (xi − x̄)2, a = ȳ − b · x̄
How well the line fits is told by R², the share of the spread it explains: 0% explains nothing, 100% means every dot lies on the line.
R2 = 1 − Σi ei2Σi (yi − ȳ)2
With several inputs the line becomes a plane, and the solution is still one formula; this is how the comparison next to the decision tree is computed:
ŷ = a + b1x1 + b2x2, β = (X⊤X)−1 X⊤y
Why squares? Large errors count more than small ones, and the answer can be computed exactly (Legendre 1805, Gauss 1809). The price: a single outlier pulls the line towards itself; try “Add an outlier”.
Chart: Dr Benjamin Moritz, benjaminmoritz.de/en/ai/
How the models hang together
More complex, but nested inside each other: the straight line is in every one of them.
The three models are not separate worlds. A decision tree is a regression on yes-or-no questions and their combinations. A neural network is a regression on kinks that it learns itself, many layers one after another. Take the kinks away and the straight line remains. More complexity means more interactions, more non-linearity and more computing; the core stays the same: a number plus a number times a feature.
- 1Regressiony = a + b × xa straight line
- 2Decision treey = a + b1 × [x ≥ s1] + b2 × [x ≥ s1 und z ≥ s2]a regression on yes-or-no questions; the “and” is the interaction
- 3Neural networky = a + b1 × max(0, c1 + d1x) + b2 × max(0, c2 + d2x)a regression on kinks it learns itself, in many layers
- 4Language modelthe same, billions of times, with words instead of xa very large network
Each dot is a day at an ice-cream parlour over the year. When it gets too hot, people stay inside. Pick a model and how complex it may be; below it the model is written out as a regression.
scoops sold
temperature, °C
Always the same form: a number plus a number times a feature. Only the features become more refined.
Chart: Dr Benjamin Moritz, benjaminmoritz.de/en/ai/
The main points
What the three models on this page have in common, and what follows from it in everyday life.
- Learning means adjustingA model starts with random numbers and changes them step by step until its answers fit the examples. In the regression these are two numbers, in the small language model a few thousand, in Claude or ChatGPT billions.
- Too much fitting does harmA model that learns its examples by heart is wrong on new cases. The decision tree shows it: deeper is better on the learning data, at some point worse on new data.
- Convincing is not the same as rightA language model predicts the next word. It sounds fluent even where it is wrong, because it has learned how texts sound, not what is true. Important facts are worth checking.
- Data and computing power make the differenceThe ideas behind today's AI are decades old. What is new is the amount of data and computing power, which makes much larger models possible.
In practice
These tools are not a toy for me: I have used them in research since 2013.
- 2013An AI model with decision trees for picking shares, run on the Harvard supercomputer; in 2015 the best paper at the annual meeting of the German Finance Association.
- 2018PhD on textual analysis and machine learning in capital markets research, awarded the PLEXUS prize for artificial intelligence in finance.
- TodayWith students and partners at universities, such as UC Berkeley: machine learning in choosing funds, and models for scenarios.
All projects in Career and research
Anyone who would like to know how such models can sensibly be used is welcome to write to me: mail (at) benjaminmoritz (dot) de