{'fraction_non_alphanumeric': 0.030494172688917666, 'fraction_numerical': 0.00891850119052592, 'mean_word_length': 4.8176184690157955, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 4, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 11, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
TranSmart: A Practical Interactive Machine Translation System

Automatic machine translation is super efficient to produce translations yet their quality is not guaranteed. This technique report introduces TranSmart, a practical human-machine interactive translation system that is able to trade off translation quality and efficiency. Compared to existing publicly available interactive translation systems, TranSmart supports three key features, word-level autocompletion, sentence-level autocompletion and translation memory. By word-level and sentence-level autocompletion, TranSmart allows users to interactively translate words in their own manners rather than the strict manner from left to right. In addition, TranSmart has the potential to avoid similar translation mistakes by using translated sentences in history as its memory. This report presents major functions of TranSmart, algorithms for achieving these functions, how to use the TranSmart APIs, and evaluation results of some key functions. TranSmart is publicly available at its homepage (https://transmart.qq.com).


Introduction
Recent years have witnessed a breakthrough in automatic machine translation, thanks to the advances in neural machine translation (NMT) [1,2]. The key idea in NMT is an encoder-decoder framework where a source sentence is represented by an encoder network and a target sentence is generate by an decoder network [3,4]. By using a large-scale bilingual corpus, both encoder and decoder networks consisting of massive parameters can be trained sufficiently enough to yield excellent generalization ability on unseen sentences. As a result, NMT delivers state of the art performance in many machine translation benchmarks [5,6,7].
To the date, however, even a state-of-the-art NMT system is incapable of meeting the strict requirements in some translation scenarios, where human translation is still intensively involved even if it is inefficient and costly [8,9,10]. Therefore, interactive machine translation (IMT) [11,12], which is believed to better trade off translation quality and efficiency, has drawn increasing attention [13,14,15]: At each time a user corrects a translation, the machine automatically generates a new translation based on the human corrections until the translation process is finished [16]. Compared to automatic machine translation, an interactive machine translation system includes more components and it is more complicated in essence. During the past decade, there were a few IMT systems available, for instance, TransType [17], CASMACAT [18], and LILT 2 which are either on top of statistical machine translation [19,20,21] or the advanced NMT. All these systems share a common characteristic: they perform translation in an incremental In this report, we describe a new human-machine interactive translation system, TranSmart, which was first made publicly accessible in 2018. Compared with other IMT systems, one advantage of TranSmart is its flexibility in the sense that users can employ any translation manners to interact with the machine rather than the incremental manner from left to right. Therefore, if some users prefer to translate difficult words first and then easy words, TranSmart is able to conduct interactive translation in their own manners, as shown in Figure 1 (b & d). Moreover, TranSmart includes an NMT engine augmented with translation memory, and it is very helpful to translate a document where similar translation errors may occur for an automatic machine translation engine. To the best of our knowledge, TranSmart is the first interactive neural machine translation (INMT) system which makes use of translation memory.
Specifically, TranSmart provides three key features as follows: • Word-level autocompletion: At word level, in order to input a correct word, users do not need to type all characters of this word from scratch but a few characters instead, and then the system can automatically complete this word. Unlike other INMT systems, the corrected word is not necessary to be adjacent to the translation prefix.
• Sentence-level autocompletion: At sentence level, users do not need to translate all words from scratch but provide some of them (for instance, some difficult words), and then the system can automatically complete the translation based on user provided words. Different from other INMT systems, user provided words can be discontinuous.
• Translation-memory-augmented NMT: The system is able to re-use translation results from users through translation memory and offers better translation. As there may be several similar sentences in a document to be translated, the system can efficiently avoid the occurrence of similar translation errors thanks to the knowledge from translation memory.
By repeatedly leveraging these key features, TranSmart is able to interactively collaborate human and a machine to generate a high-quality translation in an efficient way. In addition, TranSmart provides some extended features, including terminology translation, bilingual sentence examples, document translation, tag-preserving translation, and image translation. In the remaining part of this report, we first present our implementation of the key modules of TranSmart. Then the TranSmart API is briefly introduced. Finally, the effectiveness of some functions is demonstrated through empirical experiments.

System Features
At high level, TranSmart contains three key features as well as several extended features as shown in the left side of Figure 2. This section describes the basic ideas of these features, whose detailed implementations will be given in the next section.  Figure 2: Overview of the TranSmart system.

Key Features
Word Level Autocompletion Given a source sentence, a translation context consisting of translation pieces, and a human-typed character sequence, word level autocompletion aims to predict a target word which is compatible with the typed sequence. With the help of this feature, if a user is expected to type a target word to correct a translation, it is not necessary to manually type all the characters but only some of them. This feature is inspired from recent advances [22] in input methods from monolingual scenario which are designed to improve the efficiency of human input.
Sentence Level Autocompletion Given a source sentence and a translation context, sentence-level autocompletion aims to generate a complete translation for the source sentence on top of the context. The translation context can be human typed words (with or without word level autocompletion), or human-edited translation pieces from a translation generated by the system. With this feature, a user does not need to manually translate all words from scratch but some of them which are usually difficult to the system, and then the system tries to complete the translation by generating the remaining words automatically.
Memory-Aware Machine Translation Memory-Aware Machine Translation aims to generate high-quality translation by making use of translation memory. Users can provide their own domain-specific translation data to our system as the memory or we can use our bilingual training corpus as the memory. In addition, after users finish translating a sentence, we have a mechanism to accumulate their translation history into the memory. In this way, our system has the ability to avoid the same translation errors occurring multiple times, and this feature is useful in translating a document where there are similar sentences.
The above three key features can be used as atomic operations, which can be applied multiple times to interact between the user and machine for a translation task. For example, by repeatedly leveraging word level autocompletion and sentence level autocompletion, TranSmart can generate a complete translation for a source sentence with high-quality, by using the memory-aware translation engine where translation memory is accumulated from translation history of users. It is worth noting that the translation pieces in the translation context may be discontinuous, and thus our word level and sentence level autocompletion is more general and flexible than those in existing INMT systems.

Extended Features
Document Translation This feature is used to translate a formatted document in a source language to a corresponding formatted document in a target language. It supports many popular formats including TXT, HTML, XML, MARKDOWN, PDF, DOCX, PPTX and XLSX. To this end, it generally performs two steps as follows. First, it parses the input formatted document into a text document consisting of sentences with several tags. Each tag may indicate some structural information such as a paragraph or a font. For example, a sentence in the formatted document may be "<style text-fill="red">Forrest Gump</style> is a 1994 American drama film", where "<style text-fill="red">Forrest Gump</style>" indicates the phrase Forrest Gump is with red color as its format. Second, it translates each tagged sentence by the automatic translation engine with a specially designed technique, which is named tag translation. Tag translation is crucial to document translation and we will present its challenges and our solution in the next section.
Image Translation This feature aims to translate text contained in an image file in a source language to a text document in a target language. It supports many popular image formats such as JPG and PDF. Generally, it is implemented by a pipeline procedure consisting of two steps as follows. First, it employs an external OCR toolkit to extract a text document where any content beyond text is ignored. Second, it uses our translation engine to translate all sentences in the text document one by one. The first step, which is called text extraction from image, is critical to image translation and we will present its challenge and the technique to address in next section.
Terminology Translation We collect more than 3 million of Chinese-English terminologies from websites. However, this corpus contains a large amount of noises, including non-terminology, unaligned, inconsistent format. We filter nonterminology words by considering the word frequency due to the long-tail property of terminology. More specifically, we built a phrase table from a large-scale parallel data and then extract high-frequency phrase pairs as a non-terminology list. Finally, we filter noises by comparing the stop list and collected data [23]. Furthermore, we employ our inhouse filtering scripts [24] to filter unaligned terms according to various features such as length ratio and language identification. As a result, we obtained a clean version of terminology corpus that contains around 2 million terms.

Bilingual Examples
The input sentence is used to retrieve bilingual examples from the corresponding retrieval repository. We selected and used more than 200M bilingual sentences to build the retrieval repository. The three most similar bilingual examples are displayed to help users to translate the input sentence.
3 Implemented Techniques

Generic Translation Model
Translation Model We implemented the generic translation model on top of the Transformer architecture [1]. To balance the translation performance and inference efficiency, we used a 24-layer encoder and a 6-layer decoder, whose hidden size is 1024. We trained the translation model on our in-house data after the following data manipulation methods, which consists of 200 millions of Chinese-English sentence pairs. We followed [25] to train models with batches of approximately 460k tokens, using Adam [26] with β 1 = 0.9, β 2 = 0.98 and = 10 −8 .  Data Rejuvenation Large-scale parallel datasets lie at the core of the recent success of NMT models. However, the complex patterns and potential noises in the large-scale data make training NMT models difficult. We introduce data rejuvenation to improve the training of NMT models on large-scale datasets by exploiting inactive examples [27]. The proposed framework consists of three phases, as shown in Figure 3. Data Augmentation Although we have large-scale parallel data, there are limited amount parallel data for some specific domains. Data augmentation methods (e.g. self-training and back-translation) are a promising way to alleviate this problem by augmenting model training with synthetic parallel data. The common practice is to construct synthetic data based on a randomly sampled subset of large-scale monolingual data, which we empirically show is sub-optimal. In response to this problem, we improve the sampling procedure by selecting the most informative monolingual sentences to complement the parallel data. To this end, we compute the uncertainty of monolingual sentences using < l a t e x i t s h a 1 _ b a s e 6 4 = " D + T g s s L d 7 the bilingual dictionary extracted from the parallel data. Intuitively, monolingual sentences with lower uncertainty generally correspond to easy-to-translate patterns which may not provide additional gains. Accordingly, we design an uncertainty-based sampling strategy [28] to efficiently exploit the monolingual data for self-training, in which monolingual sentences with higher uncertainty would be sampled with higher probability.

General Word-level Autocompletion
Task Definition Word-level autocompletion aims to complete the target word based on human typed characters for a given a source sentence and translation context. Previous studies have explored word-level autocompletion task, but they either do not take into account translation context [29] or they require the target word to be the next word of the translation prefix [17,30], which limit its applications in real-world scenarios such as post-editing [31]. To this end, we propose a general word-level autocompletion task which can be applied to more general scenarios.
Suppose x=(x 1 , x 2 , . . . , x m ) is a source sequence, s=(s 1 , s 2 , . . . , s k ) is a sequence of human typed characters, and translation context is denoted by c=(c l , c r ), where c l =(c l,1 , c l,2 , . . . , c l,i ) and c r =(c r,1 , c r,2 , . . . , c r,j ). The translation pieces c l and c r are on the left and right hand side of s, respectively. Formally, given a source sequence x, typed character sequence s and a context c, the general word-level autocompletion (GWLAN) task aims to predict a target word w which is to be placed in the middle between c l and c r to constitute a partial translation. Note that c l or c r may be empty in some scenarios.
Methodology Given a tuple (x, c, s), our approach decomposes the whole word autocompletion process into two parts: model the distribution of the target word w based on the source sequence x and the translation context c, and find the most possible word w based on the distribution and human typed sequence s.
In the first part, we propose a word prediction model (WPM) to define the distribution p(w|x, c) of the target word w.
We use a single placeholder [MASK] to represent the unknown target word w, and use the representation of [MASK] learned from WPM to predict it. Formally, given the source sequence x, and the translation context c = (c l , c r ), the possibility of the target word w is: where h is the hidden representation of decoding state with respect to [MASK], φ is a linear network that projects the hidden representation h to a vector with dimension of target vocabulary size, and softmax(d)[w] takes the component regarding to w after the softmax operation. Our model has a source encoder and a cross-lingual encoder. The source encoder of WPM is the same as the Transformer encoder, which is used to encode the source sequence x. The output of source encoder is passed to the cross-lingual encoder later. The cross-lingual encoder is similar to the Transformer decoder, while the only difference is that we replace the auto-regressive attention layer by a bidirectional masked attention (BMA) module, which is shown in Figure 4.
Suppose s denotes a human typed sequence of characters, in the second part, we predict the best word according to the constrained optimization: where V(s) denotes a set of target words, whose element satisfies the sequences of s, for example, c is a prefix of w.
More details can be found in [32].
Data Generation For training and evaluating GWLAN models above, firstly we should create a large scale dataset including tuples of (x, s, c, w). Ideally, we may hire professional translators to manually annotate such a dataset, but it is too costly in practice. We instead propose to automatically construct the dataset from parallel datasets.
Assume we are given a parallel dataset {(x i , y i )}, where y i is the reference translation of x i . We automatically construct the data c i and s i by randomly sampling from y i . Specifically, we first sample a word w = y i k , and sample two spans and c r = y i ar , · · · , y i br−1 . It is worth mentioning that c l or c r may not be adjacent to y i k . In addition, we randomly sample a character sequence as s i k for y i k as follows: for languages like English and German, s i k is a character prefix of y i k ; for languages like Chinese, s i k consists of the first phonetic symbol of each character in y i k . In this way, we can obtain a collection of {(x i , c l , c r , s i k , y i k ) | ∀i, ∀k}, which can be divided into training, validation and test datasets for the GWLAN task.

Sentence-level Autocompletion by Lexical Constraints
In our human-machine interactive translation scenario, human translators may pre-specify some constraint words (or lexical constraints) and our system requires to output a high-quality translation with knowledge from these pre-specified constraints. For example, the constraints can be typed by human translators through word level autocompletion in Section 3.2, and they can be a translation prefix corrected by translators, or a post-edited partial translation. It is worth noting that the constraints are not necessary to be continuous [33], unlike [34,13]. In TranSmart, we implement two different approaches to incorporate these constraints into NMT. The first one relies on constrained decoding which requires the output translation to include constraints in a hard manner; whereas the second one makes use of them in a soft manner, i.e., the output translation may not include some of constraints.
Constrained Decoding Constrained decoding is essentially a constrained optimization problem, and it aims to search the translation which satisfies some constraints and is with the best model score. Formally, suppose P (y | x) is a translation model, and c denotes a set of constraint words.
where Y(c) denotes a set of translation hypotheses which include all constraint words in c. To address this constrained optimization problem, [35] proposed a grid beam search algorithm (GBS). This algorithm maintains a beam along two dimensions, where one is the length of the hypotheses and the other is the number words in all constraints. Thus, its complexity is linear to the number of the constraint words, which is inefficient in our interactive scenario. [36] presented an improved algorithm by dynamic beam allocation (DBA) which allows hypotheses in a beam to contain different number of constraint words. In our experiments, this improved algorithm is indeed more efficient in decoding speed but its translation quality is worse than grid beam search. To this end, we propose a variant of grid beam search algorithm to achieve a trade-off between quality and efficiency.
In our interactive scenario, we observe that constraint words in c exhibit two characteristics: some of constraints in c are consecutive to form a translation piece, especially when the size of c is very large; and c provided by human translators is placed in a fixed order such that the output translation should contain c in the same order. Based on the observation, we organize a beam along the length of hypotheses and the number of constraint pieces rather than constraint words. Thanks to the fixed order of pieces, any translations with the same number of pieces will naturally contain the same number of constraint words and thereby they can be fairly pruned in terms of model scores, similar to the grid beam search algorithm. Consequently, the complexity of this algorithm is linear to the number of pieces rather than the number of constraints, which leads to substantial speedup in practice because constraint pieces usually are long enough.
NMT with Soft Constraints Unlike constrained decoding, we propose a new approach to make use of pre-specified constraints in a soft manner. The key is to treat the constraints as an external memory, integrate the memory into the standard Seq2Seq decoder [3,4] and then train the memory-augmented NMT from a dataset such that it learns to constrain the output. Specifically, given x, c and a translation prefix y <t , we generate a target word y t according to P (y t | x, y <t , c; θ). Our model includes three components: the encoder of vanilla NMT model which encodes x into a Src: Esta enmienda no afecta la versión inglesa.

Source Encoding
Target Side Self Attn.

Encoder-Decoder-TM Encoding
This amendment does not … TM  sequence of hidden vectors; the Constraint Memory Encoder (CME) that encodes the constraints c into another sequence of hidden vectors E(c), i.e., the constraint memory; and the Constraint Memory Integrator (CMI), which integrates the constraint memories into the decoder network to generate the next token y t . To train the memory-augmented model, we create a dataset from available bilingual corpus. We randomly sample some rare words from the reference r as constraints, since rare words are more difficult to translate than other words [14].
In inference, our decoding is an unconstrained optimization problem: To approximately solve the above optimization problem, we employ the standard beam search algorithm which is similar to the decoding in our baseline model. Although we need additional overheads to handle the constraint memories, this is negligible to the time consuming of the decoding in NMT. Thus, its search is as efficient as the search algorithm of the standard NMT. In addition, unlike constrained decoding, the method does not force a feasible y to include all constraints in c. Hence, if the constraints in c include some noises (i.e., spelling mistakes), it has the potential to avoid copying these noises. More details about this function can be found in [37].

Graph based Translation Memory
The basic idea of translation memory based MT is to translate an input source sentence by using the translations of the source sentences which are similar to the input one, which is related to domain adaptation [38,39,40]. Suppose we are given a translation memory (TM) for a source sentence which is a list of bilingual sentence pairs. Generally, there are two ways to improve translation models with translation memory: training model parameters with augmented data (i.e., memory) [41,42,43] and summarizing knowledge from translation memory to augment MT decoder [44,45,46]. For the latter idea, a typical solution to represent a TM is to encode each word in both the source and target sides by a neural memory [44]. Unfortunately, since a word even a phrase may appear repeatedly in a TM, redundant words are encoded multiple times, leading to a large memory network as well as considerable computation. To address this issue, we propose an effective approach to representing a TM with a compact graph structure, which is further used to enhance the translation model. The model structure is illustrated in Figure 5 and its more details can be found in [47].
Graph Representation of TM It is observed that most source words in the TM also appear in the input sentence and have already been represented by the encoder. In addition, we believe that those words in the TM yet beyond the source side may not be informative to translate the input sentence itself. Therefore, in our proposed model, we directly ignore the source sentences of the TM and only represent the target side. In addition, instead of sequentially encoding target sentences in a TM, we pack them into a compact graph such that some words in different sentences may correspond to the same node in the graph, which is inspired by the notion of lattice or hypergraph in statistical machine translation [48,49]. To this end, we convert the target side in a TM into a confusion network by using the algorithm proposed by [50] and [51].
NMT with Graph based TM The graph based TM is further used to enhance the Transformer architecture. Generally, the enhanced Transformer shares the similar architecture as Transformer but with two major differences in encoding and decoding phases.
In the encoding phrase, besides encoding the input sequence, the proposed model also encodes the graph by using L layers of networks in a similar fashion to the encoding of the input. Specifically, we firstly use a multi-head attention to encode each node in the TM graph where the query is the corresponding node, and key-value pairs are obtained from its first-order neighborhood nodes inspired by graph attention [52]. Then we apply other sub-layers to the resulting vector obtained by the multi-head attention layer, which contain a residual layer, a feed-forward layer and a layer normalization. In this way, we can represent the graph into a list of vectors whose size is the same as the number of nodes in the graph.
In the decoding phase, similar to Transformer, the proposed model employs L layers of networks but each layer includes sub-layers (i.e., multi-head attention, residual layer and layer normalization) to incorporate the list of vectors obtained from graph encoding, besides other six sub-layers. We place the extra three sub-layers nearest to the output of the decoder network in order to let the graph encoding fully influence the decoding process.

Others
Word Alignment Word alignment plays an important role in document translation for TranSmart. Since NMT is a blackbox model with massive parameters, previous work has made numerous efforts to induce word alignment from attention in NMT [53,54,55] or other explanation methods [56,57,58]. Other work improves alignment quality by building a word alignment model whose architecture is similar to NMT [59]. Despite its success, statistical aligners [60,61] are still respectful counterparts because of their training efficiency and alignment quality. Therefore, we employ statistical aligners to obtain word alignment. As TranSmart involves billion scale of bilingual sentences as its training data, the popular aligner GIZA++ can not train successfully due to memory consumption. Instead, we re-implement an aligner based on HMM [62] with an adaptive strategy to prune the word translation table: for each high-frequency word we allow more words to be its translations whereas we allow less for each low-frequency word.
Tag Translation Tag translation aims to translate a source language with tags into a target language with tags, and it serves as the key step for document translation. Since the standard translation engine are trained on top of bilingual sentences without tags, standard translation engines can not perform well on translating tagged sentences. In addition, there are no sufficient tagged bilingual sentences to train a customized tag translation engine. Therefore, we propose a simple post-processing approach based on word alignment as follows. First, we delete all tags from a tagged source sentence to obtain a tag-free sentence and then translate it into a target sentence by our default translation engine. Then we run our word aligner on both the tag-free sentence and its translation to obtain word level alignments. Second, we insert the corresponding tags from the source sentence into its translation. However, the second step is not straightforward because one tagged piece (or phrase) within the tagged source sentence may align to multiple pieces in the target side due to the essence of word alignment. We propose an algorithm based on dynamic programming to extract a piece-to-piece alignment: the piece-to-piece alignment is a one-to-one map between pieces in the source and target sides such that it makes the minimal violations according to the word alignment results. By using the piece-to-piece alignment, it is trivial to insert the tags from the source sentence into its target sentence.
Text Extraction from Image Text Extraction from Image aims to extract the text content from an image file to form a text document in a source language while ignoring other content. Generally, this task is challenging due to two reasons. First, a sentence in an image file may not explicitly contain a special symbol to indicate its end and several such sentences may actually constitute one sentence. More importantly, OCR may recognize many blocks of text content from an image file to some extent, but it is difficult to organize these text blocks into a text document which preserves the same sequential structure of text blocks as in the original image file. To tackle the first challenge, we develop a language model to detect the end symbol for a sentence without an end symbol. In addition, we design another model to detect whether several sentences without an end symbol should be combined to one sentence. To address the second challenge, we employ the position information of each block from the OCR toolkit and uses it as a signal to decide the sequential order of all blocks, which is critical to form the final text document.
Discourse-Aware Translation Existing translation models usually translate a text by considering isolated sentences based on a strict assumption that the sentences in a text are independent of one another. However, disregarding dependencies across sentences will harm translation quality especially in terms of coherence, cohesion, and consistency [63].
To response this problem, we adapt document-level NMT [64] to document-level training. Specifically, we add bilingual documents and paragraphs to our training data, which can helps models to learn discourse knowledge from larger contexts [65,66]. This works well with the Document Translation Feature as stated in Section 2.2. Chinese is a pro-drop language, where pronouns are usually omitted when they can be inferable from the context. This leads to serious problems for Chinese-to-English translation models in terms of completeness and correctness. Thus, we recover missing pronouns in the informal domain of training data (e.g. conversations and movie subtitles) by leveraging our approaches [67,68,69].

System Usage
Two ways are available to use TranSmart. One way is to visit the website of TranSmart 3 , which has a friendly interactive user-interface (UI). Another way is calling the TranSmart HTTP APIs. The HTTP APIs can be accessed by sending a JSON request to the service 4 via POST method. The major fields of the JSON request of the translation APIs are shown in Table 1. In this section, we will focus more on the latter way and introduce the usage of some selected features.

Word And Sentence Level Autocompletion
One important API is the "dynamic_suggestion" function, aiming to save the effort of human translators when correcting the translation generated by AI. This API is capable of providing autocompletion at both word-level and sentence-level, which will be introduced one by one. First, the word-level autocompletion is able to complete the unfinished word input by human translators. As shown in Figure 6, when the a character sequence "th" is tagged by "editing" in the "segment_list" field, TranSmart will return its autocompletion in the "ime_suggestion" field in response. Second, the sentence-level suggestion can complete the whole translation based on the user-specified spans. As shown in Figure 7, the span with the "prefix" type is promised to be the prefix of the re-generated translation in response, and spans with "std" are forced to be included in re-generated translation. The result of sentence-level autocompletion is in the "sentence_suggestion" field in response.

Memory-Aware Machine Translation
As shown in Figure 8, when users provide the information of translation memory in the "reference_list" field, TranSmart will be able to leverage those existing and relevant translations in history to improve the translation quality. The translation results are in the "auto_translation" field in response. Note that users can also disable this feature by removing the "reference_list" field, then TranSmart will translate only based on the source text, i.e., the setting of traditional automatic translation.

Extended Features
TranSmart also has two APIs that may be helpful for human translators. First, it provides a static_suggestion function to retrieve relevant information from our pre-constructed terminology and bilingual example databases. As shown in Figure 9, the "static_suggestion" function returns the most relevant terminology translations and bilingual examples in the "term_list" and "sentence_example_list" field in response, respectively. Second, our "selection_suggestion" is designed to translate specified spans in a source sentence. As shown in Figure 10, only spans with "selection" status in the "segment_list" field will be translated. The results of selection suggestions are placed in the "segment_suggestion" field in response.

Generic Translation
Datasets We conducted experiments on the widely used WMT14 English⇒German (En⇒De) and English⇒French (En⇒Fr) datasets, which consist of about 4.5M and 35.5M sentence pairs, respectively. 6 We applied BPE [72] with 32K merge operations for both language pairs. The experimental results were reported in case-sensitive BLEU score [73].
Systems We validated our approach on a couple of representative NMT architectures: • LSTM [74] that is implemented in the TRANSFORMER framework.
• TRANSFORMER [75] that is based solely on attention mechanisms. • DYNAMICCONV [76] that is implemented with lightweight and dynamic convolutions, which can perform competitively to the best reported TRANSFORMER results.
We adopted the open-source toolkit Fairseq [77] to implement the above NMT models. We followed the settings in the original works to train the models. In brief, we trained the LSTM model for 100K steps with 32K (4096 × 8) tokens per batch. For TRANSFORMER, we trained 100K and 300K steps with 32K tokens per batch for the BASE and BIG models respectively. We trained the DYNAMICCONV model for 30K steps with 459K (3584 × 128) tokens per batch. We selected the model with the best perplexity on the validation set as the final model.
Results Table 3 lists the results across model architectures and language pairs. Our TRANSFORMER models achieve better results than that reported in previous work [75], especially on the large-scale En⇒Fr dataset (e.g., more than 1.0 BLEU points). [78] showed that models of larger capacity benefit from training with large batches. Analogous to DYNAMICCONV, we trained another TRANSFORMER-BIG model with 459K tokens per batch ("+ Large Batch" in Table 3) as a strong baseline. We tested statistical significance with paired bootstrap resampling [79] using compare-mt 7 [80].
Clearly, our data rejuvenation consistently and significantly improves translation performance in all cases, demonstrating the effectiveness and universality of the proposed data rejuvenation approach. It's worth noting that our approach achieves significant improvements without introducing any additional data and model modification. It makes the approach robustly applicable to most existing NMT systems.

Word Level Autocompletion
Datasets We carry out experiments on four GWLAN tasks including bidirectional Chinese-English tasks and German-English tasks. The training set for two directional Chinese-English tasks consists of 1.25M bilingual sentence pairs from LDC corpora. As discussed in §3.2, the training data for GWLAN is extracted from 1.25M sentence pairs. The validation data for GWLAN is extracted from NIST02 and the test datasets for GWLAN are constructed from NIST05 and NIST06. For two German-English tasks, we use the WMT14 dataset standard preprocessed by Stanford 8 . The validation and test sets for our tasks are based on newstest13 and newstest14 respectively. All the sample operations in the data construction process are based on the uniform distribution. For each dataset, the models are tuned and selected based on the validation set.

Systems
In the experiments, we evaluate and compare the performance of our proposed approach (WPM) and a few baselines, which are illustrated below: • TRANSTABLE: We train an alignment model 9 on the training set and build a word-level translation  • TRANS-PE: We train a vanilla NMT model using the Transformer-base model. During the inference process, we use the context on the left hand side of human input as the model input, and return the most possible words based on the probability of valid words selected out by the human input. This baseline is inspired by [17,30]. • TRANS-NPE: As another baseline, we also train an NMT model based on Transformer, but without position encoding on the target side. While testing, we use the averaged hidden vectors of all the target words outputted by the last decoder layer to predict the potential candidates.
Evaluation Metric To evaluate the performance of the well-trained models, we choose accuracy as the evaluation metric: where N match is the number of words that are correctly predicted and N all is the number of testing examples.
Results Table 4 shows the main results of our method and three baselines on the test sets of Chinese-English and German-English datasets. The method TRANS-PE, which assumes the human input is the next word of the given context, behaves poorly under the more general setting. As the results of TRANS-NPE show, when we use the same model as TRANS-PE and relax the constraint of position by removing the position encoding, the accuracy of the model improves. One interesting finding is that the TRANSTABLE method, which is only capable of leveraging the zero-context, achieves good results on the Chinese-English task when the target language is English. However, when the target language is Chinese, the performance of TRANSTABLE drops significantly. It is clear from the results that our method WPM significantly outperforms the three baseline methods.

Sentence Level Autocompletion
Datasets We conduct experiments on the Zh⇒En, Fr⇒En, De⇒En, and translation tasks. The Zh⇒En bilingual corpus includes news articles collected from several online news websites. After the standard preprocessing procedure as in [70], we obtain about 2 million bilingual sentences in total. Then we randomly select 2000 sentences as the development and test datasets, respectively, and leave other sentences as the training dataset. The Fr⇒En bilingual corpus is from JRC-Acquis datasets [82] and it is preprocessed following [44]. This dataset is a collection of the parallel legislative text of European Union Law applicable in the EU member states and thus it is a highly related corpus focusing on a specific domain. We also evaluate our methods on the WMT 2018 English-German news translation task, which is composed of Europarl and news commentary data [83]. We use the WMT newstest2013 and newstest2014 as the development and test set respectively. In addition, in our experiments, we use the subword technique [72] to ensure that there are no unknown tokens in our input, even if a constraint word is not included in the training set. Therefore, if a human translator provides an unknown word as a constraint word, our system tokenizes it into several BPE tokens which are considered as several constraints accordingly. Since there are no real constraints available provided by human for all these datasets, we simulate this effect by randomly picking some words from the reference side as the constraints following [35,84].
Systems As presented in section 3.3, we implement two methods: constrained decoding with ordered constraints denoted by O-GBS and NMT with soft constraints denoted by SC. We compare both of our methods against three baselines: • TRANSFORMER: It is the standard Transformer, which is an in-house implementation using Pytorch following [85]. • GBS: It is the Grid Beam Search in [35] built on top of the in-house TRANSFORMER.  Table 5: BLEU and runtime comparisons on perfect constraints for the Zh⇒En, Fr⇒En, and De⇒En tasks. The runtime is measured by the time consumed by decoding one sentence on the Zh⇒En task. † indicates the comparison over TRANSFORMER is significant with p < 0.05.
• DBA: It is the lexically constrained decoding with Dynamic Beam Allocation (an improved approach for [35]) in [36] .
To ensure the translation quality, we set the default beam size for GBS and DBA as suggested by [35] and [36]. The hyper-parameters for all the systems are following those of TRANSFORMER base model [1]. We train all the models with Adam optimization algorithm [26] and tune the number of iteration based on the performance of the development set.
Results As shown in Table 5, although the DBA method would reduce the computational overhead compared to GBS, its translation quality slightly sacrifices accordingly, which is similar to the finding in [36]. Thanks to the ordered constraints, the O-GBS is faster than GBS in running speed and delivers the same performance as GBS. The advantage of these three lexically decoding algorithm is that they do not need to retrain a translation model. Moreover, SC performs better than GBS on the Fr⇒En and Zh⇒En tasks and outperforms DBA on all the three tasks, in terms of translation quality. This observation indicates that our model SC is able to learn how to integrate the lexical constraints correctly. Moreover, there is an additional advantage that the decoding speed of our model is comparable with that of the TRANSFORMER model and is much faster than lexically constrained decoding.

Translation Memory
Since there is no translation history provided by human translators, we simply use the training set as the memory for simulation. For each sentence, we retrieve 100 translation pairs from the training set by using Apache Lucene [86]. We score the source side of each retrieved pair against the source sentence with fuzzy matching score and select top N = 5 translation sentence pairs as a translation memory for the sentence to be translated, following [44,45,46]. Sentences from the target side in the translation memory are used to form a graph, with each word represented as a node and the connection between adjacent words in a sentence represented as an undirected edge.
Datasets Following the previous works incorporating TM into NMT models, we use the JRC-Acquis corpus for training and evaluating our proposed model. The JRC-Acquis corpus is a collection of parallel legislative text of European union Law applicable in the EU member states. The highly related text in the corpus is suitable for us to make evaluations. To fully explore the effectiveness of our proposed model, we conduct translation experiments on three language pair bidirectionally, namely, en-fr, en-es, and en-de. We manage to obtain preprocessed datasets from [44]. For each language pair, we randomly select 3000 samples to form a development and a test set respectively. The rest of the pairs are used as the training set. Sentences longer than 80 and 100 are removed from the training and development/test set. The technique of Byte-pair Encoding [72] is applied and the vocabulary size is set to be 20K for all the experiments.

Systems
The proposed graph based TM model is built on transformer [1], and it is denoted by G-TFM. We compare the proposed model against the following baselines: 10 • TFM: It is a natural baseline as the proposed model is directly built upon the Transformer architecture.
• P-RNN: It is an in-house implementation of [45] on top of RNN-search.
• P-TFM: It similar to P-RNN but it is on top of Transformer rather than RNN-search as [45].
• SEG-TFM: It implements the idea of [44]    and z t in [44] are replaced by the hidden units obtained from the multi-head attention over the encoding units and the decoding hidden state units before the softmax operator.
• SEQ-TFM: It sequentially encodes all target sentences in a TM as one of the baseline models. Specifically, each target sentence in TM goes through a multi-head mechanism and an immediate residual connection plus layer normalization in l th layer. The derived representations for these sentences are then concatenated to form the representation of the translation memory, which can be utilized flexibly in l th decoding layer.
For training all systems, we maintain the same hyper-parameters for fair comparison. Besides, we adopt the same training algorithm to learn the models as follows. We use a customized leaning rate decay paradigm following Tensor2Tensor [91] package. The learning rate increases linearly on early stages for a certain number of steps, known as warm-up steps, and decay exponentially later on. We set the warm-up step to be 5 epochs and we early stop the model after training 20 epochs, typically the time when the development performance varies insignificantly. Furthermore, since there is a hyperparameter in the system P-TFM of [45] which is sensitive to the specific translation task, we tune it carefully on the development set for all translation tasks. Its optimized value is 0.7 for es and de tasks while it is 0.8 for fr task. 11 Results Table 6 shows the experiment results of all the systems on the es-en task in terms of BLEU. Several observations can be made from the results. First, the baseline TFM achieves substantial gains over RNN and even outperforms P-RNN by around 1 BLEU point on the test set. Compared with the strongest baseline P-TFM, the proposed SEQ-TFM and G-TFM are able to obtain some gains up to 1.9 BLEU points on the test set. This result verifies that our compact representation of TM is able to guide the decoding of the state-of-the-art model.
Second, it is observed that SEG-TFM is only comparable to TFM on this task, although its RNN based counterpart brought significant gains as reported in [44]. This fact shows that the transformer architecture may need a sophisticated way to well define a key-value memory for TM encoding, which can be significantly different from that on RNN architecture. This is beyond the scope of this paper. Fortunately, this paper provides an easy yet effective approach to encode a TM, i.e. G-TFM, which does not rely on a context-based key-value memory.
Since the retrieval time can be neglected compared with the decoding time as found in [45], we thereby eliminate the retrieval time and directly compare running time for neural models as shown in Table 7. From this table, we observe that the proposed graph based model G-TFM saves significant running time compared with SEG-TFM and SEQ-TFM while achieving better translation performance.  We pick stronger baselines from the es-en task, i.e. TFM and P-TFM, and compare them with the proposed G-TFM model on other 5 translation tasks. Table 8 summarizes their results on both the development and test sets. From this table, we can see that on the test set, G-TFM steadily outperforms TFM by up to 3 BLEU points across all these 5 tasks, In addition, contrast to P-TFM, G-TFM demonstrates better performance by exceeding at least 1 BLEU point across all these tasks except the en-fr task. These results are consistent with the results on es-en task and further validates the effectiveness of integrating graph-based translation memory into the Transformer model.