Machine Translation with Latent Reasoning
This repository contains the code, data recipes, and experiment pipeline for training machine translation systems with latent reasoning looped language models for the paper: LatentMT: Machine Translation with Latent Reasoning.
- Overview of the pipeline
- 1. Environment setup
- 2. Running experiments
- 3. Reproducing the experimental results
The pipeline has three stages that are launched from two entry points:
- Train and Inference are launched together by the single public launcher
src/entrypoint_of_entrypoint.sh. It sweeps over the recurrent-depth values inUT_STEPS_VALUES, and for each one submits a training Slurm job followed by an inference job that depends on it. Each inference run id is appended to a manifest file (eval_run_ids.txt) as it is launched. - Evaluation is launched separately from
src/entrypoint_eval.sh. It reads the run-id manifest, computes CPU metrics (BLEU / chrF) locally, and submits a GPU Slurm job for COMET scoring.
The setup script src/prepare_env/run.sh creates virtual environments and downloads all required models.
export HF_TOKEN=YOUR_HF_TOKEN
bash src/prepare_env/run.shEach dataset is prepared from its original source as follows:
| Dataset (registry key) | Direction | Recipe |
|---|---|---|
drtMetaphorTrans |
English→Chinese | data/DRT/README.md — copy the MetaphorTrans train/val/test JSONL from the DRT repo. |
ArzEnMultiGenre |
English→Egyptian Arabic | data/ArzEn-multiGenre/README.md — download from Mendeley Data and run processing.py. |
oldi_flores200_eng_Latn-* |
English→(many) | data/OLDI_seed_Flores200/README.md — download FLORES-200 + OLDI-seed and run hf_to_jsonl.py. |
All training + inference runs go through the single public launcher src/entrypoint_of_entrypoint.sh.
Run it from the repository root.
To run your own experiments, change the environment variables you pass to the launcher. The most common knobs:
- Dataset — set
TRAIN_DATASET_NAME/INFER_DATASET_NAMEto any registry key. - New datasets — to train on a dataset that is not already registered, write its train/validation/test splits as JSONL where each row has
id,text(source),trans(reference translation), and ametadataobject. Then register them by adding aDatasetSpecentry toDATASET_REGISTRYinsrc/dataset_preparer.py. - Recurrent-depth sweep —
UT_STEPS_VALUESis a comma-separated list of recurrent depths to sweep (e.g.UT_STEPS_VALUES=2,4,6). - Training —
EPOCHS,PER_DEVICE_TRAIN_BATCH_SIZE,GRADIENT_ACCUMULATION_STEPS, and the LoRA knobsLORA_R,LORA_ALPHA,LORA_DROPOUT. - Inference —
PIPELINE_INFER_MODE(lorato use the trained adapter, orbasefor the base model),SHOT_MODE(zero,few, orboth),NUM_SHOTS,TEMPERATURE,TOP_P,DO_SAMPLE.
Evaluation can be run after inference completes.
src/entrypoint_eval.sh reads the run-id manifest that the pipeline populated (eval_run_ids.txt), computes CPU metrics locally, and submits a Slurm GPU job for COMET:
bash src/entrypoint_eval.shThe command below reproduces our DRT (MetaphorTrans, English→Chinese) results.
To reproduce our results on the other datasets, swap TRAIN_DATASET_NAME / INFER_DATASET_NAME for another registry key and adjust the hyperparameters:
MODEL_NAME_OR_PATH="$PWD/my_custom_models/my_ouro2p6_thinking" \
ENABLE_SLURM_TMPDIR_STAGING=0 \
QUICK_TEST=0 \
RUN_TRAIN=1 \
RUN_INFERENCE=1 \
RUN_EVAL=0 \
TRAIN_DATASET_NAME=drtMetaphorTrans \
INFER_DATASET_NAME=drtMetaphorTrans \
UT_STEPS_VALUES=1,2,3,4,5,6 \
EPOCHS=3 \
LEARNING_RATES=2e-4 \
LORA_R=32 \
LORA_ALPHA=64 \
PIPELINE_INFER_MODE=lora \
SHOT_MODE=zero \
TRAIN_THINK_MODE=off \
INFER_THINK_MODE=off \
SKIP_GIT_SYNC=1 \
bash src/entrypoint_of_entrypoint.shPlease consider citing if our paper/code is helpful to you:
@misc{chen2026latentmtmachinetranslationlatent,
title={LatentMT: Machine Translation with Latent Reasoning},
author={Wei-Rui Chen and Samar M. Magdy and Chiyu Zhang and Wenhui Zhu and Zhipeng Wang and Muhammad Abdul-Mageed},
year={2026},
eprint={2607.18618},
archivePrefix={arXiv},
primaryClass={cs.CL},
url={https://arxiv.org/abs/2607.18618},
}