TL;DR
Standard neural machine translation (NMT) architectures can learn both natural language translation and arithmetic unit conversions simultaneously without external processing scripts. By augmenting training with synthetic conversion tables, parallel text, and context-bridging examples—supported by token-level source factors—a standard Transformer learns to accurately convert units in context without degrading overall translation quality.
What Problem Does This Paper Address?
Real-world localization requires adapting content to cultural norms, including dates, currencies, and units of measurement (e.g., converting miles to kilometers or Fahrenheit to Celsius). Traditional machine translation handles these formal, procedural operations poorly. Typical industry workflows rely on brittle, multi-stage pipelines: regular expressions strip out numerical units, external scripts convert the math, and post-processing stitches the result back into the translated sentence.
Such decoupling fails to capture the subtle interplay between natural language and numbers—for example, knowing whether to translate "approximately 500 miles" as an exact conversion ("ungefähr 804 km") or an appropriately rounded estimate ("ungefähr 800 km"). The authors investigate whether an end-to-end Transformer model can learn these non-trivial arithmetic transformations directly while preserving translation fluency.
Methods
The authors train an end-to-end model using the Sockeye toolkit on a standard Transformer architecture (4 encoder layers, 2 decoder layers, 8 attention heads, 512 hidden dimension). To teach the network both tasks and how to alternate between them, they employ a data-mixture strategy combining three data types:
- Standard MT Data: Parallel sentence pairs to preserve general translation capability.
- Pure Conversion Data (
Conv): Isolated, digit-tokenized mathematical input-output pairs mapping affine ($\text{°F} \rightarrow \text{°C}$) and linear ($\text{mi} \rightarrow \text{km}$) functions. - Localization in Context (
Loc): Parallel sentences where the source contains imperial units and the reference contains the metric equivalent. These act as a "bridge" between translation and arithmetic.
To assist the network with context switching, the authors implement source factors (token-level parallel feature streams) that label whether a token is part of a distance expression, a temperature expression, or general running text, projected as 8-dimensional embeddings concatenated to the token embeddings.
Datasets
- WMT 2019 English$\rightarrow$German: 2.2 million sentence pairs (Europarl and News Commentary) for general MT training. Evaluated on the
news17test set. - Pure Conversion Synthetic Sets: Arithmetic mappings of numbers with 1 to 6 digits (in the range $10^3$ to $10^6$), evaluated at a relative error tolerance of $\pm 10^{-4}$ (0.01%).
- Localization Dataset (
Loc): Sourced by mining open datasets (ParaCrawl, DGT, Wikipedia, OpenSubtitles, and TED talks via OPUS) using regular expressions. The authors extracted 7,000 sentences per function (5,000 train, 2,000 test) and up-sampled up to 30,000 by replacing extracted expressions with synthetic unit pairs. - Challenge Sets: Evaluation sets using real-world sentence frames but replacing numbers with synthetically balanced numbers spanning lengths from 1 to 6 digits.
Key Insights and Ideas
- Transformers can learn arithmetic functions directly: Given isolated digit sequences, the Transformer architecture successfully learns both affine ($x \rightarrow (x - 32) \times \frac{5}{9}$) and linear ($x \rightarrow x \times 1.60934$) functions.
- Different functions learn differently: Temperature conversion behaves like a step function—the model learns it cleanly with just a few thousand examples. Distance conversion is learned continuously as an approximation, requiring roughly two orders of magnitude more data to reach equivalent precision.
- Context data acts as a bridge, not the teacher: Localization data (
Loc) alone is insufficient to learn the underlying arithmetic, while conversion data (Conv) alone fails because the model naively tries to end all sentences with unit symbols. Both are necessary:Convteaches the calculation, whileLocteaches the network when to execute it. - Joint multi-task synergy: Training temperature and distance conversions jointly with source factors speeds up learning for both, suggesting the model develops shared intermediate representations for number manipulation.
Key Results
- High Conversion Accuracy: On the localization test sets, adding 15k
Locexamples and 100kConvpairs raised conversion accuracy from near-zero (0–3.4%) up to 88.0% for distance and 77.8% for temperature (using source factors). - No Translation Penalty: BLEU scores on the
news17translation benchmark remained stable across configurations (varying between 22.6 and 23.2 BLEU), proving that mathematical multitasking does not degrade generic translation quality. - Approximation Disparity: When evaluated on exact matches (0.0% tolerance), temperature accuracy stayed largely unchanged, whereas distance conversion accuracy dropped by up to 30%, confirming distance is modeled via numerical approximation rather than lookup-like rules.
Limitations and Future Work
- Narrow Scope of Phenomena: The study only examines two specific conversions (mi $\rightarrow$ km, °F $\rightarrow$ °C) on a single language direction (En$\rightarrow$De).
- Interpolation vs. Extrapolation: The models were evaluated strictly within the interpolation range (1–6 digits); they were not tested on numbers orders of magnitude larger than those seen during training.
- Stylistic Rounding Not Implemented: Although the paper opens with the problem of translating approximate phrases ("approx 500 miles" to "approx 800 km"), experiments evaluated adherence to precise mathematical conversions rather than context-dependent rounding.
- Future Directions: The authors plan to build broader localization evaluation suites and explore whether unsupervised pre-training (e.g., large pre-trained language models) can inherently facilitate numerical representations.
Summary updated