Abstract
Neural Machine Translation (NMT) often requires enforcing specific lexical or structural constraints, such as industry-specific terminology or markup tags. Traditional approaches to constrained NMT typically suffer from either significant inference latency or inconsistent constraint satisfaction. This paper introduces a novel template-based framework that disentangles the arrangement of constraints from the generation of free text. By reformulating the task into template generation and derivation sub-tasks, the proposed method achieves 100% constraint match accuracy and superior translation quality while maintaining the inference speed of unconstrained NMT models.
Introduction
In practical translation scenarios, NMT models are frequently required to adhere to external constraints. These include lexical constraints, such as brand names or technical jargon, and structural constraints, such as HTML or XML tags that must be preserved for proper document formatting.
Existing solutions generally fall into two categories, both of which have significant drawbacks:
- Constrained Decoding: Algorithms like Vectorized Dynamic Beam Allocation (VDBA) force the inclusion of specific tokens during inference. While highly accurate, they are computationally expensive and often result in lower translation quality due to rigid decoding paths.
- Data Augmentation: These models are trained on synthetic data to learn constraint following. While they maintain high inference speeds, they often fail to satisfy constraints in complex or long-form sentences.
This research seeks to achieve the "holy grail" of constrained NMT: high translation quality, 100% match accuracy, and low latency.
Methodology: The Template-Based Framework
The core innovation of this work is the decomposition of the translation task into two distinct sub-tasks handled within a single sequence-to-sequence framework:
- Template Generation: The model first generates a "plan" or template. It places the provided constraints in their grammatically correct order while abstracting the remaining parts of the sentence into nonterminal placeholders (e.g., $Y_0, Y_1$).
- Template Derivation: The model then fills these nonterminals with the appropriate natural language tokens to complete the sentence.
Implementation via Data Formatting
Notably, this method does not require modifications to the underlying Transformer architecture. Instead, it leverages a specialized data format. The input sequence consists of source constraints, the source template, and source free tokens, separated by a <sep> delimiter. The output sequence contains the target constraints, the target template, and the derivation rules for the placeholders. This allows the model to be trained and deployed using standard, highly optimized NMT software.
Experimental Setup
The authors evaluated the framework on two primary tasks:
- Lexical Constraints: Tested on WMT17 English-Chinese (20.6M pairs) and WMT20 English-German (41.0M pairs). Constraints were simulated by sampling phrases from a phrase table.
- Structural Constraints: Tested on a dataset covering English to French, Russian, Chinese, and German, focusing on the preservation of XML-style markup tags.
Key Results
The template-based method demonstrated significant improvements across all key metrics:
- Constraint Accuracy: The model achieved near-perfect (100%) exact match accuracy for constraints in almost every test scenario, outperforming data augmentation baselines.
- Translation Quality: The method outperformed strong baselines like VDBA and TextInfill. For English-Chinese, it achieved a BLEU score of 47.5, compared to 42.7 for the vanilla unconstrained model.
- Inference Speed: The model maintained a speed of 3390 tokens per second, which is virtually identical to the vanilla model (3392 tokens/sec). This represents a massive speedup over traditional constrained decoding methods.
- Automatic Reordering: A significant advantage of this approach is its ability to learn constraint reordering. If source constraints appear in one order but the target language grammar requires another, the template generation phase handles the reordering automatically.
Conclusion and Future Work
The template-based approach successfully bridges the gap between accuracy and efficiency in constrained NMT. By separating the structural arrangement of constraints from the creative generation of text, the model provides a robust solution for real-world translation tasks without architectural overhead.
One current limitation is the handling of "one-to-many" constraints, where a single source phrase might have multiple valid target translations. Future research will focus on allowing the model to choose the most appropriate synonym from a set of provided options and extending the framework to other tasks like abstractive summarization and table-to-text generation.
Summary updated