Is a Large Language Model Just a Function? AI Principles Explained with Middle School Math

Large language models are essentially functions — inputs map to outputs through trillion-parameter composite math.
This article explains how large language models work using nothing more than middle school math. By framing an LLM as a function — where user input is x and model output is y — it demystifies training (solving for parameters via backpropagation) and inference (next-token probability prediction via Softmax), making the core mechanics accessible to anyone.
Forget the Math Fear — Let's Rethink Large Language Models
Anyone who's read popular explainers on large language models (LLMs) has likely hit the same wall: you've absorbed a lot, yet still can't quite articulate what an LLM actually is. The problem usually lies in the framing — the more formulas and jargon get piled on, the more confusing things become.
This article takes a different approach. Instead of diving into complex derivations, we'll start from the most fundamental truth and explain LLMs using nothing beyond middle school math. The core idea fits in a single sentence: A large language model is, at its heart, a function.

That definition may sound deceptively simple, but it captures the core logic of how LLMs operate. Once you grasp it, the entire workflow of a large language model suddenly clicks into place.
The Nature of an LLM: A Function
A Quick Refresher on Functions
We all learned about functions in middle school. At its core, a function is simply a mapping between inputs and outputs.
Take the simplest example: y = x. Here, x is the input and y is the output — give it an x, and you get exactly one corresponding y. A slightly more complex example, f(x) = x², is a quadratic function that traces a curve on a coordinate plane.
The notation f(x) is essentially a shorthand. When a function's expression becomes very complex, we use the symbol f to represent the whole thing — so next time we invoke it, we just write f instead of spelling out the full expression.
Running an LLM Is Running a Function
Think about using an AI product like Doubao or DeepSeek: you type something into the input box, wait a moment, and receive a response.
This mirrors exactly how a function works — you put in an x, you get back a y. So we can cleanly abstract an LLM's operation as a function: the user's input is x, it's processed by function f, and the output is y.
From a principles standpoint, LLMs aren't mysterious at all. The real difficulty lies not in the underlying concept, but in engineering it into reality.
It's worth noting that the mathematical structure powering an LLM is a deep neural network — which is itself a massive composite function formed by stacking countless simple functions in layers. Each layer takes the previous layer's output as its input, applies a weighted sum and an activation function, then passes the result forward. This "function within a function" architecture is the most direct engineering realization of the composite function concept. Today's mainstream LLMs — such as GPT, DeepSeek, and LLaMA — are all built on the Transformer architecture, introduced in 2017 by a Google team in the paper Attention Is All You Need. The key innovation was the self-attention mechanism, which allows the model to simultaneously consider relationships between all positions in an input sequence. Compared to earlier RNNs (Recurrent Neural Networks), this dramatically improved parallel computation efficiency and the ability to understand long texts.
The Two Core Phases of an LLM: Training and Inference

Building a working LLM comes down to two core stages: training and inference.
Training: Solving for the Function
Training is essentially finding that unknown function.
The function isn't predetermined — we don't know how many parameters it has or what values they should take. Training is the process of using massive amounts of data to pin down every single parameter in that function.
In a neural network, "parameters" refer to the weights (Weights) and biases (Biases) on each connection. Before training, these values are randomly initialized. During training, Backpropagation and Gradient Descent are used to iteratively adjust them until the model's prediction error on the training data is minimized. Training a model at the hundred-billion-parameter scale typically requires thousands of A100/H100 high-end GPUs running continuously for weeks or even months. Industry estimates suggest the one-time training cost of a top-tier model can exceed $100 million.
Inference: Plugging in the Input to Get the Output
Inference is the process of substituting x into the already-solved function to compute y. In practice, this is simply the moment a user asks a question and the model returns an answer.
The Cost Comparison: Training vs. Inference
Here's a counterintuitive insight:
- In terms of difficulty: solving for the function (training) is far harder than evaluating it (inference).
- In terms of total cost: inference ends up being more expensive overall.
The reason is frequency. Training typically happens once — once the function is solved, it's done. But inference happens billions of times. A product like Doubao, with hundreds of millions of users, may serve billions of calls per day; every single conversation is an inference event. Leading LLM companies therefore maintain tens of thousands of GPUs for real-time responses. This "train once, infer endlessly" economic model is also the underlying logic behind why LLM companies overwhelmingly adopt API pay-per-use pricing — cumulatively, the total cost of inference far outstrips the cost of training.
What Does This Function Actually Look Like?

A natural question arises: can we write out the LLM function explicitly, like y = x + 1 or y = x²?
The answer is: no, not as a simple fixed formula. There are three reasons:
- It is an extraordinarily complex composite function;
- It has an enormous number of parameters — not just one
x, butx₁, x₂, x₃…spanning thousands to trillions of variables, collectively called parameters in the LLM world; - Each company's trained model is unique; there is no universal expression.
Today's mainstream LLMs commonly operate at the trillion-parameter scale, which is precisely why they're called "large" models — both the complexity of the function and the scale of parameters are staggering. A trillion parameters means storing and computing a trillion floating-point numbers. Just storing a hundred-billion-parameter model (at 16-bit precision) requires roughly 200GB of GPU memory, which explains why consumer-grade devices can't run full-scale models locally.
The Nature of Inference: It's Really About Probability

When the input is fed into the function to produce an output, what is that "computation" actually doing?
The answer: computing probabilities.
From Tokens to a Probability Table
Before diving deeper, there's one important concept to understand: LLMs don't process text word by word. Instead, they work with Tokens as the smallest unit of processing. A token might be a full word, a single character, or even part of a word (like the root of an English word). This segmentation is handled by a Tokenizer. Mainstream LLMs typically maintain a vocabulary of 30,000 to 150,000 tokens — that's what a "vocabulary" actually looks like under the hood.
Take the prompt "Please write a poem." Here's what happens internally:
- Build the vocabulary: During training, a vocabulary is constructed from large text corpora. Every token is a "slot" in this vocabulary.
- Compute probabilities: Once the input is fed into the function, the model calculates the probability of every single token in the vocabulary being the next word. Technically, the model first computes raw scores (Logits) for each token, then applies the Softmax function to normalize them into a probability distribution — ensuring all token probabilities sum to exactly 1.
- Generate a probability table: The result is a table of probabilities — for example, one word at 85%, another at 10%, another at 5%, and so on.
- Select the next word: The token with the highest probability is selected as the very next word in the output.
Temperature and Creativity Control
In practice, the selection strategy doesn't always pick the highest-probability token. Engineers introduce a Temperature parameter to control the randomness of outputs: a lower temperature (approaching 0) makes outputs more deterministic and consistent; a higher temperature spreads out the probability distribution, resulting in more varied and creative outputs. This is why asking the same question multiple times can yield different answers — the model isn't "reciting memorized answers"; it's dynamically sampling from a probability distribution during each inference.
The Indirect, Word-by-Word Generation Process
So when a model outputs a complete poem, it might look like it "generated the whole poem at once" — but in reality, it's an indirect, token-by-token prediction process. What the model actually does is repeatedly predict the most likely next token given everything that has come before, then string those tokens together into a complete output.
This is the core mechanism of LLM inference: Next Token Prediction based on probability.
Summary and Further Exploration
Thinking of an LLM as "a function" is an illuminating mental model. Four sentences capture the whole picture:
- Nature: An LLM is a complex composite function with up to trillions of parameters, implemented under the hood by a deep neural network (Transformer architecture);
- Training: Backpropagation and Gradient Descent are used to solve for all parameters in the function — done only once, but extremely difficult and costly;
- Inference: The input is substituted into the function to produce an output — happens with enormous frequency, and the cumulative total cost exceeds that of training;
- Mechanism: The core of inference is using Softmax to compute the probability of each token in the vocabulary being the next word, then sampling step by step according to a chosen strategy to build the complete output.
With this framework in hand, you have the fundamental logic of how LLMs work. The natural next question is: how exactly is this complex function "solved" in the first place? That's the heart of the training process — and an essential piece of the puzzle for truly understanding large language models.
Related articles

Self-Hosted Family Calendar Solutions Compared: Homeflow, Nextcloud, and Lightweight Alternatives
Compare self-hosted family calendar solutions including Homeflow, Nextcloud, Radicale, and Vikunja across CalDAV compatibility, multi-user management, and task integration.

CostPerPrompt: A Deep Dive into Real-Time AI API Cost Estimation and Pricing Comparison
CostPerPrompt is a real-time AI API pricing comparison and cost estimation tool supporting OpenAI, Anthropic, Google and more, helping developers estimate monthly token costs based on real workloads.

Running the 1.56TB Kimi K3 Model on 8GB RAM with Pure C
A developer built a pure C99 inference engine that runs the 1.56TB Kimi K3 model on 8GB RAM using MoE sparsity and NVMe on-demand loading—no GPU, 176KB binary.