The problem
Machine translation, on its own, translates each sentence in isolation. It doesn't know the company has translated a near-identical clause a hundred times before in a specific way, for a specific regulatory reason — or that a product name has exactly one approved Chinese rendering and every other one is wrong. Point a generic translator at a new document and the output is fluent but inconsistent with everything already published.
The brief: build a pipeline that pulls from the company's own translation memory (TMX) and glossaries before generating anything, so a document translated today reads consistently with one translated a year ago — not like it went through a different translator each time.
Retrieval before translation
This is a RAG pipeline where the thing being retrieved isn't a knowledge-base passage, it's a prior translation decision. Four retrieval strategies run per chunk, each covering a gap the others miss, before the translation engine (Google NMT or an LLM, depending on which the accuracy assessment favors for that content type) ever sees the text.
Four strategies, one precedence rule
Difflib in practice
Both steps use Python's difflib.SequenceMatcher: ratio() for the fuzzy top-n ranking, find_longest_match() for the tie-break.
Chunking a .docx without touching its structure
Each chunk is one paragraph's full text — enough context for the model to produce coherent English→Chinese grammar, since word order shifts across the two languages in ways that per-run fragments can't capture. The write-back stays inside that paragraph's own runs, so the document's XML — styles, tables, headers — is never rebuilt, only the text inside existing runs changes.
The flow, end to end
Load docx → chunk per paragraph → retrieve context → translate → write back into the original runs → repeat to the end of the document.
Evaluating translation quality
Building the retrieval pipeline was one problem; proving which translation approach actually performs best for this document type was another. Alongside it, I helped build an evaluation framework that scores candidate translation engines head-to-head on a held-out set of real documents, across five metrics that each catch something the others miss.
LLM-as-a-judge, roughly
The judge gets the original, the human reference, and the candidate translation side by side, and scores the candidate on accuracy and fluency independently — deliberately not just "does it match the reference," since a translation can be faithful and fluent while still wording things differently than the reference did.
Ranking with the same Bradley-Terry approach
Rather than average scores across documents, each pair of translation methods is compared head-to-head on the same document, per metric — the same Bradley-Terry ranking approach used for LLM benchmarking, reused here to turn per-document scores into a single relative ranking per metric.
Where it's headed
This isn't a one-time comparison — as new translation approaches and newer LLMs show up, the plan is to re-run the same evaluation framework against them, so a model's fit for this use case stays a question that gets re-asked, not one answered once and left to age.
From POC to production
The retrieval pipeline and evaluation above settled which approach to use — turning that into something other systems can rely on was a separate step. Once the POC proved out, it handed off to MSD's Central AI team, who own productionizing it: hosting, scaling, and exposing it as a shared API rather than something every consuming app has to embed on its own.
Extending the proof of concept
- A self-evolving translation memory. Exploring automatically updating TMX entries from post-translation edits, so a human correction today improves retrieval for every document translated after it — instead of the same mistake recurring.
- RLHF into the pipeline. Investigating how reinforcement learning from human feedback fits into the translation step itself, including whether DPO is a feasible route given the volume of edit data available.
- Open-source models as an alternative engine. Assessing feasibility and accuracy of models such as TranslateGemma, with RLHF integration, against the Google NMT / LLM comparison already done.