Home >Technology peripherals >AI >What is the Transformer machine learning model?
Translator | Li Rui
Reviewer | Sun Shujuan
In recent years, the Transformer machine learning model has become one of the main highlights of the advancement of deep learning and deep neural network technology. It is mainly used for advanced applications in natural language processing. Google is using it to enhance its search engine results. OpenAI used Transformer to create the famous GPT-2 and GPT-3 models.
Since its debut in 2017, the Transformer architecture has continued to evolve and expand into many different variants, extending from language tasks to other domains. They have been used for time series forecasting. They are the key innovation behind AlphaFold, DeepMind’s protein structure prediction model. OpenAI’s source code generation model Codex is also based on Transformer. Transformers have also recently entered the field of computer vision, where they are slowly replacing convolutional neural networks (CNN) in many complex tasks.
Researchers are still exploring ways to improve Transformer and use it in new applications. Here’s a quick explanation of what makes Transformers exciting and how they work.
Traditional feedforward neural networks are not designed to track sequential data and map each input to an output. It works well for tasks like image classification, but fails on sequence data like text. Machine learning models that process text must not only process each word, but also consider how words are arranged in order and related to each other. And the meaning of a word may change depending on the other words that appear before and after them in the sentence.
Before the advent of Transformer, Recurrent Neural Networks (RNN) were the preferred solution for natural language processing. When given a sequence of words, a Recurrent Neural Network (RNN) will process the first word and feed the results back to the layer that processes the next word. This enables it to track an entire sentence rather than processing each word individually.
The shortcomings of recurrent neural networks (RNN) limit their usefulness. First, they are very slow to process. Because they must process data sequentially, they cannot take advantage of parallel computing hardware and graphics processing units (GPUs) for training and inference. Second, they cannot handle long sequences of text. As the recurrent neural network (RNN) goes deeper into the text excerpt, the effect of the first few words of the sentence gradually diminishes. This problem known as "vanishing gradient" occurs when two linked words are far apart in the text. Third, they only capture the relationship between a word and the words that precede it. In fact, the meaning of words depends on the words that come before and after them.
The Long Short-Term Memory (LSTM) network is the successor of the Recurrent Neural Network (RNN), which can solve the vanishing gradient problem to a certain extent and can handle larger text sequences. But Long Short-Term Memory (LSTM) is even slower to train than Recurrent Neural Networks (RNN), and still cannot take full advantage of parallel computing. They still rely on serial processing of text sequences.
A paper published in 2017 called "Attention is All That Is Needed" introduced Transformer, stating that Transformer
made two key contributions: First, they made parallel processing of entire sequences a possible, thereby scaling the speed and capacity of sequential deep learning models to unprecedented speeds. Second, they introduce "attention mechanisms" that can track relationships between words in very long text sequences, both forward and backward.
Before discussing how the Transformer model works, it is necessary to discuss the types of problems that sequence neural networks solve.
Despite their differences, all these types of models have one thing in common - they learn expressions. The job of a neural network is to convert one type of data into another type of data. During training, the neural network's hidden layer (the layer between the input and output) adjusts its parameters in a way that best represents the characteristics of the input data type and maps them to the output. The original Transformer was designed as a sequence-to-sequence (seq2seq) model for machine translation (of course, sequence-to-sequence models are not limited to translation tasks). It consists of an encoder module that compresses the input string from the source language into a vector that represents words and their relationships to each other. The decoder module converts the encoded vector into a text string in the target language.
The input text must be processed and converted into a unified format, and then can be input to Transformer. First, the text is passed through a "tokenizer," which breaks it into chunks of characters that can be processed individually. The tokenization algorithm can depend on the application. In most cases, each word and punctuation mark roughly counts as one token. Some suffixes and prefixes count as separate tokens (for example, "ize", "ly", and "pre"). The tokenizer generates a list of numbers representing the token IDs of the input text.
The tokens are then converted into "word embeddings". Word embedding is a vector that attempts to capture the value of a word in a multi-dimensional space. For example, the words "cat" and "dog" may have similar values on some dimensions because they are both used in sentences about animals and pets. However, on other dimensions that distinguish felines from canines, "cat" is closer to "lion" than "wolf." Likewise, "Paris" and "London" are probably closer to each other because they are both cities. However, "London" is closer to "England" and "Paris" is closer to "France" because of the differentiating dimensions of a country. And word embeddings typically have hundreds of dimensions.
Word embeddings are created through embedding models that are trained separately from the Transformer. There are several pre-trained embedding models for language tasks.
contains several attention blocks and feed-forward layers to gradually capture more complex relationships.
The decoder uses the same tokenization, word embedding and attention mechanisms to process the expected results and create attention vectors. It then passes this attention vector and attention layer in the encoder module to establish a relationship between the input and output values. In a translation application, this is the part where words in the source and target language are mapped to each other. Like the encoder module, the decoder attention vectors are passed through feedforward layers. The result is then mapped to a very large pool of vectors, i.e. the size of the target data (in the case of translation, this can involve tens of thousands of words).
The above is the detailed content of What is the Transformer machine learning model?. For more information, please follow other related articles on the PHP Chinese website!