Artificial intelligence · Article
How Neural Networks Learn: The Math Behind ChatGPT and Gemini
Published:

In brief
Neural networks learn by making a prediction, measuring how wrong it was with a loss function, and then adjusting internal values called weights backward through the network — a process called backpropagation paired with an optimisation method called gradient descent. The same mechanics, scaled to billions of parameters, underlie how systems such as ChatGPT and Gemini are first trained and then adapted to specific tasks through fine-tuning.
Every time a chatbot answers a question or a photo app recognises a face, a neural network is running a learning process that follows the same basic steps, regardless of the task. According to IBM, that process rests on two linked techniques: backpropagation, which calculates how much each internal parameter contributed to an error, and gradient descent, the optimisation method that uses those calculations to correct the parameters.
What a Neural Network Actually Is
Stanford's Institute for Human-Centered AI (HAI) describes a neural network as a computational model inspired by the structure of the human brain, built from interconnected layers of artificial 'neurons' that process and transmit information. Each neuron takes in numeric inputs, multiplies them by adjustable values called weights, adds a bias term, and passes the result through a non-linear activation function before sending it to the next layer, per IBM's description of the architecture. Stanford HAI notes that this layered structure is what allows neural networks to extract patterns from large amounts of data, forming the basis of deep learning.
Step One: The Forward Pass
Training begins with weights and biases set to random values, IBM explains. During the 'forward pass,' input data moves through the network layer by layer: each neuron computes its weighted sum, applies its activation function, and forwards the output, until the final layer produces a prediction. At this early stage, because the weights are random, that prediction is essentially a guess.
Step Two: Measuring the Error
The network then compares its prediction to the correct answer using a loss function, a formula that quantifies how far off the output was, according to IBM. Different tasks use different formulas — mean squared error is common for predicting numbers, while cross-entropy is used for classification tasks such as sorting images into categories.
Step Three: Backpropagation Traces the Blame
The 'backward pass' is where learning happens. IBM describes backpropagation as working from the output layer back toward the input layer, using a calculus technique called the chain rule to determine how much each individual weight contributed to the overall error. The result is a gradient: a set of values, one for every weight and bias, indicating the direction and size of the adjustment that would reduce the error.
IBM points to the efficiency of this approach: for a network with one million weights, testing each parameter individually by trial and error would require more than a million separate forward passes through the network. Backpropagation reaches the same information in just two passes — one forward, one backward.
Step Four: Gradient Descent Updates the Weights
Once the gradient is known, gradient descent moves each weight a small step in the direction that lowers the error, IBM explains. The size of that step is controlled by the 'learning rate': a higher learning rate speeds up training but risks overshooting the best values, while a lower rate is more precise but slower to converge. The four steps — forward pass, loss calculation, backward pass, weight update — repeat over and over, often across millions of examples, until the loss stops meaningfully decreasing.
From Lab Technique to ChatGPT and Gemini
Large language models apply this same backpropagation-and-gradient-descent cycle at a much larger scale, across two distinct stages. The first, pretraining, exposes the model to massive amounts of unlabeled text — corpora containing hundreds of billions of tokens, according to RBC Borealis — and repeatedly asks it to predict the next word in a sequence. A research blog from RBC Borealis describes this foundation model as fundamentally a network trained to 'predict the next word in a partially complete input string,' which teaches it grammar, facts and general patterns but does not by itself make it a reliable assistant.
The second stage, fine-tuning, adapts the pretrained network to specific behaviour. RBC Borealis outlines three common approaches: supervised fine-tuning on human-written example answers; reinforcement learning from human feedback (RLHF), in which a separate reward model trained on human preferences guides further weight updates; and newer methods such as direct preference optimisation, which skip the separate reward model but still rely on backpropagation. This fine-tuning stage is what turns a general next-word predictor into a system that follows instructions and declines certain requests, rather than simply continuing text in whatever direction is statistically likely.
| Stage | Main goal | Typical data |
|---|---|---|
| Pretraining | Learn language patterns and general knowledge by predicting the next token | Hundreds of billions of tokens of text, per RBC Borealis |
| Fine-tuning | Adapt the pretrained model to follow instructions and specific tasks | A much smaller set of human-written examples or human preference ratings |
Why the Mechanism Matters
Because both pretraining and fine-tuning rely on the same underlying backpropagation-and-gradient-descent loop, improvements to that core technique — faster hardware, better loss functions, more efficient optimisation — affect every downstream application at once, from image recognition to conversational assistants. Stanford HAI notes that neural networks now form the foundation of deep learning systems used in facial recognition, voice assistants and autonomous vehicles, all of which are trained through variations of the same four-step cycle described above.
Questions
- What is backpropagation in simple terms?
- Backpropagation is the step in which a neural network works backward from its final error to figure out how much each internal weight contributed to that mistake, using a calculus rule called the chain rule, according to IBM.
- What is the difference between backpropagation and gradient descent?
- Backpropagation calculates the gradient — how much each weight should change — while gradient descent is the separate step that actually uses that gradient to update the weights by a small amount, IBM explains.
- Do ChatGPT and Gemini keep learning from every conversation?
- The sourced training process described here covers pretraining and fine-tuning, the stages in which a model's weights are set before and shortly after release; the available sources do not describe whether a deployed model's core weights change during ordinary use.
- What is the learning rate in neural network training?
- The learning rate controls how large a step gradient descent takes when updating weights; IBM notes a higher rate speeds up training but risks overshooting the best values, while a lower rate is slower but more precise.
- What is fine-tuning in AI models?
- Fine-tuning is a second training stage, after pretraining, where a model is adapted to specific tasks using a much smaller dataset of labeled examples or human preference feedback, according to a RBC Borealis research blog.
Sources
This piece was prepared with artificial intelligence and passed an automated source check before publication. If you see an error, ask for a correction. Request a correction or reply · How we make this
Related

Artificial intelligenceArticle
How AI Generates Art and Music, and Why "True Creativity" Remains Disputed
AI image tools like Midjourney and Stable Diffusion build pictures by learning to reverse a noise process, while music tools like Suno and Udio compress audio into tokens and predict them step by step, guided by a text prompt. Whether either process counts as genuine creativity is unresolved: researchers are split between calling it pattern-based "remixing" and crediting it with measurable creative performance.
Artificial intelligenceArticle
Why Moonshot Deliberately Weakened Its New Kimi AI Model's Hacking Skills
Chinese AI lab Moonshot says it removed cyber-related training data from its new Kimi K3.1 Pro model so the open-weight system would not push the "frontier" of offensive hacking capability. The move, announced Saturday, October 24, 2026, comes as governments and security researchers warn that increasingly capable AI could make sophisticated cyberattacks cheaper and easier to carry out.
Artificial intelligenceArticle
How AI Text Detectors Work, Explained Through a Prize-Winning Novel Dispute
AI text detectors do not prove who wrote something; they estimate a probability by measuring statistical patterns such as word predictability and sentence-length variation. A detector called Pangram 4.1 recently attributed 99% of a €20,000 prize-winning Spanish-language novel to artificial intelligence, prompting its publisher to suspend promotional events while it investigates.
Artificial intelligenceArticle
Moonshot's Kimi K3.1 Pro: What the New AI Model Can Do and How It Compares
Moonshot AI launched Kimi K3.1 Pro on October 23, 2026, an open-weight AI model with 2.8 trillion total parameters built for coding, 3D modeling and financial research. The Beijing startup says the model narrows the gap with OpenAI's GPT-6 Astra and Anthropic's Claude Opus 5.5 on several of its own benchmarks, though those figures are self-reported and the full model weights are not due for release until November 4, 2026.