Combining Subword Representations into Word-level Representations in the Transformer Architecture (2020)

Abstract: In Neural Machine Translation, using word-level tokens leads to degradation in translation quality. The dominant approaches use subword-level tokens, but this increases the length of the sequences and makes it difficult to profit from word-level information such as POS tags or semantic dependencies. We propose a modification to the Transformer model to combine subword-level representations into word-level ones in the first layers of the encoder, reducing the effective length of the sequences in the following layers and providing a natural point to incorporate extra word-level information. Our experiments show that this approach maintains the translation quality with respect to the normal Transformer model when no extra word-level information is injected and that it is superior to the currently dominant method for incorporating word-level source language information to models based on subword-level vocabularies.

## introduction currently dominant neural machine translation (nmt) architectures receive as input sequences of discrete tokens taken from fixed-size source and target token vocabularies defined a priori. before being fed to the network, the input text is tokenized and the positions of those tokens within the vocabulary table are the actual network inputs. the granularity of the tokens in those vocabularies can range from character-level, to subword-level, to word-level. character-level token granularity, while allowing maximum representation ability with minimal vocabulary size for alphabet-based scripts, also delegates word formation modeling to the network and makes token sequences to be much longer than with word-based tokens. using word-level tokens leads to very large vocabulary sizes, especially for morphologically rich languages, where the number of surface forms per lemma is high. large token vocabularies are impractical for the current neural architectures and hardware. it is frequent to constrain the vocabulary size to a few tens of thousand tokens, which is hardly enough to fit the number of symbols in a complete word-based vocabulary. compositional word structures like numbers pose further problems with such a granularity level, as well as proper nouns. when word-based vocabularies are used, the vocabulary is built with the most frequent surface forms in the training data, which normally leads to degradation of translation quality. subword-level token granularity offers a compromise between representational power and vocabulary size, especially statistically extracted subword vocabulary strategies like byte pair encoding (bpe) @xcite . models with word-level token vocabularies can incorporate word-level information as extra input to the model by combining it one-to-one with the token representations. some examples of word-level information are part of speech (pos) tags, syntactic dependency relationships or lemmas. in order to make use of word-level information in models with subword-level token vocabularies, a usual approach is to assign the word information to all its subwords @xcite . this approach, despite improving the translation quality, introduces an information assignment mismatch. we propose to modify the transformer architecture @xcite to combine the learned subword representations into word representations in the encoder block. this allows to naturally incorporate any extra word-level information directly at the level of word-level representations. this work is structured as follows: the relevant related work is described in section 2; the proposed approach is described in section 3, while the experimental setup is presented in section 4 and the results are described and discussed in section 5. finally, the conclusions are drawn in section 6. ## related work the main difficulty in profiting from word-level information in subword-based nmt architectures is the word-subword token level mismatch. several lines of research have studied how to combine subword-level representations into wordlevel information in a task-agnostic way. while the approaches by @xcite al. (2017), zhao et al. (2018) and li et al. (2018) aim at computing pre-trained word representations, other proposals integrate the computation of the word representation in the overall nmt model, either combining information from character level, like those by luong and manning (2016) costa-jussà and fonollosa (2016), from n-gram level, like the one by @xcite , or from multiple granularities like the work by @xcite . some other approaches like those by @xcite and @xcite try to extend this idea to obtain multilingual conceptual representations from character-level representations. nevertheless, in all those approaches, the decoder only has access to the aggregated wordlevel information and not to the original subwordlevel information. this, while mitigating the unknown word problem, cannot handle the scenario where copying from source to target is necessary, like with unseen proper names or with compositional structures like numbers. to the best of our knowledge, this type of neural architectures that condense subword/character-level information into word-level representations have not been used for integrating extra word-level information as an additional input to the model in a translation task. on the other hand, word level information has been injected to subword-based nmt models: sennrich and haddow (2016) copy the word-level linguistic information (e.g. lemma, pos tag) to each of the subwords in a word. such information is used in an embedding and is concatenated with the subword token embedding. in this method, the subwords are also injected information about whether they are the leading subword in a word or they appear in the middle of a sequence of subwords or they are the last subword. ## subword to word transformer in the standard transformer architecture from @xcite , the encoder applies a series of self-attention layers to the input token embeddings. the output of the encoder is then used at every layer of the decoder as key and value of the multi-head attention. in these operations, the token representations in the sequences in the source batch are masked according to the original sequence lengths in tokens. in our first tests we directly used the encoder word representations as keys and values to every decoder layer (instead of using the encoder subword representations in the last layers of the decoder). this, however, led to poor results. we understand that such a configuration made it impossible for the network to properly handle token copying from source to target, which is usually needed in cases of proper nouns or compositional structures like numbers. other possible causes for this degradation could be some mismatch on the encoder side e.g. positional embeddings being subword-based but encoder embeddings being word-level. to test this hypothesis, we added positional encodings after the point where subword representations are combined into word-level representations. this led to no improvement, indicating that the inability to copy was certainly the cause of the degradation. the specific approach chosen to combine subword representations into word representations is a layer of gated recurrent units (gru) @xcite , which receives as input the output of the first encoder block. we take the output of the gru at the positions of the last subword tokens in each word, providing the appropriate padding positions to handle the minibatch sequences. this way, the lengths of the sequences in the batch are now the number of word tokens in each sentence. other subword-to-word combination approaches tested during the early stages of this work included using long-short term memories (lstm) @xcite and simply adding all subwords within each word. the proposed approach provides a natural point to incorporate word-level information: after the subword-level representations have been combined into word-level ones. this way, as shown in figure 1 , the extra word-level information is embedded into a vector space and added to the word-level representations of the source sentence, after the word-to-subword combination. note that, while applying this approach to the encoder part is straightforward, applying it to the decoder presents a key challenge: at inference time, the target side tokens are generated one by one, which implies that it is not possible to combine all of the subword tokens of a word until they have all been generated. ## experimental setup we understand that there are two desirable properties for the proposed word-subword combination model: to be able to retain the translation quality obtained with the analogous subword-based model and to be able to better profit from word-level information than other approaches. in order to verify that the translation quality is retained, we performed experiments on the iwslt14 english-german data, both in @xmath0, with a bpe shared subword vocabulary with 10k merge operations. we studied the resulting translation quality with different hyperparameter sets in order to understand their effect on the model. in order to study the effectiveness of the proposed model with other approaches to incorporate word-level information into a subword-based model, we used the wmt16 english-romanian data with the back-translated synthetic data from @xcite , using a shared subword vocabulary of 40k merge operations. we used the proposal by @xcite as baseline, and compared it to a vanilla transformer baseline and to our proposed method. for all experiments, we used the fairseq library @xcite , either with its built-in models for the baselines or with custom model implementations for the approach by @xcite and for our own proposed architecture. for the iwslt14 de-en and en-de baselines we used the transformer architecture @xcite with the hyperparameters proposed by the fairseq authors foot_0 , namely 6 layers in encoder and decoder, 4 attention heads, embedding size of 512 and 1024 for the feedforward expansion size, together with dropout of 0.3 and a total batch size of 4000 tokens, using label smoothing of 0.1. for the wmt16 en-ro baseline we used the base configuration of the transformer model offered in fairseq, that is, 6 layers in encoder and decoder, 8 attention heads, embedding size of 512 and 2048 for the feedforward expansion size, together with dropout of 0.1 and total batch size of 32000 tokens, without label smoothing (following the baseline used by @xcite ). all reported bleu scores are computed with the model weights averaged over the last 10 checkpoints after training until convergence. ## results we studied the effect of different hyperparameter values over translation quality. we measured the results obtained on the iwslt14 de-en data by using different types of subword combination strategies, as well as combining subwords at different layer levels, chosen arbitrarily. n (e) sw n (d) sw bleu 3 5 33.53 3 3 34.02 5 3 34.46 once determined that using gru as subword combination and setting n (e) @xmath1, we checked whether the proposed architecture maintains the translation quality with respect to a vanilla transformer baseline. as shown in finally, in order to assess our proposed approach at incorporating extra word-level information, we compared it against the approach by @xcite (with the transformer as base architecture), which copies the word level information to each of the subwords in the word; in our implementation, the subword embedding and the linguistic information are combined by adding them together, which is analogous to the original alternative that concatenates them. for the vanilla transformer and the approach by @xcite we used a total batch size of 32000 while for the word-subword model (our proposal), we used a total batch size of 40000, gru as subword combination strategy and n the word-level linguistic information used was only the lemma (using a vocabulary of 40k lemmas), which is the feature that should provide the largest improvement according to @xcite . we used stanford corenlp @xcite to annotate the corpus with the english lemmas. the obtained results are shown in ## conclusion in this work, we proposed a modification to the transformer architecture to merge the subword representations from the first layers of the encoder into word-level representations. merging wordlevel representations inside the model allows it to use the subword-level representations in the final decoder layers so that it can handle compositional structures and other situations where copying from source is needed. this approach provided an appropriate point to incorporate linguistic word-level information and it is superior at doing so compared with the reference approach by @xcite . future extensions to this work may include applying it to character-level instead of subword representations, and using it for morphologically richer languages, especially low-resourced agglutinative ones, where our approach, together with the incorporation of linguistic information, may provide larger improvements in translation quality. further extensions may include studying the behavior of more powerful subword combination strategies (e.g. convolutions, self-attention) and the application of subword merging to the target side.