Key Takeaways
|
In Part 1, we explored how Large Language Models (LLMs) are trained to understand the building blocks of human language. We followed a sentence through the initial stages of the training pipeline:
“The cars in the retail were waiting to be sold.”
We saw how a tokenizer converts text into numerical IDs, how embedding vectors represent tokens, and how positional encoding helps the model understand the order of words. The result is a Combined Input Matrix containing both token-related and positional information. But how does the model use this information to understand the relationships between words, predict what comes next, and improve its predictions over time? This is where the Transformer architecture comes in.
In this article, we’ll continue tracing our example sentence through the remaining stages of the LLM training process, focusing on Transformer layers, self-attention, prediction, loss calculation, and backpropagation.
4. The Transformer Layers (Contextual Vectors)
The Transformer Layers look at a token in the context of all the surrounding words. Once the Combined Input Matrix is created, it passes through a series of identical Transformer Layers, often 12, 32, or 80 layers stacked on top of one another, depending on the size of the model.
Each layer’s job is to refine the meaning of every token by allowing it to interact with other tokens in the sentence. Every Transformer Layer contains two primary components:
- Self-Attention Engine
- Feed-Forward Network
Self-Attention Engine (Context Gathering)
This is where tokens figure out how they relate to one another. A word like “were” does not know its complete meaning in isolation. Its interpretation depends on the other words around it. In the sentence:
“The cars in the retail were waiting to be sold.”
The token “were” needs to establish its relationship with the other tokens, particularly its subject. The self-attention mechanism does this by allowing each token to generate three representations:
- Query: What am I looking for?
- Key: What information do I offer?
- Value: If I am relevant to you, here is my information.
For the token “were”, we can think of the process as asking the following questions:
- “What am I looking for?” (I’m a verb and plural. Where is my noun?)
- “What am I offering?” (I’m a verb sitting in Slot 5.)
- “If I am relevant to you, here is my information.”
The model compares these representations to determine how strongly tokens relate to one another. In our example, the token “cars” generates a strong match because it is a plural noun and is relevant to the verb “were”.
Before self-attention, the vector for “were” primarily contains its learned representation and its position (Slot 5). After self-attention, the vector for “were” is enriched with contextual information. It now has information about its relationship with “cars”, allowing higher layers in the model to evaluate the sentence more accurately. This is how self-attention enables an LLM to understand the relationships between words rather than treating every word independently.
Feed-Forward Network
Once self-attention allows tokens to gather context from their neighbors, each vector moves through a Feed-Forward Network (FFN). This step processes and consolidates the contextual information, helping the model develop richer representations based on patterns learned during training. For example, the contextualized “cars” vector can activate learned associations involving:
- Commercial retail
- Auto dealerships
- Inventory
- Vehicle sales
These associations help the model interpret the sentence more accurately. The Self-Attention Engine gathers contextual information, while the Feed-Forward Network further processes that information. Together, these components allow the Transformer layers to progressively refine the representations of tokens.
5. Prediction and Loss Calculation (The Training Step)
The primary training objective of an LLM is to predict the next token in a sequence. For example:
- Given [“The”], predict “cars”.
- Given [“The”, “cars”], predict “in”.
- Given [“The”, “cars”, “in”, “the”], predict “retail”.
- And so on.
The model repeatedly attempts to predict the next token based on the preceding context. Let’s examine how this works.
A. The Prediction (Guessing)
During training, the LLM behaves like a student taking a massive fill-in-the-blank test. You show the model part of a sentence:
“The cars in the ___”
The LLM generates a probability distribution predicting which token is most likely to come next. This probability distribution assigns a score to every token in the model’s vocabulary, indicating how likely it is to follow the preceding sequence.
These probabilities are not calculated using simple word counts or raw frequencies from the training data. Instead, they are driven primarily by the context of the preceding tokens and the patterns the model has learned. Because the model is still learning, its highest-scoring prediction might be completely wrong. For example, it might predict “refrigerator” instead of “retail”.
Because LLMs rely on probability-based predictions rather than fixed rules, their outputs are not always deterministic. The same input can sometimes produce different responses or decisions, particularly when an AI agent is allowed to evaluate multiple courses of action. This introduces important considerations around reliability, consistency, and control when deploying AI agents in enterprise environments, particularly when considering the risks of non-deterministic processing in autonomous AI agents.
B. The Loss Calculation (Measuring the Mistake)
During training, we already know the correct answer for the next token. In our example sentence, the correct target token is “retail”. The system evaluates the model’s prediction by looking at the probability assigned to this correct target token. Consider three possibilities:
Scenario 1: High Probability
If the model assigns a probability of 90% to “retail”, the system calculates a very low loss score. This means the model correctly identified the next token with a high degree of confidence.
Scenario 2: Moderate Probability
If the model assigns a probability of 30% to “retail”, the system calculates a medium loss score. The model is moving in the right direction, but its prediction needs improvement.
Scenario 3: Very Low Probability
If the model assigns a probability of just 0.01% to “retail” because it was confident that the next token was “refrigerator”, the system calculates a high loss score. This indicates that the model’s prediction was significantly different from the correct answer. The Loss Calculation gives the model a measurable way to understand how far its prediction was from the expected result.
C. Updating the Model (Learning from the Error)
Once the system calculates the Loss score, it works backward through the model to adjust its internal settings, called weights, to improve future predictions. These adjustments affect how the model processes information in areas such as:
Attention Weights
The model adjusts how tokens interact within a sequence. For example, it learns to connect “cars” and “sold” with commercial locations such as retail outlets and automobile dealerships rather than unrelated concepts such as kitchen appliances.
Feed-Forward Network Weights
The model also updates the learned associations stored in its Feed-Forward Networks. For example, if the model incorrectly activates associations related to kitchen appliances and predicts “refrigerator”, those weights can be adjusted to reduce the likelihood of similar mistakes in the future. At the same time, weights associated with commercial and automotive concepts can be strengthened. This process helps the model improve its ability to predict the next token based on context.
Summary: How Prediction Works
The training cycle can be summarized in three steps:
- Prediction: The model guesses the next token.
- Loss Calculation: The system measures how far the prediction was from the correct answer.
- Update: The system adjusts its internal weights to reduce the prediction error next time.
By repeating this cycle billions of times across millions of text examples, the model progressively improves its ability to predict what comes next.
6. Backpropagation (Updating the Vectors)
Backpropagation is the trial-and-error feedback loop that allows an LLM to learn from its mistakes. This is where the system works backward from the Loss score calculated in the previous step, passing through the mathematical operations and layers that processed the original input data. It calculates how much the individual weights contributed to the prediction error. For example:
- Weight A contributed significantly to the mistake.
- Weight B contributed only marginally to the mistake.
Based on these calculations, the system adjusts the relevant weights. These updates affect several parts of the model:
- Embedding Vectors: The vectors associated with tokens such as “The”, “cars”, and “retail” are updated.
- Attention Weights: The weights that determine how tokens interact with one another are adjusted.
- Feed-Forward Network Weights: The weights responsible for processing contextual information and learned associations are refined.
- Transformer Layers: The parameters throughout the Transformer architecture are updated through the backpropagation process.
After processing our single example sentence, the model’s internal parameters have shifted by a very small amount in the direction that helps it make better predictions. Repeated billions of times across massive datasets, these updates help the model develop rich mathematical representations of language, context, and relationships between concepts. This is the fundamental learning mechanism that allows an LLM to become increasingly capable of understanding and generating human language.
7. Recap: The Complete Lifecycle of a Token
Let’s bring everything together. Tracing our example sentence – “The cars in the retail were waiting to be sold.” – illustrates the end-to-end pipeline that an LLM uses during training.
- Tokenization
Raw text is divided into sub-word tokens, and each token is assigned a numerical ID from a fixed vocabulary.
- Embedding and Positioning
Each token retrieves a static semantic vector from the Embedding Table. This vector is combined with positional encoding to preserve the token’s position in the sequence.
- Transformer Layers
Through Self-Attention, tokens dynamically exchange contextual information with their neighbors. For example, “were” identifies “cars” as its plural subject. Feed-Forward Networks further process these contextualized vectors and enrich them using patterns learned during training.
- Prediction and Loss
The model predicts the next token using the context available to it. The system compares the predicted probability with the actual target token and calculates a Loss score.
- Backpropagation
The system traces the prediction error backward through the model, updating weights across embeddings, attention mechanisms, and Feed-Forward Networks to improve future predictions.
Conclusion
An LLM may appear to understand and communicate like a human, but underneath the conversational interface is a sophisticated mathematical system built around data pipelines, numerical representations, and prediction mechanisms. From tokenization and embeddings to Transformer layers, self-attention, and backpropagation, every stage plays a role in enabling the model to process language and generate meaningful responses.
For application consultants, understanding these fundamentals provides a useful foundation for working with AI-powered enterprise applications. Whether integrating AI capabilities into ERP systems, exploring AI agents, or evaluating how LLMs can support business processes, understanding what happens under the hood makes it easier to appreciate both the capabilities and limitations of these technologies.
Understanding how LLMs process information is also key to learning how they can be incorporated into more sophisticated enterprise AI architectures. For example, Salesforce Agentforce extends the capabilities of an LLM by combining reasoning, enterprise data, and actions within an iterative orchestration framework, allowing AI agents to work toward business goals rather than simply generate responses.
Frequently Asked Questions (FAQs)
- What are Transformer layers in an LLM?
Transformer layers are processing units that help LLMs understand relationships between tokens by combining self-attention and feed-forward networks. - What is self-attention in a Large Language Model?
Self-attention allows tokens to identify and exchange relevant information with other tokens in a sequence, helping the model understand context. - What is the role of a feed-forward network in an LLM?
A feed-forward network processes contextual information gathered through self-attention and strengthens the model’s learned associations. - How do LLMs predict the next token?
LLMs use the preceding tokens as context to generate a probability distribution of possible next tokens and select a prediction. - What is loss calculation in LLM training?
Loss calculation measures how far the model’s prediction is from the correct next token. A higher loss indicates a larger prediction error. - What is backpropagation in LLMs?
Backpropagation is the process of tracing prediction errors backward through the model and adjusting its internal weights to improve future predictions. - How do LLMs improve their predictions?
LLMs repeatedly predict the next token, calculate the resulting loss, and update their weights through backpropagation across large training datasets. - Why should application consultants understand Transformer architecture?
Understanding Transformer architecture helps application consultants better evaluate how LLMs process information, recognize their capabilities and limitations, and work with AI-powered enterprise applications.




