Skip to content
Back to projects

AI Engineering

MarianMT medical translation (En-Ar)

Fine-tuned transformer translation models for English-Arabic medical text, trained end to end in both directions with a memory-efficient inference path.

The code is private, so this page covers the engineering approach only.

PythonPyTorchHugging Face TransformersMarianMTSentencePiecesafetensors

Problem

General-purpose machine translation handles medical text poorly: clinical terminology, drug names, and dosage phrasing are exactly where a generic model drifts, and English-Arabic is a lower-resource direction than English-European pairs. The goal was a translation model adapted to medical-domain text in both directions, English to Arabic and Arabic to English, that runs within a bounded memory footprint for deployment.

How it works

The work fine-tunes MarianMT, a transformer encoder-decoder for neural machine translation, from a pretrained checkpoint on medical-domain parallel text. Each translation direction is trained as its own model, so the two directions can be tuned and served independently. The fine-tuning script handles tokenization through the Marian SentencePiece vocabularies, the training loop, and export of the trained weights as safetensors.

For serving, a memory-efficient translator and an optimized translator load the fine-tuned weights and run inference with a reduced footprint, and an upload path pushes the trained models to the Hugging Face Hub.

Medical parallel text (En/Ar)
   -> MarianMT pretrained checkpoint -> fine-tune per direction (PyTorch)
   -> trained weights (safetensors) : en-ar-medical, ar-en-medical
   -> memory-efficient / optimized translator -> inference

Hard parts

  • Two directions as two models: English-to-Arabic and Arabic-to-English are fine-tuned separately from the pretrained Marian checkpoints, each with its own tokenizer and trained weight set.
  • Memory-bounded inference: a memory-efficient translator and a separate optimized translator load the fine-tuned weights and run with a reduced footprint for deployment rather than loading the full training-time stack.
  • Reproducible training data: a subtitle-corpus preparation step builds the medical parallel text the fine-tune runs on.
  • Portable artifacts: trained models export as safetensors with their tokenizer and generation configs, and an upload path publishes them to the Hugging Face Hub.

Results

Both translation directions were trained end to end and the fine-tuned weights are saved as deployable models, each roughly 300 MB with its tokenizer, generation config, and SentencePiece vocabularies. A test harness runs the fine-tuned models on held-out input, and both a memory-efficient and an optimized inference path are implemented for serving. This is domain-adaptation research rather than a benchmarked system; no formal BLEU evaluation is claimed here.

Artifacts

A fine-tuning pipeline (data preparation, training script, model loader), two sets of trained MarianMT weights for the two translation directions exported as safetensors, memory-efficient and optimized inference translators, a test script, and a Hugging Face Hub upload path.

Back to projects