Seq2seq
≈ 6 min read
Names in other languages
No names in other languages are held for this entry yet.
Article bodies are English and are not machine-translated. A name in another language is not a translation of the article.
and attention mechanism Seq2seq is a family of machine learning approaches used for natural language processing. Originally developed by Lê Viết Quốc, a Vietnamese computer scientist and a machine learning pioneer at Google Brain, this framework has become foundational in many modern AI systems. Applications include language translation, image captioning, conversational models, speech recognition, and text summarization. Seq2seq uses sequence transformation: it turns one sequence into another sequence.
and attention mechanism Seq2seq is a family of machine learning approaches used for natural language processing. Originally developed by Lê Viết Quốc, a Vietnamese computer scientist and a machine learning pioneer at Google Brain, this framework has become foundational in many modern AI systems. Applications include language translation, image captioning, conversational models, speech recognition, and text summarization. Seq2seq uses sequence transformation: it turns one sequence into another sequence. ==History== , showing the process by which a message sent becomes the message received (possibly corrupted by noise) seq2seq is an approach to machine translation (or more generally, sequence transduction) with roots in information theory, where communication is understood as an encode-transmit-decode process, and machine translation can be studied as a special case of communication. This viewpoint was elaborated, for example, in the noisy channel model of machine translation. In practice, seq2seq maps an input sequence into a real-numerical vector by using a neural network (the encoder), and then maps it back to an output sequence using another neural network (the decoder). The idea of encoder-decoder sequence transduction had been developed in the early 2010s. The papers most commonly cited as the originators that produced seq2seq are two papers from 2014. In the seq2seq as proposed by them, both the encoder and the decoder were LSTMs. This had the "bottleneck" problem, since the encoding vector has a fixed size, so for long input sequences, information would tend to be lost, as they are difficult to fit into the fixed-length encoding vector. The attention mechanism, proposed in 2014, resolved the bottleneck problem. They called their model RNNsearch, as it "emulates searching through a source sentence during decoding a translation". A problem with seq2seq models at this point was that recurrent neural networks are difficult to parallelize. The 2017 publication of Transformers resolved the problem by replacing the encoding RNN with self-attention Transformer blocks ("encoder blocks"), and the decoding RNN with cross-attention causally-masked Transformer blocks ("decoder blocks"). ===Encoder=== The encoder is responsible for processing the input sequence and capturing its essential information, which is stored as the hidden state of the network and, in a model with attention mechanism, a context vector. The context vector is the weighted sum of the input hidden states and is generated for every time instance in the output sequences. ===Decoder=== The decoder takes the context vector and hidden states from the encoder and generates the final output sequence. The decoder operates in an autoregressive manner, producing one element of the output sequence at a time. At each step, it considers the previously generated elements, the context vector, and the input sequence information to make predictions for the next element in the output sequence. Specifically, in a model with attention mechanism, the context vector and the hidden state are concatenated together to form an attention hidden vector, which is used as an input for the decoder. The seq2seq method developed in the early 2010s uses two neural networks: an encoder network converts an input sentence into numerical vectors, and a decoder network converts those vectors to sentences in the target language. The Attention mechanism was grafted onto this structure in 2014 and is shown below. Later it was refined into the encoder-decoder Transformer architecture of 2017. The decoder first processes the " " input partially, to obtain an intermediate vector h^d_0 , the 0th hidden vector of decoder. Then, the intermediate vector is transformed by a linear map W^Q into a query vector q_0 = h_0^d W^Q . Meanwhile, the hidden vectors outputted by the encoder are transformed by another linear map W^K into key vectors k_0 = h_0 W^K, k_1 = h_1 W^K, \dots . The linear maps are useful for providing the model with enough freedom to find the best way to represent the data. Now, the query and keys are compared by taking dot products: q_0 k_0^T, q_0 k_1^T, \dots . Ideally, the model should have learned to compute the keys and values, such that q_0 k_0^T is large, q_0 k_1^T is small, and the rest are very small. This can be interpreted as saying that the attention weight should be mostly applied to the 0th hidden vector of the encoder, a little to the 1st, and essentially none to the rest. In order to make a properly weighted sum, we need to transform this list of dot products into a probability distribution over 0, 1, \dots . This can be accomplished by the softmax function, thus giving us the attention weights: (w_{00}, w_{01}, \dots) = \mathrm{softmax}(q_0 k_0^T, q_0 k_1^T, \dots) This is then used to compute the context vector: c_0 = w_{00} v_0 + w_{01} v_1 + \cdots where v_0 = h_0 W^V, v_1 = h_1 W^V , \dots are the value vectors, linearly transformed by another matrix to provide the model with freedom to find the best way to represent values. Without the matrices W^Q, W^K, W^V , the model would be forced to use the same hidden vector for both key and value, which might not be appropriate, as these two tasks are not the same. This is the dot-attention mechanism. The particular version described in this section is "decoder cross-attention", as the output context vector is used by the decoder, and the input keys and values come from the encoder, but the query comes from the decoder, thus "cross-attention". More succinctly, we can write it as c_0 = \mathrm{Attention}(h_0^d W^Q, HW^K, H W^V) = \mathrm{softmax}((h_0^d W^Q) \; (H W^K)^T) (H W^V) where the matrix H is the matrix whose rows are h_0, h_1, \dots . Note that the querying vector, h_0^d , is not necessarily the same as the key-value vector h_0 . In fact, it is theoretically possible for query, key, and value vectors to all be different, though that is rarely done in practice.
Text derived from https://en.wikipedia.org/w/index.php?oldid=1358644085 under CC BY-SA 4.0; modifications have been made.