Monotonic Chunkwise Attention

Chung-Cheng Chiu, Colin Raffel

Introduction

Sequence-to-sequence models (Sutskever et al., 2014; Cho et al., 2014) with a soft attention mechanism (Bahdanau et al., 2015) have been successfully applied to a plethora of sequence transduction problems (Luong et al., 2015; Xu et al., 2015; Chorowski et al., 2015; Wang et al., 2017; See et al., 2017). In their most familiar form, these models process an input sequence with an encoder recurrent neural network (RNN) to produce a sequence of hidden states, referred to as a memory. A decoder RNN then autoregressively produces the output sequence. At each output timestep, the decoder is directly conditioned by an attention mechanism, which allows the decoder to refer back to entries in the encoder’s hidden state sequence. This use of the encoder’s hidden states as a memory gives the model the ability to bridge long input-output time lags (Raffel & Ellis, 2015), which provides a distinct advantage over sequence-to-sequence models lacking an attention mechanism (Bahdanau et al., 2015). Furthermore, visualizing where in the input the model was attending to at each output timestep produces an input-output alignment which provides valuable insight into the model’s behavior.

As originally defined, soft attention inspects every entry of the memory at each output timestep, effectively allowing the model to condition on any arbitrary input sequence entry. This flexibility comes at a distinct cost, namely that decoding with a soft attention mechanism has a quadratic time and space cost O(TU)\mathcal{O}(TU), where TT and UU are the input and output sequence lengths respectively. This precludes its use on very long sequences, e.g. summarizing extremely long documents. In addition, because soft attention considers the possibility of attending to every entry in the memory at every output timestep, it must wait until the input sequence has been processed before producing output. This makes it inapplicable to real-time sequence transduction problems. Raffel et al. (2017) recently pointed out that these issues can be mitigated when the input-output alignment is monotonic, i.e. the correspondence between elements in the input and output sequence does not involve reordering. This property is present in various real-world problems, such as speech recognition and synthesis, where the input and output share a natural temporal order (see, for example, fig. 2). In other settings, the alignment only involves local reorderings, e.g. machine translation for certain language pairs (Birch et al., 2008).

Based on this observation, Raffel et al. (2017) introduced an attention mechanism that explicitly enforces a hard monotonic input-output alignment, which allows for online and linear-time decoding. However, the hard monotonicity constraint also limits the expressivity of the model compared to soft attention (which can induce an arbitrary soft alignment). Indeed, experimentally it was shown that the performance of sequence-to-sequence models utilizing this monotonic attention mechanism lagged behind that of standard soft attention.

In this paper, we aim to close this gap by introducing a novel attention mechanism which retains the online and linear-time benefits of hard monotonic attention while allowing for soft alignments. Our approach, which we dub “Monotonic Chunkwise Attention” (MoChA), allows the model to perform soft attention over small chunks of the memory preceding where a hard monotonic attention mechanism has chosen to attend. It also has a training procedure which allows it to be straightforwardly applied to existing sequence-to-sequence models and trained with standard backpropagation. We show experimentally that MoChA effectively closes the gap between monotonic and soft attention on online speech recognition and provides a 20% relative improvement over monotonic attention on document summarization (a task which does not exhibit monotonic alignments). These benefits incur only a modest increase in the number of parameters and computational cost. We also provide a discussion of related work and ideas for future research using our proposed mechanism.

Defining MoChA

To develop our proposed attention mechanism, we will first review the sequence-to-sequence framework and the most common form of soft attention used with it. Because MoChA can be considered a generalization of monotonic attention, we then re-derive this approach and point out some of its shortcomings. From there, we show how soft attention over chunks can be straightforwardly added to hard monotonic attention, giving us the MoChA attention mechanism. We also show how MoChA can be trained efficiently with respect to the mechanism’s expected output, which allows us to use standard backpropagation.

A sequence-to-sequence model is one which transduces an input sequence x={x1,,xT}\mathbf{x}=\{x_{1},\ldots,x_{T}\} to an output sequence (potentially of a different modality) y={y1,,yU}\mathbf{y}=\{y_{1},\ldots,y_{U}\}. Typically, the input sequence is first converted to a sequence of hidden states h={h1,,hT}\mathbf{h}=\{h_{1},\ldots,h_{T}\} by an encoder recurrent neural network (RNN):

A decoder RNN then updates its hidden state autoregressively and an output layer (typically using a softmax\operatorname{softmax} nonlinearity) produces the output sequence:

where sis_{i} is the decoder’s state and cic_{i} is a “context” vector which is computed as a function of the encoder hidden state sequence h\mathbf{h}. Note that cic_{i} is the sole conduit through which the decoder has access to information about the input sequence.

In the originally proposed sequence-to-sequence framework (Sutskever et al., 2014), the context vector is simply set to the final encoder hidden state, i.e. ci=hTc_{i}=h_{T}. It was subsequently found that this approach exhibits degraded performance when transducing long sequences (Bahdanau et al., 2015). Instead, it has become standard to use an attention mechanism which treats the hidden state sequence as a (soft-)addressable memory whose entries are used to compute the context vector cic_{i}. In the following subsections, we discuss three such approaches for computing cic_{i}; otherwise, the sequence-to-sequence framework remains unchanged.

2 Standard Soft Attention

Currently, the most commonly used attention mechanism is the one originally proposed in (Bahdanau et al., 2015). At each output timestep ii, this approach proceeds as follows: First, an unnormalized scalar “energy” value ei,je_{i,j} is produced for each memory entry:

A common choice for Energy()\operatorname{Energy}(\cdot) is

Finally, the context vector is computed as a simple weighted average of h\mathbf{h}, weighted by αi,:\alpha_{i,:}:

We visualize this soft attention mechanism in fig. 1(a).

Note that in order to compute cic_{i} for any output timestep ii, we need to have computed all of the encoder hidden states hjh_{j} for j{1,,T}j\in\{1,\ldots,T\}. This implies that this form of attention is not applicable to online/real-time sequence transduction problems, because it needs to have observed the entire input sequence before producing any output. Furthermore, producing each context vector cic_{i} involves computing TT energy scalar terms and weighting values. While these operations can typically be parallelized, this nevertheless results in decoding having a O(TU)\mathcal{O}(TU) cost in time and space.

3 Monotonic Attention

To address the aforementioned issues with soft attention, Raffel et al. (2017) proposed a hard monotonic attention mechanism whose attention process can be described as follows: At output timestep ii, the attention mechanism begins inspecting memory entries starting at the memory index it attended to at the previous output timestep, referred to as ti1t_{i-1}. It then computes an unnormalized energy scalar ei,je_{i,j} for j=ti1,ti1+1,j=t_{i-1},t_{i-1}+1,\ldots and passes these energy values into a logistic sigmoid function \upsigma()\upsigma(\cdot) to produce “selection probabilities” pi,jp_{i,j}. Then, a discrete attend/don’t attend decision zi,jz_{i,j} is sampled from a Bernoulli random variable parameterized by pi,jp_{i,j}. In total, so far we have

As soon as zi,j=1z_{i,j}=1 for some jj, the model stops and sets ti=jt_{i}=j and ci=htic_{i}=h_{t_{i}}. This process is visualized in fig. 1(b). Note that because this attention mechanism only makes a single pass over the memory, it has a O(max(T,U))\mathcal{O}(\max(T,U)) (linear) cost. Further, in order to attend to memory entry hjh_{j}, the encoder RNN only needs to have processed input sequence entries x1,,xjx_{1},\ldots,x_{j}, which allows it to be used for online sequence transduction. Finally, note that if pi,j{0,1}p_{i,j}\in\{0,1\} (a condition which is encouraged, as discussed below) then the greedy assignment of ci=htic_{i}=h_{t_{i}} is equivalent to marginalizing over possible alignment paths.

Because this attention process involves sampling and hard assignment, models utilizing hard monotonic attention can’t be trained with backpropagation. To remedy this, Raffel et al. (2017) propose training with respect to the expected value of cic_{i} by computing the probability distribution over the memory induced by the attention process. This distribution takes the following form:

The context vector cic_{i} is then computed as a weighted sum of the memory as in eq. 7. Equation 11 can be explained by observing that (1pi,j1)αi,j1/pi,j1(1-p_{i,j-1})\alpha_{i,j-1}/p_{i,j-1} is the probability of attending to memory entry j1j-1 at the current output timestep (αi,j1\alpha_{i,j-1}) corrected for the fact that the model did not attend to memory entry jj (by multiplying by (1pi,j1)(1-p_{i,j-1}) and dividing by pi,j1p_{i,j-1}). The addition of αi1,j\alpha_{i-1,j} represents the additional possibility that the model attended to entry jj at the previous output timestep, and finally multiplying it all by pi,jp_{i,j} reflects the probability that the model selected memory item jj at the current output timestep ii. Note that this recurrence relation is not parallelizable across memory indices jj (unlike, say, softmax\operatorname{softmax}), but fortunately substituting qi,j=αi,j/pi,jq_{i,j}=\alpha_{i,j}/p_{i,j} produces the first-order linear difference equation qi,j=(1pi,j1)qi,j1+αi1,jq_{i,j}=(1-p_{i,j-1})q_{i,j-1}+\alpha_{i-1,j} which has the following solution (Kelley & Peterson, 2001):

where cumprod(x)=[1,x1,x1x2,,ix1xi]\operatorname{\texttt{cumprod}}(\mathbf{x})=[1,x_{1},x_{1}x_{2},\ldots,\prod_{i}^{|x|-1}x_{i}] and cumsum(x)=[x1,x1+x2,,ixxi]\operatorname{\texttt{cumsum}}(\mathbf{x})=[x_{1},x_{1}+x_{2},\ldots,\sum_{i}^{|x|}x_{i}]. Because the cumulative sum and product can be computed in parallel (Ladner & Fischer, 1980), models can still be trained efficiently with this approach.

where g,rg,r are learnable scalars and v,Ws,Wh,bv,W_{s},W_{h},b are as in eq. 5. Further discussion of these modifications is provided in (Raffel et al., 2017) appendix G.

4 Monotonic Chunkwise Attention

While hard monotonic attention provides online and linear-time decoding, it nevertheless imposes two significant constraints on the model: First, that the decoder can only attend to a single entry in memory at each output timestep, and second, that the input-output alignment must be strictly monotonic. These constraints are in contrast to standard soft attention, which allows a potentially arbitrary and smooth input-output alignment. Experimentally, it was shown that performance degrades somewhat on all tasks tested in (Raffel et al., 2017). Our hypothesis is that this degradation stems from the aforementioned constraints imposed by hard monotonic attention.

To remedy these issues, we propose a novel attention mechanism which we call MoChA, for Monotonic Chunkwise Attention. The core of our idea is to allow the attention mechanism to perform soft attention over small “chunks” of memory preceding where a hard monotonic attention mechanism decides to stop. This facilitates some degree of softness in the input-output alignment, while retaining the online decoding and linear-time complexity benefits.

At test time, we follow the hard monotonic attention process of section 2.3 in order to determine tit_{i} (the location where the hard monotonic attention mechanism decides to stop scanning the memory at output timestep ii). However, instead of setting ci=htic_{i}=h_{t_{i}}, we allow the model to perform soft attention over the length-ww window of memory entries preceding and including tit_{i}:

where ChunkEnergy()\operatorname{ChunkEnergy}(\cdot) is an energy function analogous to eq. 5, which is distinct from the MonotonicEnergy()\operatorname{MonotonicEnergy}(\cdot) function. MoChA’s attention process is visualized in fig. 1(c). Note that MoChA allows for nonmonotonic alignments; specifically, it allows for reordering of the memory entries hv,,htih_{v},\ldots,h_{t_{i}}. Including soft attention over chunks only increases the runtime complexity by the constant factor ww, and decoding can still proceed in an online fashion. Furthermore, using MoChA only incurs a modest increase in the total number of parameters (corresponding to adding the second attention energy function ChunkEnergy()\operatorname{ChunkEnergy}(\cdot)). For example, in the speech recognition experiments described in section 3.1, the total number of model parameters only increased by about 1%. Finally, we point out that setting w=1w=1 recovers hard monotonic attention. For completeness, we show the decoding algorithm for MoChA in full in algorithm 1.

During training, we proceed in a similar fashion as with monotonic attention, namely training the model using the expected value of cic_{i} based on MoChA’s induced probability distribution (which we denote βi,j\beta_{i,j}). This can be computed as

The sum over kk reflects the possible positions at which the monotonic attention could have stopped scanning the memory in order to contribute probability to βi,j\beta_{i,j} and the term inside the summation represents the softmax\operatorname{softmax} probability distribution over the chunk, scaled by the monotonic attention probability αi,k\alpha_{i,k}. Computing each βi,j\beta_{i,j} in this fashion is expensive due to the nested summation. Fortunately, there is an efficient way to compute βi,j\beta_{i,j} for j{1,,T}j\in\{1,\ldots,T\} in parallel: First, for a sequence x={x1,,xT}\mathbf{x}=\{x_{1},\ldots,x_{T}\} we define

This function can be computed efficiently, for example, by convolving x\mathbf{x} with a length-(f+b1)(f+b-1) sequence of 11s and truncating appropriately. Now, we can compute βi,:\beta_{i,:} efficiently as

Putting it all together produces the following algorithm for computing cic_{i} during training:

Equations 20, 21, 22 and 23 reflect the (unchanged) computation of the monotonic attention probability distribution, eqs. 24 and 25 compute MoChA’s probability distribution, and finally eq. 26 computes the expected value of the context vector cic_{i}. In summary, we have developed a novel attention mechanism which allows computing soft attention over small chunks of the memory, whose locations are set adaptively. This mechanism has an efficient training-time algorithm and enjoys online and linear-time decoding at test time. We attempt to quantify the resulting speedup compared to soft attention with a synthetic benchmark in appendix B.

Experiments

To test out MoChA, we applied it to two exemplary sequence transduction tasks: Online speech recognition and document summarization. Speech recognition is a promising setting for MoChA because it induces a naturally monotonic input-output alignment, and because online decoding is often required in the real world. Document summarization, on the other hand, does not exhibit a monotonic alignment, and we mostly include it as a way of testing the limitations of our model. We emphasize that in all experiments, we took a strong baseline sequence-to-sequence model with standard soft attention and changed only the attention mechanism; all hyperparameters, model structure, training approach, etc. were kept exactly the same. This allows us to isolate the effective difference in performance caused by switching to MoChA. Of course, this may be an artificially low estimate of the best-case performance of MoChA, due to the fact that it may benefit from a somewhat different hyperparameter setting. We leave eking out the best-case performance for future work.

Specifically, for MoChA we used eq. 13 for both the MonotonicEnergy\operatorname{MonotonicEnergy} and the ChunkEnergy\operatorname{ChunkEnergy} functions. Following (Raffel et al., 2017), we initialized g=1/dg=1/\sqrt{d} (dd being the attention energy function hidden dimension) and tuned initial values for rr based on validation set performance, using r=4r=-4 for MoChA on speech recognition, r=0r=0 for MoChA on summarization, and r=1r=-1 for our monotonic attention baseline on summarization. We similarly tuned the chunk size ww: For speech recognition, we were surprised to find that all of w{2,3,4,6,8}w\in\{2,3,4,6,8\} performed comparably and thus chose the smallest value of w=2w=2. For summarization, we found w=8w=8 to work best. We demonstrate empirically that even these small window sizes give a significant boost over hard monotonic attention (w=1w=1) while incurring only a minor computational penalty. In all experiments, we report metrics on the test set at the training step of best performance on a validation set.

First, we apply MoChA in its natural setting, i.e. a domain where we expect roughly monotonic alignments:Even for nonphonemic utterances (e.g. “AAA” being transcribed as “triple A”), the learned alignment still tends to be monotonic – see e.g. (Chan et al., 2016) figure 6. Online speech recognition on the Wall Street Journal (WSJ) corpus (Paul & Baker, 1992). The goal in this task is to produce the sequence of words spoken in a recorded speech utterance. In this setting, RNN-based models must be unidirectional in order to satisfy the online requirement. We use the model of (Raffel et al., 2017), which is itself based on that of (Zhang et al., 2016). Full model and training details are provided in section A.1, but as a broad overview, the network ingests the spoken utterance as a mel-filterbank spectrogram which is passed to an encoder consisting of convolution layers, convolutional LSTM layers, and unidirectional LSTM layers. The decoder is a single unidirectional LSTM, which attends to the encoder state sequence via either MoChA or a standard soft attention mechanism. The decoder produces a sequence of distributions over character and word-delimiter tokens. Performance is measured in terms of word error rate (WER) after segmenting characters output by the model into words based on the produced word delimiter tokens. None of the models we report integrated a separate language model.

We show the results of our experiments, along with those obtained by prior work, in table 2. MoChA was able to beat the state-of-the-art by a large margin (20% relative). Because the performance of MoChA and the soft attention baseline was so close, we ran 8 repeat trials for both attention mechanisms and report the best, average, and standard deviation of word error rates across these trials. We found MoChA-based models to have slightly higher variance across trials, which resulted in it having a lower best WER but a slightly higher mean WER compared to soft attention (though the difference in means was not statistically significant for N=8N=8 under an unpaired Student’s t-test). This is the first time, to our knowledge, that an online attention mechanism matched the performance of standard (offline) soft attention. To get an idea of the behavior of the different attention mechanisms, we show attention alignments for an example from the WSJ validation set in fig. 2. As expected, the alignment looks roughly the same for all attention mechanisms. We note especially that MoChA is indeed taking advantage of the opportunity to produce a soft attention distribution over each length-22 chunk.

Since we empirically found the small value of w=2w=2 to be sufficient to realize these gains, we carried out a few additional experiments to confirm that they can indeed be attributed to MoChA. First, the use of a second independent attention energy function ChunkEnergy()\operatorname{ChunkEnergy}(\cdot) incurs a modest increase in parameter count – about 1% in our speech recognition model. To ensure the improved performance was not due to this parameter increase, we also re-trained the monotonic attention baseline with an energy function with a doubled hidden dimensionality (which produces a comparable increase in the number of parameters in a natural way). Across eight trials, the difference in performance (a decrease of 0.3% WER) was not significant compared to the baseline and was dwarfed by the gains achieved by MoChA. We also trained the w=2w=2 MoChA model with half the attention energy hidden dimensionality (which similarly reconciles the parameter difference) and found it did not significantly undercut our gains, increasing the WER by only 0.2% (not significant over eight trials). Separately, one possible benefit of MoChA is that the attention mechanism can access a larger window of the input when producing the context vectors. An alternative approach towards this end would be to increase the temporal receptive field of the convolutional front-end, so we also re-trained the monotonic attention baseline with this change. Again, the difference in performance (an increase of 0.3% WER) was not significant over eight trials. These additional experiments reinforce the benefits of using MoChA for online speech recognition.

2 Document Summarization

Having proven the effectiveness of MoChA in the comfortable setting of speech recognition, we now test its limits in a task without a monotonic input/output alignment. Raffel et al. (2017) experimented with sentence summarization on the Gigaword dataset, which frequently exhibits monotonic alignments and involves short sequences (sentence-length sequences of words). They were able to achieve only slightly degraded performance with hard monotonic attention compared to a soft attention baseline. As a result, we turn to a more difficult task where hard monotonic attention struggles more substantially due to the lack of monotonic alignments: Document summarization on the CNN/Daily Mail corpus (Nallapati et al., 2016). While we primarily study this problem because it has the potential to be challenging, online and linear-time attention could also be beneficial in real-world scenarios where very long bodies of text need to be summarized as they are being created (e.g. producing a summary of a speech as it is being given).

The goal of this task is to produce a sequence of “highlight” sentences from a news article. As a baseline model, we chose the “pointer-generator” network (without the coverage penalty) of (See et al., 2017). For full model architecture and training details, refer to section A.2. As a brief summary, input words are converted to a learned embedding and passed into the model’s encoder, consisting of a single bidirectional LSTM layer. The decoder is a unidirectional LSTM with an attention mechanism whose state is passed to a softmax\operatorname{softmax} layer which produces a sequence of distributions over the vocabulary. The model is augmented with a copy mechanism, which interpolates linearly between using the softmax\operatorname{softmax} output layer’s word distribution, or a distribution of word IDs weighted by the attention distribution at a given output timestep. We tested this model with standard soft attention (as used in (See et al., 2017)), hard monotonic attention, and MoChA with w=8w=8.

The results are shown in table 2. We found that using a hard monotonic attention mechanism degraded performance substantially (nearly 8 ROUGE-1 points), likely because of the strong reordering required by this task. However, MoChA was able to effectively halve the gap between monotonic and soft attention, despite using the modest chunk size of w=8w=8. We consider this an encouraging indication of the benefits of being able to deal with local reorderings.

Related Work

A similar model to MoChA is the “Neural Transducer” (Jaitly et al., 2015), where the input sequence is pre-segmented into equally-sized non-overlapping chunks and attentive sequence-to-sequence transduction is performed over each chunk separately. The full output sequence is produced by marginalizing out over possible end-of-sequence locations for the sequences generated from each chunk. While our model also performs soft attention over chunks, the locations of our chunks are set adaptively by a hard monotonic attention mechanism rather than fixed, and it avoids the marginalization over chunkwise end-of-sequence tokens.

Chorowski et al. (2015) proposes a similar idea, wherein the range over which soft attention is computed at each output timestep is limited to a fixed-sized window around the memory index of maximal attention probability at the previous output timestep. While this also produces soft attention over chunks, our approach differs in that the chunk boundary is set by an independent hard monotonic attention mechanism. This difference resulted in Chorowski et al. (2015) using a very large chunk size of 150, which effectively prevents its use in online settings and incurs a significantly higher computational cost than our approach which only required small values for ww.

A related class of non-attentive sequence transduction models which can be used in online settings are connectionist temporal classification (Graves et al., 2006), the RNN transducer (Graves, 2012), segment-to-segment neural transduction (Yu et al., 2016), and the segmental RNN (Kong et al., 2015). These models are distinguished from sequence-to-sequence models with attention mechanisms by the fact that the decoder does not condition directly on the input sequence, and that decoding is done via a dynamic program. A detailed comparison of this class of approaches and attention-based models is provided in (Prabhavalkar et al., 2017), where it is shown that attention-based models perform best in speech recognition experiments. Further, Hori et al. (2017) recently proposed jointly training a speech recognition model with both a CTC loss and an attention mechanism. This combination encouraged the model to learn monotonic alignments, but Hori et al. (2017) still used a standard soft attention mechanism which precludes the model’s use in online settings.

Finally, we note that there have been a few other works considering hard monotonic alignments, e.g. using reinforcement learning (Zaremba & Sutskever, 2015; Luo et al., 2016; Lawson et al., 2017), by using separately-computed target alignments (Aharoni & Goldberg, 2016) or by assuming a strictly diagonal alignment (Luong et al., 2015). We suspect that these approaches may confer similar benefits from adding chunkwise attention.

Conclusion

We have proposed MoChA, an attention mechanism which performs soft attention over adaptively-located chunks of the input sequence. MoChA allows for online and linear-time decoding, while also facilitating local input-output reorderings. Experimentally, we showed that MoChA obtains state-of-the-art performance on an online speech recognition task, and that it substantially outperformed a hard monotonic attention-based model on document summarization. In future work, we are interested in applying MoChA to additional problems with (approximately) monotonic alignments, such as speech synthesis (Wang et al., 2017) and morphological inflection (Aharoni & Goldberg, 2016). We would also like to investigate ways to allow the chunk size ww to also vary adaptively. To facilitate building on our work, we provide an example implementation of MoChA online.https://github.com/craffel/mocha

We thank Ying Xiao, Kevin Clark, Jacob Buckman, our anonymous reviewers, and members of the Google Brain Team for their helpful comments on this paper.

References

Appendix A Experiment Details

In this appendix, we provide specifics about the experiments carried out in section 3. All experiments were done using TensorFlow (Abadi et al., 2016).

Overall, our model follows that of (Raffel et al., 2017), but we repeat the details here for posterity. We represented speech utterances as mel-scaled spectrograms with 80 coefficients, along with delta and delta-delta coefficients. Feature sequences were first fed into two convolutional layers, each with 3×33\times 3 filters and a 2×22\times 2 stride with 3232 filters per layer. Each convolution was followed by batch normalization (Ioffe & Szegedy, 2015) prior to a ReLU nonlinearity. The output of the convolutional layers was fed into a convolutional LSTM layer, using 1×31\times 3 filters. This was followed by an additional 3×33\times 3 convolutional layer with 3232 filters and a stride of 1×11\times 1. Finally, the encoder had three additional unidirectional LSTM layers with a hidden state size of 256, each followed by a dense layer with a 256-dimensional output with batch normalization and a ReLU nonlinearity.

The decoder was a single unidirectional LSTM layer with a hidden state size of 256. Its input consisted of a 64-dimensional learned embedding of the previously output symbol and the 256-dimensional context vector produced by the attention mechanism. The attention energy function had a hidden dimensionality dd of 128. The softmax\operatorname{softmax} output layer took as input the concatenation of the attention context vector and the decoder’s state.

The network was trained using the Adam optimizer (Kingma & Ba, 2014) with β1=0.9\beta_{1}=0.9, β2=0.999\beta_{2}=0.999, and ϵ=106\epsilon=10^{-6}. The initial learning rate 0.0010.001 was dropped by a factor of 1010 after 600,000, 800,000, and 1,000,000 steps. Note that Raffel et al. (2017) used a slightly different learning rate schedule, but we found that the aforementioned schedule improved performance both for the soft attention baseline and for MoChA, but hurt performance for hard monotonic attention. For this reason, we report the hard monotonic attention performance from (Raffel et al., 2017) instead of re-running that baseline. Inputs were fed into the network in batches of 8 utterances, using standard teacher forcing. Localized label smoothing (Chorowski & Jaitly, 2017) was applied to the target outputs with weights [0.015,0.035,0.035,0.015][0.015,0.035,0.035,0.015] for neighbors at $.Weusedgradientclipping,settingthenormoftheglobalgradientvectorto. We used gradient clipping, setting the norm of the global gradient vector to1wheneveritexceededthatthreshold.WeaddedvariationalweightnoisetoLSTMlayerparametersandembeddingswithstandarddeviationofwhenever it exceeded that threshold. We added variational weight noise to LSTM layer parameters and embeddings with standard deviation of0.075startingafter20,000trainingsteps.WealsoappliedL2weightdecaywithacoefficientofstarting after 20,000 training steps. We also applied L2 weight decay with a coefficient of10^{-6}$. At test time, we used a beam search with rank pruning at 8 hypotheses and a pruning threshold of 3.

A.2 Document Summarization

For summarization, we reimplemented the pointer-generator of See et al. (2017). Inputs were provided as one-hot vectors representing ID in a 50,000 word vocabulary, which were mapped to a 512-dimensional learned embedding. The encoder consisted of a single bidirectional LSTM layer with 512 hidden units, and the decoder was a single unidirectional LSTM layer with 1024 hidden units. Our attention mechanisms had a hidden dimensionality dd of 1024. Output words were embedded into a learned 1024-dimensional embedding and concatenated with the context vector before being fed back in to the decoder.

For training, we used the Adam optimizer with β1=0.9\beta_{1}=0.9, β2=0.999\beta_{2}=0.999, and ϵ=0.0000008\epsilon=0.0000008. Our optimizer had an initial learning rate of 0.00050.0005 which was continuously decayed starting at 50,000 steps such that the learning rate was halved every 10,000 steps until it reached 0.000050.00005. Sequences were fed into the model with a batch size of 6464. As in See et al. (2017), we truncated all input sequence to a maximum length of 400400 words. The global norm of the gradient was clipped to never exceed 55. Note that we did not include the “coverage penalty” discussed in See et al. (2017) in our models. During eval, we used an identical beam search as in the speech recognition experiments with rank pruning at 8 hypotheses and a pruning threshold of 3.

Appendix B Speed Benchmark

To get an idea of the possible speedup incurred by using MoChA instead of standard soft attention, we carried out a simple synthetic benchmark analogous to the one in (Raffel et al., 2017), appendix F. In this test, we implemented solely the attention mechanism and measured its speed for various input/output sequence lengths. This isolates the speed of the portion of the network we are studying; in practice, other portions of the network (e.g. encoder RNN, decoder RNN, etc.) may dominate the computational cost of running the full model. Any resulting speedup can therefore be considered an upper bound on what might be observed in the real-world. Further, we coded the benchmark in C++ using the Eigen library (Guennebaud et al., 2010) to remove any overhead incurred by a particular model framework.

In this synthetic setting, attention was performed over a randomly generated encoder hidden state sequence, using random decoder states. The encoder and decoder state dimensionality was set to 256256. We varied the input and output sequence lengths TT and UU simultaneously, in the range {10,20,30,,100}\{10,20,30,\ldots,100\}. We measured the speed for soft attention, monotonic attention (i.e. MoChA with w=1w=1), and MoChA with w={2,4,8}w=\{2,4,8\}. For all times, we report the mean of 100 trials.

The results are shown in fig. 3. As expected, soft attention exhibits a roughly quadratic time complexity, where as MoChA’s is linear. This results in a larger speedup factor as TT and UU increase. Further, the complexity of MoChA increases linearly with ww. Finally, note that for T,U=10T,U=10 and w=8w=8, the speed of MoChA and soft attention are similar, because the chunk effectively spans the entire memory. This confirms the intuition that speedups from MoChA will be most dramatic for large TT and UU and relatively small ww.

Appendix C Monotonic Adaptive Chunkwise Attention (MAtChA)

In this paper, we considered an attention mechanism which attends to small, fixed-length chunks preceding the location set by a monotonic attention mechanism. In parallel with this work, we also considered another online and linear-time attention mechanism which instead set the chunks to be the region of memory between tit_{i} and ti1t_{i-1}. We called this approach MAtChA, for Monotonic Adaptive Chunkwise Attention. The motivation behind this alternative was that in some cases it may be suboptimal to use a fixed chunk size for all locations in all sequences. However, as we will discuss below, we found that it did not improve performance over MoChA on any of the tasks we tried despite the training-time algorithm having increased memory and computational requirements. We include a discussion and derivation of MAtChA here for posterity, in case other researchers are interested in pursuing similar ideas.

Overall, the test-time decoding process of MAtChA (which is also online and linear-time) is extremely similar to algorithm 1 except that instead of setting the chunk start location vv to v=jw+1v=j-w+1, we set v=ti1v=t_{i-1} so that

This process is visualized in fig. 4. Note that if ti=ti1t_{i}=t_{i-1}, then MAtChA must assign all attention to memory entry tit_{i} because the sole entry of the chunk must be assigned a probability of 11.

The overall equation for MAtChA’s attention for memory entry jj at output timestep ii can be expressed as

This equation can be explained left to right as follows: First, we must sum over all possible positions that monotonic attention could have attended to at the previous timestep k{1,,j}k\in\{1,\ldots,j\}. Second, we sum over all possible locations where we can attend at the current output timestep l{j,,T}l\in\{j,\ldots,T\}. Third, for a given input/output timestep combination, we compute the softmax probability of memory entry jj over the chunk spanning from kk to ll (as in the main text, we refer to attention energies produced by ChunkEnergy\operatorname{ChunkEnergy} as ui,ju_{i,j}). Fourth, we multiply by αi1,k\alpha_{i-1,k} which represents the probability that the monotonic attention mechanism attended to memory entry kk at the previous timestep. Fifth, we multiply by pi,lp_{i,l}, the probability of the monotonic attention mechanism choosing memory entry ll at the current output timestep. Finally, we multiply by the probability of not choosing any of the memory entries from kk to l1l-1. Using eq. 28 to compute βi,j\beta_{i,j} to obtain the expected value of the context vector cic_{i} allows models utilizing MAtChA to be trained with backpropagation.

Note that eq. 28 contains multiple nested summations and products for computing each i,ji,j pair. Fortunately, as with monotonic attention and MoChA there is a dynamic program which allows βi,:\beta_{i,:} to be computed completely in parallel which can be derived as follows:

Note that eq. 38 has the same form as eq. 11; following the derivation of (Raffel et al., 2017) appendix C.1 suggests that it can similarly be expressed in terms of (parallelizable) cumulative sum and cumulative product operations. However, a notable difference between eq. 38 and eq. 11 is that the former has a dependence on an additional index variable ll. This is due to the fact that computing ri,j,lr_{i,j,l} for all jj and ll requires computing the sum of all possible subsequences of exp(ui,:)\exp(u_{i,:}). Fortunately, these subsequence sums can also be computed efficiently; first, define

Note that, for a sequence x\mathbf{x} of length TT, AllPartialSums(x)\operatorname{AllPartialSums}(\textbf{x}) produces a matrix of shape T×TT\times T. Now, for jlj\leq l we have

The sum in the first set of parentheses is simply the llth entry of the cumulative sum of x\mathbf{x}; the sum in the second is the jjth entry of the exclusive cumulative sum of xx. It follows that all entries of AllPartialSums(x)\operatorname{AllPartialSums}(\textbf{x}) can be computed efficiently in parallel by computing the cumulative sum and subtracting appropriately. Combining the above and the derivation of (Raffel et al., 2017) appendix C.1, we have that

where, as a minor abuse, we are using “broadcasting”https://docs.scipy.org/doc/numpy-1.13.0/user/basics.broadcasting.html notation. In a similar fashion, the product over terms (1pi,o)(1-p_{i,o}) in eq. 39 involves computing the product of all possible subsequences. A function AllPartialProducts()\operatorname{AllPartialProducts}(\cdot) can be analogously defined to eq. 40 and computed efficiently with a cumulative product and division. Putting it all together, we can compute all of the terms βi,j\beta_{i,j} in parallel for a given output timestep ii as

While we have demonstrated a parallelizable procedure for computing MAtChA’s attention distribution, the marginalization over all possible chunk start and end locations necessitates a quadratic number of terms to be computed for each output timestep/memory entry combination. Even in the case of perfectly efficient parallelization, the result is an algorithm which requires O(UT2)\mathcal{O}(UT^{2}) memory for decoding (as opposed to the O(UT)\mathcal{O}(UT) memory required when training standard soft attention, monotonic attention, or MoChA). This puts it at a distinct disadvantage, especially for large values of TT. Experimentally, we had hoped that these drawbacks would be outweighed by superior empirical performance of MAtChA, but we unfortunately found that it did not perform any better than MoChA for the tasks we tried. As a result, we decided not to include discussion of MAtChA in the main text and recommend against its use in its current form. Nevertheless, we are interested in mixing MoChA and MAtChA in future work in attempt to reap the benefits of their combined strength.