All articles

Artificial Intelligence · a note from my learning journal

How Does AI Actually Learn? Diving Inside the Mind of a Machine

What happens between giving a computer data and getting an intelligent-looking answer? Behind these outputs are machine learning models, mathematical processes, and training algorithms that allow AI systems to recognise patterns, make predictions, and generate responses. Understanding how these components work together reveals what it actually means for a machine to learn.

What happens between giving a computer data and getting an intelligent-looking answer? Behind these outputs are machine learning models, mathematical processes, and training algorithms that allow AI systems to recognise patterns, make predictions, and generate responses. Understanding how these components work together reveals what it actually means for a machine to learn.

The process involves much more than feeding information into a computer. Models adjust their parameters during training, use patterns in data to improve their predictions, and are evaluated on how well they perform with unfamiliar examples. Exploring these steps helps explain both the capabilities of AI systems and the limitations that shape their performance

Before AI can learn, it needs data

When I think about how artificial intelligence works, one of my first questions is how a computer goes from receiving information to making a prediction. A machine doesn’t automatically know what information matters or which patterns it should look for. That depends on how its learning process is designed.

This is where machine learning (ML) comes in. Machine learning is a field of AI in which algorithms use data to develop models that perform tasks such as classification, prediction, and pattern recognition.

Consider a model designed to identify handwritten digits. We can provide it with images of handwritten numbers, along with their correct labels. Each image contains numerical information about its pixels, and the labels tell the model which digit each image represents.

In supervised learning, these labelled examples form the training data. The model uses them to learn relationships between its inputs and the desired outputs.

The information used as input is often represented through features. Depending on the task, features might be pixel values, measurements, categories, or other useful attributes. The output a model is trained to predict is called the target; in a classification task, it may also be called the label.

However, providing examples isn’t enough on its own. The learning algorithm must use those examples to adjust the model in a way that improves its performance.

That distinction matters: data provides the information, while the learning process determines how a model uses it.

The model: a mathematical representation of patterns

A machine learning model is a mathematical system that maps inputs to outputs. During training, the model’s parameters are adjusted so that its predictions become more useful for the task it is designed to perform.

To understand this, imagine a model that estimates the price of a house using its size. A simple model might represent the relationship as:

Predicted price = (weight × house size) + bias

Here, the weight determines how strongly house size influences the prediction, while the bias allows the prediction to be shifted up or down.

The weight and bias are examples of model parameters. During training, the algorithm adjusts these values to improve the model’s predictions.

This is a deliberately simple model. Real house prices depend on other factors, including location, condition, and market conditions. A more complex model could incorporate several features and learn more complicated relationships.

The underlying principle, however, remains the same: a model has a mathematical structure, and its parameters influence how it processes information.

But where do these parameters come from?

They’re not necessarily written by a programmer as fixed rules. In machine learning, parameters are typically initialised and then adjusted during training using information derived from the data.

The model doesn’t begin with a complete understanding of the relationship it’s supposed to learn. Training is the process through which its parameters are adapted to the task.

This brings us to one of the most important questions in machine learning: how does the algorithm decide which adjustments to make?

Loss functions: measuring how wrong a prediction is

A model needs a way to evaluate its predictions during training. This is the role of a loss function: a mathematical function that measures the difference between a model’s predictions and the expected outputs.

Let’s return to our house-price model. Suppose it predicts that a house costs ₹80 lakh, while the actual price in our training data is ₹90 lakh. The prediction has an error of ₹10 lakh.

One way to measure this error is through squared error:

Squared error = (actual price − predicted price)²

In our example:

Squared error = (90 − 80)² = 100

Here, the calculation uses prices measured in lakhs of rupees, so the squared error is expressed in squared lakh-rupee units.

Why square the difference instead of simply using the difference itself? Squaring makes negative and positive errors contribute positively and penalises larger errors more heavily. In practice, a regression model might use mean squared error, which averages the squared differences across multiple examples.

Different tasks require different loss functions. A model predicting numerical values might use a regression loss, while a classification model might use cross-entropy loss to measure how well its predicted probabilities match the correct classes.

The purpose is not merely to identify whether a prediction is right or wrong. A loss function provides a numerical signal that a training algorithm can use to improve the model.

However, minimising training loss doesn’t automatically produce a reliable model. A model can achieve low loss on its training data while performing poorly on new examples. To understand how its parameters are adjusted, we need to look at optimisation.

Google’s Machine Learning Crash Course explains loss functions and their role in training models.

Gradient descent: how a model adjusts its parameters

Once we have a way to measure prediction errors, we need a method for reducing them. One widely used optimisation algorithm is gradient descent.

Gradient descent adjusts a model’s parameters in a direction that is expected to reduce its loss. It uses the gradient of the loss function, which describes how the loss changes when the parameters change.

Consider our house-price model again. If changing its weight slightly causes the loss to increase, the algorithm can use that information to determine which direction to adjust the weight. It performs similar calculations for other trainable parameters.

The general update rule can be written as:

New parameter = Old parameter − Learning rate × Gradient

The learning rate controls the size of each update. If it is too large, the algorithm may repeatedly overshoot useful parameter values. If it is too small, training can take longer to make progress.

This process repeats across training examples, allowing the model’s parameters to change as the algorithm works to reduce the loss.

It is worth distinguishing two things here: the model makes predictions using its current parameters, while the training algorithm determines how those parameters should change. Gradient descent is one method used to make those changes.

Modern machine learning systems can contain millions or billions of parameters, so these calculations can become computationally demanding. Neural networks, in particular, commonly use gradient-based optimisation methods to adjust their weights and biases.

The important idea is that a model learns by updating numerical parameters according to a training objective—not by simply collecting answers and remembering them.

Neural networks: learning more complex patterns

Some problems are too complicated for a simple mathematical relationship. Recognising objects in photographs, processing language, and identifying intricate patterns in data can require models capable of representing more complex relationships.

This is where artificial neural networks become useful.

A neural network consists of interconnected computational units arranged in layers. These generally include an input layer, one or more hidden layers, and an output layer.

The input layer receives the data. Hidden layers transform that information through mathematical operations involving learned weights, biases, and activation functions. The output layer produces the model’s final prediction or other result.

Each layer builds on the representations produced by earlier layers. Depending on the architecture and training process, a network can learn increasingly complex relationships between its inputs and outputs.

For example, a network trained to classify images might learn representations that respond to visual patterns such as edges and textures, eventually combining information to distinguish objects. This is a simplified illustration; the representations learned by real networks can be much more complicated and aren’t necessarily easy for humans to interpret.

During training, the network’s predictions are evaluated using a loss function. An algorithm called backpropagation calculates how the loss changes with respect to the network’s parameters. An optimiser then uses this information to update those parameters.

Backpropagation and gradient-based optimisation work together: the former calculates gradients, while the latter uses them to adjust the parameters.

Although neural networks are loosely inspired by biological nervous systems, artificial neurons are mathematical computational units. Their operation is not equivalent to the way a human brain thinks or learns.

Understanding this distinction helps explain both the capabilities of neural networks and why their performance shouldn’t automatically be interpreted as evidence of human-like understanding.

Generalisation: can the model handle something it hasn’t seen?

A model might perform exceptionally well on its training data and still fail when given unfamiliar examples. This is one of the reasons evaluating machine learning systems requires more than measuring their performance during training.

Generalisation refers to a model’s ability to perform well on data it hasn’t encountered during training.

To evaluate this, datasets are commonly divided into training, validation, and test sets. The training set is used to fit the model. The validation set helps compare approaches and tune settings during development. The test set provides a final evaluation on data kept separate from those decisions.

One problem that can interfere with generalisation is overfitting. This occurs when a model learns patterns specific to its training data, including irrelevant details or noise, instead of learning relationships that transfer well to new examples.

Imagine a model trained to recognise cats using images that mostly show them indoors. If it relies too heavily on indoor backgrounds rather than relevant visual features, it may struggle when shown a cat outdoors.

The model hasn’t necessarily learned nothing. Instead, it has learned patterns that aren’t reliable enough for the broader task.

This also explains why adding more training data isn’t always sufficient. The data must be relevant and representative, and the model must be evaluated appropriately.

Generalisation is especially important when AI systems are used in real-world settings, where inputs can differ from the examples used during development. A model’s performance should therefore be measured against the task it is expected to perform, rather than assumed from its training results alone.

Google’s guide to datasets, generalisation, and overfitting explores these issues in more detail.

How does this apply to ChatGPT and other language models?

Large language models (LLMs) use many of these same machine learning principles, but their architecture and training objectives allow them to work with language at a much larger scale.

During pretraining, a language model learns statistical patterns from large collections of text. Many modern language models are trained to predict the next token in a sequence. A token is a unit of text that might represent a complete word, part of a word, or punctuation.

Consider the sentence:

“The Earth revolves around the…”

A model trained to predict the next token learns to assign probabilities to possible continuations. It encounters enormous numbers of text examples during training, gradually adjusting its parameters to improve its predictions.

This objective can teach a model relationships between words, grammatical structures, and patterns associated with different subjects. However, language models are not simply databases of memorised sentences. Their learned parameters encode patterns that help them generate outputs in response to new inputs, although memorisation can still occur in some circumstances.

Pretraining is also not the entire process. Depending on the system, additional training stages can use examples of desired responses and human feedback to improve instruction-following, usefulness, and other behaviours.

When a language model generates a response, it uses its trained parameters and the current input to predict and generate a sequence of tokens. This process is called inference.

But generating a plausible response is not the same as guaranteeing a correct one. Language models can produce inaccurate claims, overlook context, and express uncertainty poorly. Their outputs still require evaluation, particularly when accuracy matters.

For a more detailed explanation, OpenAI’s article on how ChatGPT and its foundation models are developed describes the training process and the role of model parameters.

From theory to practice

Understanding how AI learns gives us a foundation for exploring how these systems are built, trained, and evaluated. Data provides examples, models learn mathematical relationships, and optimisation algorithms adjust their parameters to improve predictions. Together, these processes form the basis of many machine learning systems, from simple prediction models to complex neural networks.

However, understanding the training process is only part of the picture. The quality of a model also depends on the data it learns from, the task it is designed to perform, and how well its predictions generalise to unfamiliar situations. Evaluating these factors is just as important as understanding the algorithms themselves.

The next step is to put these concepts into practice: explore a dataset, train a simple model, examine its predictions, and see how changing its parameters affects the results. Working through these experiments can turn abstract mathematical ideas into something tangible.

Because understanding how a model learns is one thing. Building one and seeing that learning process in action is where the theory starts to come alive.

References & Further Reading

0 comments

Join the conversation

Subscribe to the newsletter

Join the list! New posts and cool things I find, straight to your inbox.