No history yet

Modern Neural Architectures

The Anatomy of Modern AI

You already know that neural networks are built from layers of interconnected neurons. But modern AI, especially the large language models (LLMs) that have become so prominent, isn't just about stacking more layers. It's about specific, clever architectural choices that enable these models to learn from vast amounts of data with incredible efficiency.

The most significant of these is the Transformer architecture. Introduced in 2017, it completely changed the game by moving away from processing information sequentially, like in Recurrent Neural Networks (RNNs), to processing it all at once. This parallel processing capability is powered by a mechanism called attention, which allows the model to weigh the importance of different words in a sequence.

Lesson image

The original Transformer had two parts: an encoder to 'understand' the input sequence and a decoder to generate the output sequence. This design is great for tasks like language translation. However, different tasks benefit from different parts of this structure.

Over time, the industry has largely converged on decoder-only models for generative tasks. Why? They are simpler to train and scale, and they excel at predicting the next word in a sequence, which is the foundation of text generation. This architecture is the basis for models like OpenAI's GPT series.

Inside the Transformer Block

The magic of a Transformer lies in its building blocks, which are stacked on top of each other. Each block contains a few key components, and small tweaks to their arrangement can have a huge impact on performance. Two of the most critical adjustments in modern architectures involve normalization and activation functions.

Small architectural choices create big differences in model stability, speed, and overall capability.

One crucial choice is where to place the Layer Normalization (LN) step. Normalization helps keep the numbers flowing through the network in a stable range, preventing them from becoming too large or too small. The original Transformer used Post-LN, applying normalization after the main operations. However, this can lead to unstable training in very deep networks.

Most modern models now use Pre-LN, applying normalization before the operations. This simple change allows for much better and enables the stable training of models with hundreds of layers.

Lesson image

Another key ingredient is the activation function, which decides whether a neuron should 'fire'. While the simple ReLU function was popular for years, it has limitations. Modern architectures often use smoother, more nuanced functions like GELU (Gaussian Error Linear Unit) or SwiGLU. These functions allow for more complex relationships to be learned.

GELU(x)=xΦ(x)\text{GELU}(x) = x \cdot \Phi(x)

While GELU was a step forward, many state-of-the-art models now use variants of GLU (Gated Linear Units), such as SwiGLU. These functions introduce a 'gate' that is controlled by the network itself, allowing the model to dynamically regulate the flow of information through the neuron, often leading to better performance.

Attention is All You Need

The heart of the Transformer is its attention mechanism. This is what allows the model to look at an entire sequence and decide which parts are most important for understanding a given word. Early on, this evolved into .. Instead of calculating attention just once, the model does it multiple times in parallel, with each 'head' focusing on a different aspect of the relationships between words.

Lesson image

Within the Transformer, we see two main types of attention:

  • Self-Attention: This is used within the encoder or decoder. Each word in a sequence attends to all other words in the same sequence to build a contextual understanding. This is how a model figures out that in the phrase 'the dog chased its tail', the word 'its' refers to 'the dog'.
  • Cross-Attention: This is used in the decoder of an encoder-decoder model. Words in the output sequence being generated attend to all the words in the input sequence. This is crucial for tasks like translation, where the decoder must constantly refer back to the source sentence.

Depth vs. Width

Finally, architects must decide how to scale a model. Do you make it deeper (more layers) or wider (more neurons per layer)?

Depth allows a model to build up more complex and abstract representations. Each layer processes the output of the previous one, creating a hierarchy of features. Think of it like a manufacturing assembly line, where each station performs a progressively more complex task.

Width increases the model's capacity to memorize information and learn fine-grained patterns within a single layer of abstraction. A wider layer can capture more features from the same input simultaneously.

DimensionEffectAnalogy
Deeper (More Layers)Better at learning hierarchical, abstract features.An assembly line with more specialized stations.
Wider (More Neurons)Better at memorizing and learning diverse patterns at one level.A single workshop with more tools available.

Modern LLMs have found that scaling both is effective, but there's a strong emphasis on depth. The performance of these models often scales predictably with the number of layers and parameters, leading to the massive, deep architectures we see today.

Quiz Questions 1/6

What was the key innovation of the Transformer architecture that set it apart from previous sequential models like Recurrent Neural Networks (RNNs)?

Quiz Questions 2/6

Most modern generative LLMs, like OpenAI's GPT series, primarily use which architectural structure?