Attention Neural Networks with Sparse Attention Mechanism

By employing a sparse attention mechanism that limits attention calculations to a subset of positions, the neural network efficiently processes long sequences and operates within memory constraints, addressing the computational inefficiencies of traditional attention-based networks.

JP7670905B2Active Publication Date: 2025-04-30GOOGLE LLC
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
JP2024091358
Authority / Receiving Office
JP · JP
Patent Type
Patents
Current Assignee / Owner
Priority Date
2020-06-05
Filing Date
2024-06-05
Publication Date
2025-04-30
Estimated Expiration
2041-06-07

AI Technical Summary

Technical Problem

Existing attention-based neural networks face significant computational costs due to their quadratic dependency on sequence length, making them inefficient for processing long sequences and memory-constrained environments.

Method used

The implementation of a sparse attention mechanism in neural networks, where only a subset of positions attend to all other locations, significantly reducing the number of attention calculations while maintaining output quality.

Benefits of technology

This approach allows neural networks to efficiently process sequences with long-term dependencies, even exceeding 4000 tokens, while operating within limited memory constraints, ensuring high-quality outputs with reduced computational and memory requirements.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure 0007670905000001
    Figure 0007670905000001
  • Figure 0007670905000002
    Figure 0007670905000002
  • Figure 0007670905000003
    Figure 0007670905000003
Patent Text Reader

Abstract

To provide attention neural networks with sparse attention mechanisms.SOLUTION: Methods, systems, and apparatus, including computer programs encoded on computer storage media, for processing network inputs using an attention neural network having one or more sparse attention sub-layers, are provided. Each sparse attention sub-layer is configured to apply a sparse attention mechanism that attends differently for input positions that are in a first proper subset of the input positions in the input to the sub-layer than for positions that are not in the first proper subset.SELECTED DRAWING: Figure 2B
Need to check novelty before this filing date? Find Prior Art

Description

[Technical field]

[0001] CROSS-REFERENCE TO RELATED APPLICATIONS This application claims priority to U.S. Provisional Application No. 63 / 035,632, filed June 5, 2020, which is incorporated by reference in its entirety. [Background technology]

[0002] This specification relates to using neural networks to perform machine learning tasks on network inputs.

[0003] A neural network is a machine learning model that employs one or more layers of nonlinear units to predict an output for a received input. Some neural networks contain one or more hidden layers in addition to an output layer. The output of each hidden layer is used as the input to the next layer in the network, i.e. the next hidden layer or the output layer. Each layer of the network generates an output from the received input according to the current values ​​of its respective set of parameters. [Prior art documents] [Non-patent literature]

[0004] [Non-Patent Document 1] "Attention Is All You Need" by Vaswani et al., arXiv:1706.03762 [Non-Patent Document 2] Raffel et al., "Exploring the Limits of Transfer Learning with a Unified Text-to-Text Transformer," arXiv:1910.10683 [Non-Patent Document 3] Devlin et al., "BERT: Pre-training of Deep Bidirectional Transformers for Language Understanding," arXiv:1810.04805 [Non-Patent Document 4] Dai et al., "Transformer-XL: Attentive Language Models Beyond a Fixed-Length Context," arXiv:1901.02860 [Non-Patent Document 5] "Reformer: The Efficient Transformer" by Kitaev et al., arXiv:2001.04451 Summary of the Invention [Means for solving the problem]

[0005] This specification describes a system implemented as a computer program on one or more computers at one or more locations that performs machine learning tasks on network inputs using an attention neural network that includes an attention sub-layer that applies sparse attention.

[0006] Particular embodiments of the subject matter described in this specification can be implemented to realize one or more of the following advantages.

[0007] The techniques described herein enable neural network systems to process input sequences, generate output sequences, or both, more efficiently than existing attention-based networks, both during training and at run-time, i.e., in terms of computational resources (e.g., memory, computing power, or both), by utilizing a sparse attention mechanism.

[0008] The attention layer in some existing attention neural networks employs a dot-product attention mechanism that involves, for each given query, computing the respective dot product of the query with all the keys. Typically, the network derives such keys or queries from potentially consecutive network inputs. Thus, applying the dot-product attention mechanism to sequential data of significant length can be computationally expensive. In particular, conventional self-attention layers have a quadratic dependence on the length of the sequence, so that when operating or generating longer sequences, the model consumes a large amount of computational resources. However, the described technique addresses these issues by applying a sparse attention mechanism to effectively limit the number of attention calculations performed in each attention layer while maintaining output quality comparable to conventional self-attention neural networks. In particular, by having a majority of positions attend only a sparse subset of other positions, and a much smaller subset of positions (size O(1) compared to the sequence length) attend all positions (and are attended by all positions), the system can effectively propagate the long context of the sequence and ensure high quality output while maintaining computational efficiency even for very long sequences. As a specific example, using the aforementioned sparse attention, an attention neural network can perform effectively on tasks that require operating on sequences with long-term dependencies exceeding 4000 or more tokens, even though there may be fewer than 100 global tokens attending the entire sequence. Thus, a first proper subset of positions containing global tokens may contain no more than 3 / 100th the number of tokens as a second proper subset containing other tokens.

[0009] More specifically, the described techniques allow the self-attention neural network to be deployed under memory constraints, i.e., within a more limited memory space compared to the memory space required if the described techniques are not employed. As a particular example, modern hardware chips that perform the multiplications required for the self-attention mechanism have limited on-chip memory. As another example, edge computing devices such as mobile phones have limited on-device memory. By sparsifying the self-attention mechanism, the described techniques allow the attention neural network to generate high quality output while operating within this constrained memory space, i.e., when the attention neural network is deployed, and thus the attention mechanism is applied by one or more devices with limited device memory. In particular, by using a query at a given input location to attend all keys in a sequence of keys only for input locations in a first suitable subset of input locations, while using an input location query to attend only keys in the corresponding suitable subset of input locations for input locations in a second suitable subset of input locations, the described technique significantly reduces the number of keys that need to be loaded into the constrained memory space to compute attended inputs for the second subset of input locations. This allows the aforementioned self-attention mechanism to be effectively performed within the constrained memory space. However, because location queries are still used to attend all keys at all input locations for locations in the first suitable subset, and location queries are still used to attend all keys at all locations in the first subset for input locations in the second suitable subset, the system can still propagate information to all input locations and ensure high quality output.Furthermore, if the suitable subset corresponding to any given position in the second subset includes (i) one or more input positions randomly selected from input positions outside the first suitable subset, and (ii) each input position that is within a window of a fixed number of positions of the input positions in the second suitable subset, the system can generate high quality output even when the number of positions in the corresponding suitable subset is small compared to the total number of positions in the second subset, further reducing the number of keys that need to be loaded into memory to apply the attention mechanism to positions in the second subset. Moreover, because there are typically many more positions in the second subset than in the first subset, the number of keys that need to be loaded into memory to apply the self-attention mechanism to the entire layer input is significantly reduced overall, while at the same time ensuring that the self-attention mechanism generates high quality output.

[0010] The details of one or more embodiments of the subject matter herein are set forth in the accompanying drawings and the description below. Other features, aspects, and advantages of the subject matter will become apparent from the description, drawings, and claims. [Brief description of the drawings]

[0011] [Figure 1] FIG. 1 illustrates an example of a neural network system. [Figure 2A] FIG. 1 is a diagram of the sparse attention mechanism being applied. [Figure 2B] FIG. 1 illustrates a sparse attention scheme where queries and keys are split into blocks. [Diagram 3] 1 is a flow diagram of an example process for applying a sparse attention mechanism. DETAILED DESCRIPTION OF THE PREFERRED EMBODIMENTS

[0012] Like reference numbers and designations in the various drawings indicate like elements.

[0013] This specification describes a system implemented as a computer program on one or more computers at one or more locations that performs a machine learning task on a network input to generate a network output for the machine learning task.

[0014] The machine learning task may be any machine learning task that (i) operates on a network input, which is a sequence of inputs; (ii) produces a network output, which is a sequence of outputs; or (iii) does both.

[0015] Here are some examples of machine learning tasks that the system can be configured to perform:

[0016] As an example, the task may be a neural machine translation task. For example, if the input to the neural network is a sequence of text, e.g., a sequence of words, phrases, characters, or word fragments in one language, the output generated by the neural network may be a translation of the sequence of text into another language, i.e., a sequence of text in the other language that is a translation of the input sequence of text. As a particular example, the task may be a multilingual machine translation task in which a single neural network is configured to translate between multiple different source and target language pairs. In this example, the source language text may be augmented with an identifier indicating the target language into which the neural network should translate the source language text.

[0017] As another example, the task may be a speech processing task. For example, if the input to a neural network is a sequence representing an utterance, the output generated by the neural network may be a score for each of a set of fragments of text, each score representing an estimated likelihood that the fragment of text is a correct transcript of the utterance. As another example, if the input to a neural network is a sequence representing an utterance, the output generated by the neural network may indicate whether a particular word or phrase (a "hotword") was spoken in the utterance. As another example, if the input to a neural network is a sequence representing an utterance, the output generated by the neural network may identify the natural language in which the utterance was spoken.

[0018] As another example, the task may be a natural language processing or understanding task that operates on a sequence of text in some natural language, such as an entailment task, a paraphrase task, a text similarity task, a sentiment task, a sentence completion task, a grammar task, etc.

[0019] As another example, the task may be a text-to-speech task, where the input is natural language text or features of natural language text, and the network output is a spectrogram, waveform, or other data defining the audio of the text spoken in the natural language.

[0020] As another example, the task may be a health prediction task, where the input is a sequence derived from a patient's electronic health record data and the output is a prediction related to the patient's future health, such as a predicted treatment to be prescribed for the patient, the likelihood that the patient will experience an adverse health event, or a predicted diagnosis for the patient.

[0021] As another example, the task may be a text generation task where the input is a sequence of text and the output is another sequence of text, e.g., a completion of the input sequence of text, a response to a question posed in the input sequence, or a sequence of text on a topic specified by the first sequence of text. As another example, the input to a text generation task may be a non-textual input, e.g., an image, and the output sequence may be text that describes the input.

[0022] As another example, the task may be an image generation task where the input is a conditioning input and the output is a sequence of intensity values ​​input for pixels of an image.

[0023] As another example, the task may be an agent control task, where the inputs are sequences of observations or other data that characterize the state of the environment, and the outputs define actions to be taken by an agent in response to the most recent data in the sequence. The agent may be, for example, a real-world or simulated robot, a control system for an industrial facility, or a control system that controls different kinds of agents.

[0024] As another example, the task may be a genomics task, where the input is a sequence representing a fragment of a DNA sequence or other molecular sequence, and the output is either an embedding of the fragment for use in a downstream task, for example by utilizing unsupervised learning techniques on a dataset of DNA sequence fragments, or the output of a downstream task. Examples of downstream tasks include promoter site prediction, methylation analysis, predicting the functional impact of non-coding variants, etc.

[0025] In some cases, the machine learning task is a combination of multiple individual machine learning tasks, i.e., the system is configured to perform multiple different individual machine learning tasks, e.g., two or more of the machine learning tasks listed above. For example, the system can be configured to perform multiple individual natural language understanding tasks using a network input that includes identifiers of the individual natural language understanding tasks to be performed on the network input.

[0026] To perform a machine learning task, the system includes an attention neural network that includes multiple attention layers, each layer operating on a respective input sequence that includes a respective layer input at each of one or more locations.

[0027] Additionally, each of the layers includes an attention sub-layer and, optionally, a position-wise feedforward sub-layer that receives the layer's input sequence and applies an attention mechanism to the layer's input sequence to generate an attended input sequence.

[0028] The attention mechanism applied by the attention sub-layers depends on the configuration of the attention neural network, as described in more detail below, however, at least one of the attention sub-layers applies an attention mechanism that uses sparse attention, as described below.

[0029] If included, the feedforward sublayer operates on the attended input sequence to generate an output sequence for the layer.

[0030] If a feedforward sublayer is not included, the attended input sequence is the output sequence of the layer.

[0031] In general, the layers in an attention neural network can be arranged in any of a variety of configurations.

[0032] As an example, when the network input is an input sequence, the attention neural network includes an encoder neural network that includes a subset of the layers and encodes the input sequence to generate a respective encoded representation of each input in the sequence. In this example, the attention mechanism applied by the layers of the encoder is a self-attention mechanism. In this example, some or all of the layers of the encoder may apply a sparse attention mechanism, as described below.

[0033] As another example, an attention neural network includes a decoder neural network that includes different subsets of layers and processes either the network input or an encoded representation of the network input to generate a network output. In some of these examples, when the network output is an output sequence, the decoder neural network operates autoregressively, and attention sublayers in layers in some or all of the decoder apply masked self-attention to the partially generated output sequence. When the neural network includes both an encoder and a decoder, some of the layers in the decoder apply cross-attention to the encoded representation, and other layers apply self-attention to the output sequence, whether masked or not.

[0034] If the attention neural network includes a decoder neural network that operates directly on the input sequence, then the attention layers in the decoder can apply a self-attention mechanism to the input sequence. In this example, some or all of the layers of the decoder can apply a sparse attention mechanism, as described below.

[0035] Details of the operation of attention layers within the decoder neural network and encoder neural network are described in more detail in Vaswani et al., "Attention Is All You Need," arXiv:1706.03762, and Raffel et al., "Exploring the Limits of Transfer Learning with a Unified Text-to-Text Transformer," arXiv:1910.10683, and Devlin et al., "BERT: Pre-training of Deep Bidirectional Transformers for Language Understanding," arXiv:1810.04805, the entire contents of which are incorporated herein by reference in their entireties.

[0036] 1 illustrates an example of a neural network system 100. Neural network system 100 is an example of a system implemented as a computer program on one or more computers at one or more locations, in which the systems, components, and techniques described below may be implemented.

[0037] The neural network system 100 can receive an input 102 and perform a machine learning task on the input 102 to generate an output 152 .

[0038] As described above, the neural network system 100 may perform any of a variety of tasks, including (i) operating on an input sequence, the input 102, (ii) generating an output sequence, the output 152, or (iii) both.

[0039] The neural network system 100 includes an attention neural network 150 that includes multiple attention layers, at least one of which is a sparse attention layer 110.

[0040] Each attention layer operates on an input sequence 104 and produces a corresponding output sequence 134.

[0041] Although only one attention layer is shown in FIG. 1 for convenience, as discussed above, the attention neural network 150 typically includes many other layers, including other attention layers, e.g., an embedding layer and an output layer.

[0042] Specifically, input sequence 104 has a respective input at each of a number of positions in the input order, and output sequence 134 has a respective output at each of one or more positions, i.e., input sequence 104 has one or more inputs arranged according to an input order, and output sequence 134 has one or more outputs arranged according to an output order.

[0043] In general, the input sequence 104 may be any intermediate sequential data generated by the attention neural network 150 when performing a machine learning task on the input 102.

[0044] For example, if the attention layer 110 is the first attention layer in a neural network, the input sequence 104 may be an embedded (i.e., numerical) representation of the system input 102 generated by an embedding layer.

[0045] As another example, the input sequence 104 may be an output sequence generated by a previous attention layer or other layer in the attention neural network 150.

[0046] To generate an output sequence 134 from the input sequence 104, the sparse attention layer 110 includes one or more attention sub-layers 120 (also called "attention heads") and, optionally, one or more position-wise feedforward sub-layers 130.

[0047] The one or more attention sub-layers 120 collectively generate a final attended input sequence 124 from the input sequence 104 that includes each final attended input at each of the input positions.

[0048] Each attention sub-layer 120 receives the input sequence 104 of a layer 110 and applies an attention mechanism to the input sequence of the layer to generate a respective attended input sequence.

[0049] For at least some of the attention layers in the neural network, each sub-layer 120 applies a sparse attention mechanism, i.e., instead of using traditional attention.

[0050] A sparse attention mechanism may be a single-head attention mechanism, where the attention layer includes only a single head, i.e., a single sub-layer 120, applying a single sparse attention mechanism to the input sequence, or a multi-head attention mechanism, where the attention layer includes multiple heads, i.e., multiple attention sub-layers 120, each of the multiple attention heads applying a respective sparse attention mechanism in parallel to the input sequence to generate a respective attended input sequence.

[0051] The attention layer then combines the outputs of multiple attention heads, for example by concatenating the outputs, summing the outputs, or averaging the outputs, and optionally processes the concatenated outputs through a linear layer as part of generating the final attended input sequence 124 of the attention layer 110.

[0052] The application of the sparse attention mechanism is described in more detail below with reference to FIG. 2.

[0053] As mentioned above, neural networks generally contain multiple attention layers, where all of the attention layers can apply sparse attention, some of the attention layers can apply sparse attention, and other attention layers can apply traditional multi-head or single-head attention. In general, the attention layer that applies sparse attention can be applied to any attention neural network architecture, e.g., "Attention Is All You Need" by Vaswani et al., arXiv:1706.03762, "Exploring the Limits of Transfer Learning with a Unified Text-to-Text Transformer" by Raffel et al., arXiv:1910.10683, "BERT: Pre-training of Deep Bidirectional Transformers for Language Understanding" by Devlin et al., arXiv:1810.04805, "Transformer-XL: Attentive Language Models Beyond a Fixed-Length Context" by Dai et al., arXiv:1901.02860, and "Reformer: The Efficient

[0036] The present invention can be inserted in place of a traditional attention layer to implement self-attention in any of the neural networks described in "The Self-Attention in neural networks for the Transformer," arXiv:2001.04451, the entire contents of which are incorporated herein by reference in their entirety.

[0054] A self-attention mechanism is an attention mechanism in which the queries, keys, and values ​​used by the mechanism are all generated from the input sequence to the attention sub-layer, i.e., the set of memory vectors is the same as the input sequence to the layer.

[0055] In some cases, the combined attended input sequence generated from the attended input sequence is the final output of the attention mechanism, i.e., the final attended input sequence 124. In some other cases, the attention layer applies one or more other operations, such as residual connections, layer normalization, or both, to the combined attended input sequence to generate sequence 124.

[0056] If included, one or more feedforward sublayers 130 then operate on the final attended input sequence 124 to generate an output sequence 134 of layer 110 by applying a series of operations in parallel to each attended input of the final attended input sequence, e.g., by processing each attended input through a fully connected neural network and then optionally applying layer normalization, residual connections, or both to the output of the fully connected neural network. As a particular example, the fully connected neural network may apply one linear transformation in parallel to each attended input, followed by an activation function, e.g., a nonlinear element-wise activation function such as a ReLU activation function, followed by another linear transformation.

[0057] If the feedforward sublayer 130 is not included, the final attended input sequence 124 is the output sequence 134 of the layer.

[0058] In general, the layers within the attention neural network can be arranged in any of a variety of configurations, and the attention mechanism applied by the attention sub-layer 120 depends on the configuration of the attention neural network 150.

[0059] As an example, if the network input is an input sequence and the attention neural network 150 includes an encoder neural network that includes a subset of multiple layers and encodes the input sequence to generate a respective encoded representation of each input in the sequence, the attention sublayer 120 may be included in one of the layers of the encoder.

[0060] As another example, if the network input is an input sequence and the attention neural network 150 includes a decoder neural network that includes a subset of multiple layers and processes the network input to generate a network output, the attention sublayer 120 may be included in one of the layers of the decoder.

[0061] As used herein, the term “learned” means that an action or value has been adjusted during training of the attention neural network 150 .

[0062] FIG. 2A is a diagram 200 of a sparse attention mechanism being applied to an input sequence. As mentioned above, the sparse attention mechanism can be applied by one of multiple attention heads of an attention sub-layer or by an attention sub-layer with a single attention head. For clarity, in the example of FIG. 2A, the sparse attention mechanism is described as being performed by an attention sub-layer, which can correspond to either a single attention head of the sparse attention layer or one of multiple attention heads of the sparse attention layer.

[0063] To apply the attention mechanism, the attention sub-layer takes (i) a sequence of queries derived from the input sequence to the sparse attention layer, (ii) a sequence of keys derived from the input sequence to the sparse attention layer, and (iii) a sequence of value inputs derived from the input sequence to the sparse attention layer.

[0064] For example, a sub-layer may generate queries, keys, and values ​​by applying various learned linear transformations to an input sequence.

[0065] In other words, a sub-layer may apply a respective query linear transformation to the input sequence to generate a sequence of queries for the sub-layer, a respective key linear transformation to the input sequence to generate a sequence of keys for the sparse attention sub-layer, and a value linear transformation to the input sequence to generate a sequence of value inputs for the sparse attention sub-layer. Each linear transformation may include multiplying each input in the sequence with a corresponding learned weight matrix and, optionally, adding a corresponding learned bias.

[0066] In the example of FIG. 2A, the input sequence includes 12 input positions, queries for the input positions are represented on the y-axis 210, and keys for the 12 input positions are represented on the x-axis 220.

[0067] The sub-layer then generates an attended input sequence that includes a respective attended input at each of the multiple input locations.

[0068] In particular, the sub-layer identifies a first suitable subset of input positions. In the example of FIG. 2A, the first suitable subset includes the first two of the 12 input positions. For each input position in the first suitable subset, the sub-layer first uses a query at the input position to attend all keys in the sequence of keys to generate respective weights for all input positions, and then generates attended inputs at the input position by calculating a weighted sum of value inputs at all input positions according to their respective weights. That is, the weight of a given value input in the weighted sum is equal to the weight of the input position corresponding to the given value input.

[0069] More specifically, the weight for a given input position in the first subset may be equal to the output of a scoring function, e.g., a softmax or hardmax function, applied to the matrix product of (i) the query for the given input position and (ii) the keys for all input positions in the input sequence. Optionally, the system may apply a scaling factor to the product before computing the scoring function.

[0070] Thus, the attended input for each input position in the first proper subset depends on the input position query and the keys and values ​​of all input positions in the sequence, including all positions outside the first proper subset.

[0071] The sub-layer also identifies a second proper subset of the input locations, and for each input location in the proper subset, identifies a corresponding proper subset of the input locations. In particular, the sub-layer can identify locations that are not in the first proper subset as the second proper subset, i.e., divide the input locations into a first and a second proper subset. Thus, in the example of FIG. 2A, the locations in the second proper subset are the remaining 10 locations that are not in the first proper subset.

[0072] The corresponding proper subset of any given input location in the second subset includes the first proper subset of input locations and one or more input locations prior to the input location that are outside the first proper subset of input locations.

[0073] For each input location in the second proper subset, the sub-layer generates attended inputs at the input location by calculating a weighted sum of value inputs in the corresponding proper subset of input locations according to their respective weights for the corresponding proper subset of input locations using the query at the input location to generate respective weights for each of the input locations in the corresponding proper subset to attend only the keys in the corresponding proper subset of input locations, i.e., the weight of a given value input in the weighted sum is equal to the weight of the input location corresponding to the given value input.

[0074] More specifically, the weight for a given input location in the second subset may be equal to the output of a scoring function, e.g., a softmax or hardmax function, applied to the matrix product of (i) the query for the given input location and (ii) the keys of the corresponding appropriate subset of input locations. Optionally, the system may apply a scaling factor to the product before computing the scoring function.

[0075] More specifically, for each particular position in the second suitable subset, the one or more input positions outside the first suitable subset include one or more input positions randomly selected from the input positions outside the first suitable subset.

[0076] In some cases, for each particular position in the second suitable subset, the one or more input positions outside the first suitable subset include each input position that is within a window of a fixed number of positions of the particular input position in the second suitable subset.

[0077] Thus, a query of positions in the second subset will attend much fewer keys of positions in the input sequence than will all keys of positions in the input sequence. In particular, because a query of a given input position only attends keys of positions in the first subset and a small number of keys of positions in the second subset, there are many positions in the second subset that a query of a given input position does not attend.

[0078] This attention scheme is illustrated in Figure 2A.

[0079] In FIG. 2A , a blank cell 221 indicates that no attention occurs between the corresponding query and key, a global cell 226 indicates “global attention” that includes one of the locations in the first subset, a random cell 222 indicates “random attention” between a query for a location in the second subset and a randomly selected set of keys for other locations in the second subset, and a windowed cell 224 indicates “windowed attention” between a query for a location in the second subset and each of the sets of keys for locations that fall within the window of locations.

[0080] More specifically, as shown in Fig. 2A, the first suitable subset includes the first two input positions in the sequence, and the second suitable subset includes the remaining 10 input positions in the sequence. For each position in the second subset, the location query attends two randomly selected keys and all keys at that position that are within a window of size 3 at the position.

[0081] The system may select one or more "global locations", ie, one or more locations in the first subset, in any of a variety of ways.

[0082] As an example, if the network input is a sequence having a respective token at each of a number of input positions, the attention neural network may augment the network input before processing it, e.g., by adding one or more predetermined global tokens to the beginning of the network input, and the first suitable subset of input positions may correspond to the positions to which the one or more global tokens are added.

[0083] As another example, if the network input is a sequence having a respective token at each of a number of input positions, the attention neural network is configured to designate a fixed number of the input positions, e.g., a fixed number of initial or final positions in the input sequence, or a fixed number of initial positions and a fixed number of final positions, as a first suitable subset of the input positions, i.e., without augmenting the network input with any additional tokens.

[0084] If a given sparse attention layer has multiple sub-layers ("attention heads"), the sparse attention layer can combine the attended input sequences generated by each of the sub-layers as described above to generate a final attended input sequence.

[0085] Furthermore, the described attention scheme is designed to be optimized for execution on hardware accelerators, such as graphic processing units (GPUs) and tensor processing units (TPUs) that perform matrix multiplication in hardware. In particular, as described above, the described attention has advantages over traditional attention mechanisms because only a small subset of positions attends all positions in a sequence, while the remaining subset of positions only attends a sparse subset of positions.

[0086] By appropriately selecting which locations are in the first location subset and which locations are in the corresponding subset for each location in the second location subset, for example, in using coalescing memory operations that load a block of contiguous bytes at a time, the described techniques can leverage additional benefits resulting from GPUs and TPUs that are designed to provide additional computational advantages in terms of latency and throughput.

[0087] FIG. 2B is a diagram 250 illustrating a sparse attention scheme in which the input query and keys are divided into blocks.

[0088] In particular, in the example shown in Figure 2B, there are also 12 input positions, with queries displayed on the y-axis 210 and keys displayed on the x-axis 220, but in this example the queries are divided into fixed-size query blocks and the keys are divided into fixed-size blocks. In the example of Figure 2, the fixed size is equal to 2.

[0089] The determination of which locations are in the first suitable subset and which locations are in the suitable subset corresponding to each location in the second suitable subset then takes into account the query block and key block assignments.

[0090] For global attention, the system selects positions corresponding to one or more of the query block or key block as positions to be included in the first proper subset. In the example in FIG. 2B, the system selects the input position corresponding to the first query block as a position in the first proper subset.

[0091] For random attention, for each query block, the system randomly selects a key block, and then includes the positions corresponding to the selected key block in the corresponding subset of input positions in the query block. In the example in Figure 2B, the system randomly selected one key block for each query block.

[0092] Similarly, for windowed attention, for each query block j, the proper subset corresponding to each position in query block j includes input positions corresponding to key blocks j-(w-1) / 2 to j+(w+1) / 2, where w is a positive constant that defines the size of the window of positions in query block j. In the example in FIG. 2B, w is equal to 1.

[0093] As in Figure 2A, a blank cell 221 indicates that no attention occurs between the corresponding query and key, a global cell 226 indicates "global attention" involving one of the locations in the first subset, a random cell 222 indicates "random attention" between a query for a location in the second subset and a randomly selected set of keys for other locations in the second subset, and a windowed cell 224 indicates "windowed attention" between a query for a location in the second subset and each of the sets of keys for locations that fall within the window of locations. However, as can be seen in Figure 2B, the blank cell, global cell, and windowed cell are the same for each query in a given query block.

[0094] By selecting the keys used in computing attention for each query by splitting the queries and keys into blocks, the system can enable a hardware accelerator, e.g., a GPU or TPU, to utilize coupled memory operations (loading a block of contiguous bytes at a time) in loading the queries and keys to perform the multiplications required to generate the weights for each query position in hardware, which when deployed across one or more hardware accelerators, can ensure reduced latency in performing inference using attention neural networks.

[0095] Further, for ease of presentation, only 12 positions are shown in Figures 2A and 2B, but in general, the input sequence to the sublayer may have many more input positions, and the number of positions in the first suitable subset may be significantly less than the total number of positions in the input sequence. As a specific example, the input sequence may have 4000 or more positions, but the first subset that attends the entire sequence may have 100 to 500 positions. Thus, the first suitable subset of positions that includes global tokens may contain 15 / 100 or less number of tokens than the second suitable subset that includes other tokens.

[0096] Furthermore, the size of the subset corresponding to each input position in the second subset may be significantly smaller than the total size of the second subset, making attention to positions in the second subset very sparse. In the above example, if the input sequence has 4000 or more positions and the second subset contains positions 3500 to 3900, the subset corresponding to each position in the second subset may only have about 300 positions, so that queries for each position in the second subset will attend to no more than 10 / 100th of the keys of the positions in the second subset.

[0097] 3 is a flow diagram of an example process 300 for applying a sparse attention mechanism. For convenience, the process 300 is described as being performed by one or more computer systems located at one or more locations. For example, a neural network system, such as the neural network system 100 of FIG. 1, suitably programmed in accordance with this specification, may perform the process 300.

[0098] Process 300 may be performed by each sub-layer of the sparse attention layer to generate attended input sequences for each of the sub-layers.

[0099] The system receives (step 302) (i) a sequence of queries derived from an input sequence to the sparse attention layer, the sequence of queries having a respective query at each of a plurality of input positions, (ii) a sequence of keys derived from the input sequence to the sparse attention layer, the sequence of keys having a respective key at each of a plurality of input positions, and (iii) a sequence of value inputs derived from the input sequence to the sparse attention layer, the sequence of value inputs having a respective value input at each of a plurality of input positions.

[0100] The system then generates an attended input sequence having a respective attended input at each of the multiple input locations (step 304).

[0101] In particular, for each input location in the first suitable subset of input locations, the system generates an attended input at that location by attending all locations in the input sequence (step 306). More specifically, for a given input location in the first suitable subset, the system generates an attended input at the given input location by first using a query at the input location to attend all keys in the sequence of keys to generate respective weights for all input locations, and then calculating a weighted sum of value inputs at all input locations according to their respective weights.

[0102] For each input position in the second proper subset of input positions, the system generates inputs attended to the input position by attending a proper subset of the input positions in the input sequence, i.e., a subset that is significantly less than all of them (step 308).

[0103] More specifically, for a given input location in the second suitable subset, the system generates an attended input at the given input location by first using a query at the input location to attend only the keys in the corresponding suitable subset of input locations to generate respective weights for each of the input locations in the corresponding suitable subset, and then calculating a weighted sum of the value inputs in the corresponding suitable subset of input locations according to the respective weights for the corresponding suitable subset of input locations.

[0104] As described above, the corresponding suitable subset of input locations for each input location in the second suitable subset includes the first suitable subset of input locations and one or more input locations outside the first suitable subset of input locations.

[0105] During processing of a given network input, for each sparse attention layer in the attention neural network, the system can perform process 300 to update the input sequence to the layer. By repeatedly performing this process for all attention layers in the attention neural network and then processing at least a portion of the output sequence generated by the last attention layer in the attention neural network using one or more output layers, e.g., one or more linear layers optionally followed by a softmax layer, or more generally, a multi-layer perceptron (MLP), the system can generate a network output for the received network input.

[0106] That is, process 300 can be performed as part of predicting a desired output, ie, an output for an input where the output that should be produced by the system for a sequence of inputs is not known.

[0107] Process 300 may also be performed as part of processing inputs derived from a set of training data, i.e., inputs derived from a set of inputs for which the outputs to be generated by the system are known, to train an attention neural network to determine training values ​​for the parameters of the attention neural network. The system may repeatedly perform process 300 on inputs selected from a set of training data as part of a conventional machine learning training technique, e.g., gradient descent using a conventional optimizer, e.g., stochastic gradient descent, RMSprop, or backpropagation training technique using an Adam optimizer, to optimize an objective function appropriate for the task the attention neural network is configured to perform, to train the attention and output layers of the neural network. During training, the system may incorporate any number of techniques to improve the speed, effectiveness, or both of the training process. For example, the system may use dropout, label smoothing, or both to reduce overfitting. As another example, the system may perform training using a distributed architecture that trains multiple instances of the attention neural network in parallel. Additionally, the system can first pre-train a neural network on a large unsupervised dataset through unsupervised learning to, for example, minimize the BERT loss or other unsupervised loss, and then fine-tune the neural network on task-specific training data to optimize an objective function for the task.

[0108] The term "configured" is used herein in connection with systems and computer program components. A system of one or more computers configured to perform a particular operation or action means that the system has installed thereon software, firmware, hardware, or a combination thereof that, when in operation, causes the system to perform the operation or action. A computer program or programs configured to perform a particular operation or action means that the program or programs contain instructions that, when executed by a data processing device, cause the device to perform the operation or action.

[0109] Embodiments of the subject matter and functional operations described herein can be implemented in digital electronic circuitry, tangibly embodied computer software or firmware, computer hardware including the structures disclosed herein and their structural equivalents, or a combination of one or more of them. Embodiments of the subject matter described herein can be implemented as one or more computer programs, i.e., one or more modules of computer program instructions encoded on a tangible, non-transitory storage medium for execution by or to control the operation of a data processing apparatus. The computer storage medium can be a machine-readable storage device, a machine-readable storage substrate, a random or serial access memory device, or a combination of one or more of them. Alternatively or additionally, the program instructions can be encoded on an artificially generated propagated signal, e.g., a machine-generated electrical, optical, or electromagnetic signal, that is generated to encode information for transmission to a suitable receiver device for execution by a data processing apparatus.

[0110] The term "data processing apparatus" refers to data processing hardware and encompasses any kind of apparatus, device, and machine for processing data, including, by way of example, a programmable processor, a computer, or multiple processors or computers. An apparatus may also be or even include special purpose logic circuitry, such as, for example, an FPGA (field programmable gate array) or an ASIC (application specific integrated circuit). In addition to hardware, an apparatus may optionally include code that creates an environment for the execution of a computer program, such as code constituting a processor firmware, a protocol stack, a database management system, an operating system, or one or more combinations thereof.

[0111] A computer program, sometimes referred to or described as a program, software, software application, app, module, software module, script, or code, can be written in any form of programming language, including compiled or interpreted languages, or declarative or procedural languages, and can be deployed in any form, such as a standalone program or as a module, component, subroutine, or other unit suitable for use in a computing environment. A program may correspond to a file in a file system, but this is not necessarily the case. A program can be stored as part of a file that holds other programs or data, for example one or more scripts stored in a markup language document, a single file dedicated to the program in question, or in multiple coordinated files, for example files that store one or more modules, subprograms, or portions of code. A computer program can be deployed to be executed on one computer, or on multiple computers that are located at one site or distributed across multiple sites and interconnected by a data communications network.

[0112] As used herein, the term "database" is used broadly to refer to any collection of data, which need not be structured in any particular way, or even at all, and which may be stored on storage devices in one or more locations. Thus, for example, an index database may contain multiple collections of data, each of which may be organized and accessed in different ways.

[0113] Similarly, the term "engine" is used broadly herein to refer to a software-based system, subsystem, or process programmed to perform one or more specific functions. Typically, an engine is implemented as one or more software modules or components and installed on one or more computers in one or more locations. In some cases, one or more computers will be dedicated to a particular engine, and in other cases, multiple engines may be installed and run on the same computer.

[0114] The processes and logic flows described herein may be performed by one or more programmable computers executing one or more computer programs to perform functions by operating on input data and generating output. The processes and logic flows may also be performed by special purpose logic circuitry, such as, for example, an FPGA or ASIC, or by a combination of special purpose logic circuitry and one or more programmed computers.

[0115] A computer suitable for executing a computer program may be based on a general-purpose or special-purpose microprocessor, or both, or any other type of central processing unit. In general, the central processing unit receives instructions and data from a read-only memory or a random access memory, or both. The essential elements of a computer are a central processing unit for executing instructions and one or more memory devices for storing instructions and data. The central processing unit and memory may be supplemented by, or incorporated in, special-purpose logic circuitry. In general, the computer also includes, or is operatively coupled to receive data from, or transfer data to, one or more mass storage devices, e.g., magnetic, magneto-optical, or optical disks, for storing data. However, a computer need not be equipped with such devices. Furthermore, the computer may be embedded in another device, such as, for example, a mobile phone, a personal digital assistant (PDA), a mobile audio or video player, a game console, a global positioning system (GPS) receiver, or a portable storage device, e.g., a universal serial bus (USB) flash drive, to name just a few.

[0116] Computer readable media suitable for storing computer program instructions and data include all forms of non-volatile memory, media, and memory devices including, for example, semiconductor memory devices, e.g., EPROM, EEPROM, and flash memory devices, magnetic disks, e.g., internal hard disks or removable disks, magneto-optical disks, and CD-ROM and DVD-ROM disks.

[0117] To provide for user interaction, embodiments of the subject matter described herein can be implemented on a computer having a display device, e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor, for displaying information to the user, as well as a keyboard and a pointing device, e.g., a mouse or trackball, by which the user can provide input to the computer. Other types of devices can also be used to provide for user interaction, e.g., feedback provided to the user can be any form of sensory feedback, such as visual feedback, auditory feedback, or tactile feedback, and input from the user can be received in any form, including acoustic, speech, or tactile input. Additionally, the computer can interact with the user by sending and receiving documents to and from a device used by the user, e.g., by sending a web page to a web browser on the user's device in response to a request received from the web browser. The computer can also interact with the user by sending text messages or other forms of messages to a personal device, e.g., a smartphone running a messaging application, and receiving a response message from the user.

[0118] A data processing device for implementing machine learning models may also include dedicated hardware accelerator units, for example for handling typical, computationally intensive parts of machine learning training or production, i.e., inference, workloads.

[0119] The machine learning models can be implemented and deployed using machine learning frameworks such as, for example, the TensorFlow framework, the Microsoft Cognitive Toolkit framework, the Apache Singa framework, and the Apache MXNet framework.

[0120] An embodiment of the subject matter described herein can be implemented in a computing system that includes a back-end component, e.g., as a data server, or includes a middleware component, e.g., an application server, or includes a front-end component, e.g., a client computer having a graphical user interface, a web browser, or an app through which a user can interact with an implementation of the subject matter described herein, or any combination of one or more such back-end, middleware, or front-end components. The components of the system can be interconnected by any form or medium of digital data communication, such as a communication network. Examples of communication networks include local area networks (LANs) and wide area networks (WANs), e.g., the Internet.

[0121] A computing system may include clients and servers. Clients and servers are typically remote from each other and typically interact through a communications network. The relationship of client and server arises by virtue of computer programs running on the respective computers and having a client-server relationship to each other. In some embodiments, the server sends data, e.g., HTML pages, to a user device for the purpose of, e.g., displaying the data to a user interacting with the device functioning as a client and receiving user input therefrom. Data generated at the user device, e.g., results of user interaction, can be received at the server from the device.

[0122] Although this specification contains many specific implementation details, these should not be interpreted as limitations on the scope of the invention or what may be claimed, but as descriptions of features that may be specific to a particular embodiment of a particular invention. Certain features described in this specification in the context of separate embodiments can also be implemented in combination in a single embodiment. Conversely, various features described in the context of a single embodiment can also be implemented in multiple embodiments separately or in any suitable subcombination. Furthermore, even if features are described above as acting in a particular combination and initially claimed as such, one or more features from the claimed combination may in some cases be carved out of the combination, and the claimed combination may be directed to a subcombination or a variation of the subcombination.

[0123] Similarly, although operations are shown in the figures and claimed in a particular order, this should not be understood as requiring that such operations be performed in the particular order or sequential order shown, or that all of the operations shown be performed, to achieve desired results. In certain situations, multitasking and parallel processing may be advantageous. Furthermore, the separation of various system modules and components in the above embodiments should not be understood as requiring such separation in all embodiments, and it should be understood that the program components and systems described may generally be integrated together in a single software product or packaged in multiple software products.

[0124] Specific embodiments of the subject matter have been described. Other embodiments are within the scope of the following claims. For example, the actions recited in the claims can be performed in a different order and still achieve desirable results. As an example, the processes depicted in the accompanying figures do not necessarily require the particular order shown, or sequential order, to achieve desirable results. In some cases, multitasking and parallel processing may be advantageous. [Explanation of symbols]

[0125] 100 Neural Network System 102 Input 102 System Input 104 Input Sequence 110 Sparse Attention Layer 120 Attention Sub-layer 124 Final Attended Input Sequence 130 Feedforward Sublayer 134 Output Sequence 150 Attention Neural Network 152 Output 200 Figures 210 y-axis 220 x-axis 221 Blank Cell 222 Random Cell 224 Window Cell 226 Global Cell 250 Figures 300 processes

Claims

1. 1. A system for performing machine learning tasks on a network input to generate a network output, the system comprising: one or more computers; and when performed by the one or more computers, the one or more computers: one or more storage devices storing instructions for implementing an attention neural network configured to perform the machine learning task; and wherein the attention neural network comprises one or more sparse attention layers, each sparse attention layer comprises one or more sparse attention sub-layers, each sparse attention sub-layer comprising: receiving a sequence of queries derived from an input sequence to the sparse attention layer, the sequence of queries having a respective query at each of a plurality of input positions; receiving a sequence of keys derived from the input sequence to the sparse attention layer, the sequence of keys having a respective key at each of the plurality of input positions; receiving a sequence of value inputs derived from the input sequence to the sparse attention layer, the sequence of value inputs having a respective value input at each of the plurality of input locations; generating an attended input sequence comprising a respective attended input at each of the plurality of input locations; for each input location in the second subset of input locations; generating the attended inputs at the input locations by calculating a weighted sum of the value inputs at the corresponding appropriate subsets of the input locations according to the respective weights for the corresponding appropriate subsets of the input locations using the query at the input locations to attend only the keys at the corresponding appropriate subsets of the input locations to generate respective weights for each of the input locations in the corresponding appropriate subsets of the input locations; and wherein the corresponding appropriate subset of input locations for each input location in the second subset is configured to: a first proper subset of the input locations shared for each input location in the second subset; one or more input locations randomly selected from the input locations that are outside the first suitable subset; each input position within a window of a fixed number of positions of the input positions in the second subset; Including, the system.

2. Generating an attended input sequence is For each input location in the first suitable subset of input locations:

2. The system of claim 1, further comprising: generating the attended inputs at the input locations by calculating a weighted sum of the value inputs at all the input locations according to the respective weights, using the query at the input locations to attend all the keys in the sequence of keys to generate respective weights for all the input locations.

3. The system of claim 2 , wherein the second subset is a proper subset of the input locations, the second subset being disjoint from the first proper subset.

4. 2. The system of claim 1, wherein the network input is a sequence having a respective token at each of a plurality of the input locations, the attention neural network is configured to augment the network input by adding one or more predetermined global tokens before processing the network input, and the first suitable subset of input locations corresponds to locations to which the one or more global tokens are added.

5. 2. The system of claim 1, wherein the network input is a sequence having a respective token at each of a plurality of the input locations, and the attention neural network is configured to designate a fixed number of the plurality of input locations as the first proper subset of input locations.

6. 2. The system of claim 1, wherein each of the one or more sparse attention layers applies, for each sparse attention sub-layer, a respective query linear transformation to the input sequence to generate the sequence of queries for the sparse attention sub-layer.

7. 2. The system of claim 1, wherein each of the one or more sparse attention layers applies, for each sparse attention sub-layer, a respective key linear transformation to the input sequence to generate the sequence of keys for the sparse attention sub-layer.

8. 2. The system of claim 1, wherein each of the one or more sparse attention layers applies, for each sparse attention sub-layer, a linear transformation of respective values ​​to the input sequence to generate the sequence of value inputs for the sparse attention sub-layer.

9. Each sparse attention layer The system of claim 1 , further configured to generate a final attended input sequence from the attended input sequences generated by one or more sub-layers.

10. Each sparse attention layer and one or more positional feedforward layers configured to generate a layer output sequence from the final attended input sequence, the output sequence comprising a respective layer output at each of the plurality of input positions, the generating comprising: receiving attended input at the input location; applying a sequence of transformations to the attended layer input at the input location to generate a layer output at the input location; The system of claim 9, comprising:

11. One or more non-transitory computer-readable storage media storing instructions that, when executed by one or more computers, cause the one or more computers to implement an attention neural network configured to perform a machine learning task, The attention neural network comprises one or more sparse attention layers, each of which comprises one or more sparse attention sub-layers, each of which comprises: receiving a sequence of queries derived from an input sequence to the sparse attention layer, the sequence of queries having a respective query at each of a plurality of input positions; receiving a sequence of keys derived from the input sequence to the sparse attention layer, the sequence of keys having a respective key at each of the plurality of input positions; receiving a sequence of value inputs derived from the input sequence to the sparse attention layer, the sequence of value inputs having a respective value input at each of the plurality of input locations; generating an attended input sequence comprising a respective attended input at each of the plurality of input locations; for each input location in the second subset of input locations; generating the attended inputs at the input locations by calculating a weighted sum of the value inputs at the corresponding appropriate subsets of the input locations according to the respective weights for the corresponding appropriate subsets of the input locations using the query at the input locations to attend only the keys at the corresponding appropriate subsets of the input locations to generate respective weights for each of the input locations in the corresponding appropriate subsets of the input locations; and wherein the corresponding appropriate subset of input locations for each input location in the second subset is configured to: a first proper subset of the input locations shared for each input location in the second subset; one or more input locations randomly selected from the input locations that are outside the first suitable subset; each input position within a window of a fixed number of positions of the input positions in the second subset; 1. A non-transitory computer readable storage medium comprising:

12. receiving a network input; and processing the network inputs using an attention neural network to generate a network output for a machine learning task on the network inputs, the attention neural network comprising one or more sparse attention layers, each sparse attention layer comprising one or more sparse attention sub-layers, each sparse attention sub-layer comprising: receiving a sequence of queries derived from an input sequence to the sparse attention layer, the sequence of queries having a respective query at each of a plurality of input positions; receiving a sequence of keys derived from the input sequence to the sparse attention layer, the sequence of keys having a respective key at each of the plurality of input positions; receiving a sequence of value inputs derived from the input sequence to the sparse attention layer, the sequence of value inputs having a respective value input at each of the plurality of input locations; generating an attended input sequence comprising a respective attended input at each of the plurality of input locations; for each input location in the second subset of input locations; generating the attended inputs at the input locations by calculating a weighted sum of the value inputs at the corresponding appropriate subsets of the input locations according to the respective weights for the corresponding appropriate subsets of the input locations using the query at the input locations to attend only the keys at the corresponding appropriate subsets of the input locations to generate respective weights for each of the input locations in the corresponding appropriate subsets of the input locations; and wherein the corresponding appropriate subset of input locations for each input location in the second subset is configured to: a first proper subset of the input locations shared for each input location in the second subset; one or more input locations randomly selected from the input locations that are outside the first suitable subset; each input position within a window of a fixed number of positions of the input positions in the second subset; A method implemented by one or more computers, comprising:

13. Generating an attended input sequence is For each input location in the first suitable subset of input locations:

13. The one or more computer implemented methods of claim 12, further comprising generating the attended inputs at the input locations by calculating a weighted sum of the value inputs at all the input locations according to the respective weights, using the query at the input locations to attend all the keys in the sequence of keys to generate respective weights for all the input locations.

14. 14. The one or more computer-implemented method of claim 13, wherein the second subset is a proper subset of the input positions, the second subset being disjoint from the first proper subset.

15. 13. The method implemented by one or more computers of claim 12, wherein the network input is a sequence having a respective token at each of a plurality of the input locations, the attention neural network is configured to augment the network input by adding one or more predetermined global tokens before processing the network input, and the first suitable subset of input locations corresponds to locations to which the one or more global tokens are added.

16. 13. The method implemented by one or more computers of claim 12, wherein the network input is a sequence having a respective token at each of a plurality of the input locations, and the attention neural network is configured to designate a fixed number of the plurality of input locations as the first proper subset of input locations.

17. 13. The one or more computer-implemented method of claim 12, wherein each of the one or more sparse attention layers applies, for each sparse attention sub-layer, a respective query linear transformation to the input sequence to generate the sequence of queries for the sparse attention sub-layer.

18. 13. The one or more computer-implemented methods of claim 12, wherein each of the one or more sparse attention layers applies, for each sparse attention sub-layer, a respective key linear transformation to the input sequence to generate the sequence of keys for the sparse attention sub-layer.

19. 13. The one or more computer-implemented method of claim 12, wherein each of the one or more sparse attention layers applies, for each sparse attention sub-layer, a linear transformation of respective values ​​to the input sequence to generate the sequence of value inputs for the sparse attention sub-layer.

20. Each sparse attention layer 13. The one or more computer implemented methods of claim 12, further configured to generate a final attended input sequence from the attended input sequences generated by one or more sub-layers.