No history yet

LLM Architecture

The Engine of an LLM

Large Language Models might seem like magic, but they are built on a specific blueprint called the Transformer architecture. Introduced in 2017, this design revolutionized how machines process language. Unlike older models that read text word-by-word in a strict sequence, the Transformer can look at an entire sentence or paragraph at once.

This parallel processing allows it to understand the relationships between words, no matter how far apart they are. It's the difference between reading a book one word at a time versus grasping the meaning of a whole page. This architecture has two main parts: an encoder and a decoder. The encoder reads and understands the input text, and the decoder generates the response.

The encoder's job is to create a rich, numerical representation of the input's meaning. This isn't just a dictionary lookup; it's a complex understanding of context and nuance. The decoder then takes this numerical meaning and translates it back into human-readable language to form a coherent answer.

The transformer architecture is the backbone of LLMs.

Paying Attention to What Matters

The Transformer's secret weapon is the attention mechanism. This is how the model decides which words are most important for understanding the context. It allows the model to weigh the influence of different words when it's processing a sentence.

Think about how you read this sentence: "The dog, which was chasing a squirrel in the park, barked loudly." When you get to the word "barked," your brain instantly connects it to "dog," even though there are several words in between. The attention mechanism does something similar. It creates links between words and assigns scores based on their relevance to each other.

In the sentence "I went to the bank to sit by the river," the attention mechanism would help the model focus on the word "river" to correctly interpret "bank" as a riverbank, not a financial institution.

Mathematically, for each word, the model calculates a score that represents how much attention it should pay to every other word in the input. Words with higher scores have a greater influence on the final interpretation. This allows the LLM to handle complex sentences, resolve ambiguity, and keep track of pronouns and references across long passages of text.

The Context Window

An LLM can't remember an infinite amount of information. Its short-term memory is defined by its context window. This is the total amount of text, including your prompt and the model's response so far, that the model can consider at any one time.

The size of the context window is measured in tokens. A token is a piece of a word; for English, one token is roughly four characters. So, a context window of 4,000 tokens can handle a few pages of text.

token

noun

The basic unit of text that a language model processes. A token can be a word, part of a word, or a punctuation mark.

If a conversation exceeds the context window, the model starts to forget what was said at the beginning. This is why a chatbot might lose track of details from the start of a very long conversation. A larger context window allows the model to maintain more context, understand more complex instructions, and generate more consistent, relevant responses over longer interactions.

Model ExampleTypical Context Window (Tokens)
GPT-3.54,096 to 16,385
GPT-48,192 to 128,000
Llama 38,192
Gemini 1.51,000,000+

These three components—the Transformer architecture, the attention mechanism, and the context window—are the fundamental building blocks that allow LLMs to process, understand, and generate human-like text.

Quiz Questions 1/5

What is the primary advantage of the Transformer architecture compared to older, sequential models?

Quiz Questions 2/5

What is the main function of the attention mechanism in an LLM?