In this issue:
we explain what Attention is;
we go into details about the biggest transformer model ever built;
we discuss why Hugging Face is the most popular library for building and using transformer models.
💡 ML Concept of the Day: What is Attention?
Continuing our series about transformers, we would like to discuss the underpinnings of the attention mechanisms at the center of this new architecture. As described in Edge#109, attention is a mechanism used by transformer models to determine the most relevant parts of the input sequence for a given task. This mechanism contrasts with traditional recurrent neural network (RNNs) models that need to reprocess the entire input sequence in order, which has severe limitations in terms of scaling. Essentially, transformers are able to identify which parts of the input sequence they should “pay attention to.” Although attention sounds like an intuitive concept from a cognitive standpoint, it’s far from trivial to implement in the context of neural networks.
The specific attention mechanism used by transformers is called multi-headed attention, which, in turn, is based on another technique called self-attention. Conceptually, self-attention methods allow associating each word in the input with other words. To achieve this, self-attention mechanisms process the input to create three fully connected vectors known as query, key, and value. Imagine that we are executing a search for movies in a dataset. The transformer-based search engine will map the query against a set of key features such as video, year, etc., and present the best-matched movies (values). The self-attention mechanism starts by feeding the query, key, and value vectors through a linear layer that produces a scoring matrix that describes how much focus a word should put in other words.

The results of this operation are refined through different mathematical operations such as softmax to eliminate noise and find more stable attention weights.

In the transformer architecture, the self-attention mechanism is further refined by partitioning into multiple sections or heads. This is what is called multi-headed attention and improves the performance of the attention layer by focusing on different positions and different input representations.

Summarizing a complex mechanism like multi-headed attention in a few sentences is not easy but hopefully, this explanation helps you understand the underpinnings of this key layer of transformer architectures. Attention modules have become one of the most popular building blocks of modern deep learning architectures and have achieved new milestones in areas such as computer vision and natural language.
🔎 ML Research You Should Know: The Biggest Transformer Model Ever Built
In the paper Switch Transformers: Scaling to Trillion Parameter Models with Simple and Efficient Sparsity, Google Research introduced the biggest transformer model ever built with over one trillion parameters.
The objective: Optimize transformer architectures so that they can achieve new levels of scalability.
Why is it so important: Google’s Switch Transformer represents the biggest transformer architecture built to this day.
Diving deeper: Transformers are a race for building the largest model possible. OpenAI GPT-3 established new records by scaling up to 175 billion parameters. The record only lasted a few months until Google unveiled its Switch Transformer model that can scale up to 1.6 trillion parameters. Achieving that number of parameters is remarkable, but that’s not the most impressive contribution of the Switch Transformer architecture. With this new model, Google is essentially unveiling a method that maximizes the parameter count of a transformer model in a simple and computationally efficient way. Transformer models like GPT-3 are not only huge but also computationally expensive, which limits their adoption in mainstream scenarios.
The key modification of the Switch Transformer architecture is based on introducing a Mixture of Experts (MoE) routing layer that facilitates learning sparse models instead of a super large dense model. This is not as confusing as it reads, so let me try to explain. Typical transformer architectures are composed of the famous attention layer followed by a dense feed-forward network. Among other things, that dense layer is responsible for the large cost of training transformer models. Google’s Switch Transformer proposes replacing that layer with what they call a Switch FFN layer. That layer receives the input tokens and decides which smaller feed-forward network should process them. The Switch FFN layer includes three main benefits:
The router computation is very small as it only routes to a single expert.
The capacity of each expert network can remain manageable.
The router implementation is super simple.
With this optimization, Google was able to train a Switch Transformer model to an astonishing 1.6 trillion parameters! The training speed improved up to seven times compared to that of previous architectures.
Miraculously, the Switch Transformer release has managed to remain under the radar. Somehow, it reminds me of the original BERT paper that triggers the whole transformer movement. However, if the hype behind GPT-3 is any indication of what’s next to come, keep an eye for new milestones using the Switch Transformer.
🙌 Let’s connect
Follow us on Twitter. We share lots of useful information, events, educational materials, and informative threads that help you strengthen your knowledge.
🤖 ML Technology to Follow: Hugging Face is the Most Popular Library for Building and Using Transformer Models
Why should I know about this: Hugging Face Transformers has evolved into one of the most popular and advanced frameworks for Transformer architectures in deep learning applications.
What is it: Despite its popularity, building transformer architecture remains an incredible challenge given the complexity and cost of training and running those large models. Hugging Face Transformer library attempts to democratize the use of state-of-the-art Transformer models in mainstream deep learning solutions. Hugging Face Transformers have gone from being an experiment to becoming the most important transformer framework in the deep learning space in just a few months.
From a technical standpoint, Hugging Face Transformers provide implementations of hundreds of state-of-the-art transformer models for both PyTorch and TensorFlow 2.0. Architecturally, the Transformers library is structured into three main components:
Model Classes: Over 30 PyTorch models or Keras pre-trained transformer models.
Configuration Classes: Classes that store all the parameters required to build and instantiate a model.
Tokenizer Classes : Components that store the vocabulary for each model and provide methods for encoding/decoding strings in a list of token embeddings indices to be fed to a model.
The simplicity of the programming model is one of the main innovations of the Transformer library. Data scientists can start using an incredibly complex transformer model in a few lines of code. See the following example that illustrates how to use a question/answering transformer model with the Hugging Face library:

The Hugging Face Transformer library regularly incorporates new cutting-edge models and techniques that allow data scientists to build state-of-the-art solutions that leverage transformer architecture. The framework has attracted an enthusiastic community of data scientists that are actively contributing to the framework.
How can I use it: The current release of Hugging Face Transformers is open-source at https://github.com/huggingface/transformers


This explanation may be good for a manager! But if you are a developer this is just not enough. Please get into real technical stuff, we have enough theory on the planet!