No history yet

Modern Model Architectures

The Transformer Revolution

Most modern AI models for language are built on an architecture called the Transformer. Before Transformers, models like Recurrent Neural Networks (RNNs) processed text sequentially, one word at a time, like reading a book. This created a bottleneck and made it difficult to capture long-range dependencies in text. If a sentence was long, the model might forget the beginning by the time it reached the end.

Transformers changed the game with a mechanism called self-attention. Instead of processing words one by one, self-attention allows the model to look at all the words in a sentence at the same time. It weighs the importance of every other word as it processes a single word, allowing it to build a much richer understanding of context. This parallel processing is not only more effective but also much more efficient on modern hardware like GPUs.

The Transformer architecture, introduced in the 2017 paper “Attention Is All You Need,” is the foundation of nearly all modern large language models, including GPT, Claude, LLaMA, Gemini, and Mistral.

This ability to handle data in parallel is the key. By looking at the entire input at once, the model can directly link a pronoun like "it" to the noun it refers to, even if they are far apart in the text. This was a major limitation of older, sequential architectures.

Lesson image

But for a model to process words simultaneously, the text first needs to be converted into a format it can understand. This involves two crucial steps.

  1. Tokenization: The raw text is broken down into smaller pieces called tokens. A token can be a word, part of a word, or even a single character. For example, the word "unhappily" might become three tokens: "un", "happi", and "ly".
  2. Positional Encoding: Since self-attention processes all tokens at once, it loses the original word order. To fix this, the model adds a piece of information—a vector—to each token that indicates its position in the sequence. This way, the model knows that "The cat sat on the mat" is different from "The mat sat on the cat".

Architectural Flavors

The original Transformer had two parts: an encoder and a decoder. The encoder's job is to read and understand the input sequence, creating a rich numerical representation of it. The decoder then takes that representation and generates an output sequence. This Encoder-Decoder architecture is ideal for tasks that transform an input sequence into a new output sequence, like machine translation (English to French) or text summarization.

However, not all tasks require this two-step process. Many modern models use only one half of the architecture.

Decoder-only models, like the GPT series, are built for generation. They are auto-regressive, meaning they predict the next token in a sequence based on all the previous tokens. They excel at tasks like writing essays, generating code, or acting as a chatbot. They read a prompt and simply continue the sequence.

Encoder-only models, like BERT, are designed for understanding. They look at text in both directions (left-to-right and right-to-left) to build a deep contextual understanding. This makes them great for tasks like sentiment analysis, text classification, and named entity recognition, where the goal is to analyze or label the input text, not generate new text.

ArchitecturePrimary FunctionHow it WorksExample Models
Encoder-DecoderTransformationReads an input sequence, then generates a new output sequence.T5, BART, Original Transformer
Decoder-OnlyGenerationPredicts the next token based on preceding tokens.GPT series, LLaMA, Claude
Encoder-OnlyUnderstandingBuilds a deep contextual representation of the input text.BERT, RoBERTa

Scaling Up Efficiently

As models get larger, with parameter counts in the hundreds of billions or even trillions, the computational cost of running them becomes a major challenge. Running the entire massive network for every single token would be incredibly slow and expensive. To solve this, researchers developed the Mixture-of-Experts (MoE) architecture.

Parameter

noun

A parameter in a neural network is a variable that the model learns from the training data. They are essentially the knobs the model turns to adjust its predictions. More parameters generally mean a more powerful, but also more computationally expensive, model.

In an MoE model, the standard feed-forward network layer is replaced by a set of smaller, specialized networks called "experts." A small "router" network learns which experts are best suited to process a given input token. For each token, the router selects a small number of experts (often just two) to activate, while all other experts remain dormant.

This approach allows models to have a vast number of parameters, but only a fraction of them are used for any given computation. It's like having a large team of specialists, but only calling on the specific ones you need for a particular task. This makes training and inference much more efficient without sacrificing the model's capacity.

The parallel nature of self-attention and the efficiency of MoE are what make today's massive language models possible. They are designed from the ground up to scale across thousands of GPUs, allowing them to be trained on vast datasets and achieve their remarkable capabilities.

Quiz Questions 1/6

What was a major limitation of pre-Transformer architectures like Recurrent Neural Networks (RNNs)?

Quiz Questions 2/6

The self-attention mechanism allows a Transformer to process all tokens in parallel. What problem does this create, and what is the solution?

These architectural choices—self-attention, the balance of encoders and decoders, and efficiency techniques like MoE—define the capabilities and performance of modern AI.