← BACK TO HOME/ FIELD GUIDE 001

So, how does AI actually work?

A guided look at the mechanisms behind modern language models, what the numbers mean, and what they don't tell us.

01 / DEFINITIONS

AI isn't one single thing.

Artificial intelligence is a broad term for systems designed to perform tasks associated with intelligence, such as language use, perception, prediction, or planning. Machine learning is a major approach where systems learn patterns from data rather than following only manually written rules.

Large language models (LLMs) are one kind of AI. They use neural networks trained to model patterns in sequences of tokens. Chat interfaces can also add external tools, retrieval systems, safety constraints and other software around the model.

Explanation level
How it works · Your choice is saved across lessons

Artificial intelligence includes many kinds of systems. Machine learning learns statistical patterns from data, and a large language model is a particular kind of neural network trained on token sequences.

A useful distinction: The model, the product surrounding it, and the organization deploying it are not the same thing. Each can introduce different behavior and different risks.
02 / THE MATHEMATICS

Weights, matrices, and activation functions.

The simplest neuron multiplies each input by a weight, sums the products, adds a bias, and applies an activation function. One common activation is ReLU, which returns zero if its input is negative.

z = w₁x₁ + w₂x₂ + b
y = max(0, z)

When many numbers are handled together, their operations are efficiently written as matrix multiplication. For a layer of neurons, the same core idea becomes y = f(Wx + b). The matrix W stores many learned weights. This is the basic intuition, but real transformer blocks include normalization, attention, multilayer networks and other operations.

Weights are not moral instructions. They are numbers learned during an optimization process. But mathematical machinery can still power systems with real social consequences.

Explanation level
How it works · Your choice is saved across lessons

Inputs are multiplied by weights and combined with bias values. An activation function changes each neuron's output. Multiple neurons form layers, and the next layer uses the previous layer's results.

Try changing the weights yourself →

There is another essential part of the math: optimization. During training, gradients estimate how changing a weight affects a loss. An optimizer uses that information to update learned parameters across many examples. It's the training process that establishes useful weights, not a human assigning meanings to each individual number.

03 / THE PIPELINE

How a language model generates text.

STEP 01

Training is parameter adjustment

During training, numerical weights are adjusted to reduce an objective called a loss function. The optimizer uses gradients to estimate how changing parameters might affect the loss. Training isn't a database of pre-written answers.

STEP 02

Inference is computation with those parameters

When you send a prompt, an existing model uses its learned parameters to compute an output. A normal chat inference request does not automatically retrain the underlying model on your message.

STEP 03

Language becomes numbers

A tokenizer maps text to token IDs. An embedding layer maps each ID to a numerical vector that can participate in model calculations. The process depends on the model's tokenizer and architecture.

STEP 04

Attention combines context

Transformer attention computes relationships between positions in a sequence using learned queries, keys and values. It helps the model weight information from different parts of the context.

STEP 05

Output is generated piece by piece

The model outputs scores called logits for candidate tokens. Those are converted into a probability distribution, and a decoding strategy chooses the next token. The process repeats.

Why attention matters: A transformer computes query, key and value vectors. Dot products between queries and keys become attention scores. After scaling and softmax, the weights determine how value vectors are combined. Causal language models also mask future positions so the model cannot attend to tokens it has not generated yet.

Why logits matter: The last layer produces a score for each token in the vocabulary. Softmax converts these scores to probabilities. Decoding methods such as greedy selection, temperature sampling and top-k sampling change how the next token is selected. High probability still does not guarantee factual accuracy.

Run real DistilGPT-2 and inspect its tokens →
Explanation level
How it works · Your choice is saved across lessons

Tokenization, embeddings, attention and neural layers turn your prompt into scores for the next token. A decoding rule selects a token, which becomes part of the context for the next round.

Not human understanding by default: Fluency alone doesn't establish consciousness, intention, comprehensive world knowledge, or guaranteed factual accuracy. Those are separate questions with different evidence.
04 / REAL-WORLD RISK

Why understanding the math doesn't settle the safety debate.

It's reasonable to reject the claim that basic matrix operations are themselves malicious. It's not reasonable to conclude that AI systems therefore can't be harmful. They can be wrong, be misused, enable intrusive surveillance, or be granted dangerous permissions.

Different risks require different safeguards: fact checking and uncertainty for unreliable outputs; access control and data governance for private information; evaluation and monitoring for deployment; and human accountability when consequences are significant.

Explanation level
How it works · Your choice is saved across lessons

Even when the math is correct, an AI-generated statement can be false. Its data may contain bias, and a connected assistant could act on untrusted text. Real safeguards belong in the surrounding software.

One important security issue is prompt injection, where untrusted content tries to redirect an AI assistant's behavior. The solution cannot be merely asking the model to ignore malicious instructions. Surrounding software needs to enforce permissions independently.

05 / FURTHER LEARNING

Sources worth opening.

NEXT FIELD GUIDE

What changes when AI writes code?

Explore AI & engineering ↗