Benjamin Moritz Deutsch

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.

Humidity at 7 o'clock above 92%?yesAir pressure below 1018 hPa?noAir pressure below 1014 hPa?yes80rainy daysin 10059 daysno56rainy daysin 10045 daysyes65rainy daysin 10079 daysno24rainy daysin 100182 days
Rain: at least 0.1 mm between 12 and 20 o'clock. All 365 days up to 2026-11-22. 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). An example, not a weather forecast. More: let the tree grow yourself

Chart: Dr Benjamin Moritz, benjaminmoritz.de/en/ai/

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.

Invented early, in everyday use late

Neural network (language model)Computing power: high: one graphics card for small networks, data centres for large language models
1958 inventedfor everyone since 2015

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

Decision treeComputing power: medium: a PC is enough, many trees take longer
1963 inventedfor everyone since the 2000s

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

Regression (least squares)Computing power: small: for a few dots by hand
1805 inventedfor everyone since the 1980s

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

Sources: Legendre (1805) (opens in a new tab); Gauss (1809) (opens in a new tab); Rosenblatt (1958) (opens in a new tab); Morgan and Sonquist (1963, Journal of the American Statistical Association) (opens in a new tab); Rumelhart, Hinton and Williams (1986, Nature) (opens in a new tab); Hochreiter (1991, diploma thesis, TU Munich) (opens in a new tab); LeCun, Bottou, Bengio and Haffner (1998, Proceedings of the IEEE) (opens in a new tab); Breiman (2001) (opens in a new tab); Liaw and Wiener (2002, R News) (opens in a new tab); Krizhevsky, Sutskever and Hinton (2012) (opens in a new tab); Schmidhuber (2015, Neural Networks) (opens in a new tab); Google (9 November 2015, TensorFlow) (opens in a new tab); Vaswani and others (2017) (opens in a new tab); Reuters (1 February 2023, after UBS and Similarweb) (opens in a new tab). Computing power: own estimate.

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:
Size
bigger can keep more, but needs longer and learns by heart sooner
Memory
how many previous words it sees when guessing
Pace
too hasty and it learns restlessly
501000
how often it goes through the texts

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.

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.

0.22

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.

A small neural network: the last words in, a probability for every next word out, neurons in between (tanh), trained with Adam on the cross-entropy; learned in your browser in a few seconds. It mostly repeats what is in the texts and mixes it anew when more creative.

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.

−5 °C25 °C
10 °C38 °C
0 mm5 mm
0%40%
16
rain 8 to 20 o'clock, mm (more than 10 mm: at the top edge) highest temperature, °C Solid: the borders of the tree, one line per question; framed: the group of your values Dashed: the border of the regression
TreeRegression
Matches your rule
Right on the learning data
Right on new data
Groups2

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.

−5 °C38 °C
0 mm10 mm

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.

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.

Going for a walk and rain in the afternoon: real days in Bergisch Gladbach (Deutscher Wetterdienst), two thirds to learn from, one third to check. Shares: made-up data, 160 cases to learn from, 160 new ones to check. If the tree gets deeper, it gets better on the learning data but at some point worse on new data: overfitting. Dashed: for comparison, a linear regression on the same learning data.

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).

scoops sold temperature, °C
Scoops per degree
Explained (R²)
Days

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”.

Made-up example data. A single outlier is enough to tilt the line visibly; that is why careful work checks the data first.

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.

  1. 1Regressiony = a + b × xa straight line
  2. 2Decision treey = a + b1 × [x ≥ s1] + b2 × [x ≥ s1 und z ≥ s2]a regression on yes-or-no questions; the “and” is the interaction
  3. 3Neural networky = a + b1 × max(0, c1 + d1x) + b2 × max(0, c2 + d2x)a regression on kinks it learns itself, in many layers
  4. 4Language modelthe same, billions of times, with words instead of xa very large network

The same data, three models

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.

14
16

scoops sold

temperature, °C

Always the same form: a number plus a number times a feature. Only the features become more refined.

Explained (R²)
Numbers (parameters)
Made-up example data: 90 days. The tree is fitted with CART on the squared error, the network (ReLU, one layer) with Adam; then each is written as a regression on its features. The splits and kinks are searched or learned; that is the costly part.

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.

  1. 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.
  2. 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.
  3. 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.
  4. 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