ghanaopenai/nkrane-mt-reranker-afro-xlmr is a specialized cross-encoder reranker fine-tuned from Davlan/afro-xlmr-base for contextual lexical disambiguation in English $\rightarrow$ Asante Twi (Akan) translation.
It is a core component of the Nkrane-MT translation pipeline developed by GhanaOpenAI.
In Nkrane-MT, generative seq2seq models (e.g. Marian opus-mt-en-tw or nllb-200-distilled-600M) are trained to output fluent Asante Twi while keeping targeted English noun phrases preserved in angle brackets <noun> (with all Twi determiners such as no, yi, bi outside the brackets).
After the model generates the sentence, an offline dictionary lookup provides candidate Asante Twi translations for each bracketed term. Because many words have multiple distinct senses (e.g., "trade" can mean "dwadie" [commerce] or "adwuma" [profession]), this cross-encoder evaluates each candidate in the exact generated Asante Twi context in $<5\text{ ms}$ and selects the most contextually appropriate translation.
[English Source]
"They went to see how the trade is doing in the market."
│
▼
[Nkrane-MT Seq2Seq Translator]
│
▼
"Wɔkɔhwɛɛ sɛnea <trade> no teɛ wɔ dwadibea hɔ."
│
Dictionary candidates for 'trade': ["dwadie", "adwuma", "aguadi"]
│
▼
[Afro-XLMR Cross-Encoder Reranker (This Model)]
Pair 1: ("Wɔkɔhwɛɛ sɛnea <trade> no teɛ...", "dwadie") -> 0.985
Pair 2: ("Wɔkɔhwɛɛ sɛnea <trade> no teɛ...", "adwuma") -> 0.082
│
▼
[Final Translation]
"Wɔkɔhwɛɛ sɛnea dwadie no teɛ wɔ dwadibea hɔ."
Davlan/afro-xlmr-base (multilingual Afrocentric transformer encoder).< and > special markers to preserve bracket spans.text_a: Asante Twi sentence with preserved <noun> phrase (e.g. Wɔkɔhwɛɛ sɛnea <trade> no teɛ wɔ dwadibea hɔ.).text_b: Candidate Asante Twi dictionary translation (e.g. dwadie).text_b inside text_a.97.21% on held-out validation pairs.transformersimport torch
from transformers import AutoModelForSequenceClassification, AutoTokenizer
device = "cuda" if torch.cuda.is_available() else "cpu"
model_id = "ghanaopenai/nkrane-mt-reranker-afro-xlmr"
tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForSequenceClassification.from_pretrained(model_id).to(device)
model.eval()
# Sentence context with bracketed English noun
context = "Wɔkɔhwɛɛ sɛnea <trade> no teɛ wɔ Kejetia dwadibea hɔ."
candidates = ["dwadie", "adwuma", "aguadi"]
# Score all candidates simultaneously
pairs_a = [context] * len(candidates)
pairs_b = candidates
inputs = tokenizer(
pairs_a,
pairs_b,
padding=True,
truncation=True,
max_length=160,
return_tensors="pt",
).to(device)
with torch.no_grad():
logits = model(**inputs).logits.squeeze(-1)
scores = torch.sigmoid(logits).tolist()
for cand, score in sorted(zip(candidates, scores), key=lambda x: x[1], reverse=True):
print(f"Candidate: {cand:<10} | Confidence: {score:.4f}")
# Output:
# Candidate: dwadie | Confidence: 0.9852
# Candidate: aguadi | Confidence: 0.8124
# Candidate: adwuma | Confidence: 0.0815
nkrane-mt Python Packagefrom nkrane_mt import GlossMT2Translator
from nkrane_mt.seq2seq import Seq2SeqModelWrapper
from nkrane_mt.reranker import ContextualReranker
# Load fine-tuned NLLB-200 seq2seq generator
seq2seq = Seq2SeqModelWrapper("ghanaopenai/gloss-mt-2-nllb-600m-en2tw", direction="en-tw")
# Load Afro-XLMR Cross-Encoder Reranker
reranker = ContextualReranker("ghanaopenai/nkrane-mt-reranker-afro-xlmr")
# End-to-end pipeline with post-translation contextual disambiguation
translator = GlossMT2Translator(model=seq2seq, reranker=reranker, direction="en-tw")
res = translator.translate("The Ministry of Finance announced a new policy for the hospital.")
print(res["translation"])
# -> "Sikasɛm Asoeɛ no de nhyehyɛeɛ foforɔ maa ayaresabea no."
bfloat16 and TF32.lr=1e-5, cosine learning rate schedule, warmup steps = 500).nn.BCEWithLogitsLoss).97.21% (loss 0.0872).If you use this model or the Nkrane-MT pipeline in your research, please cite:
@misc{nkrane_mt_2026,
author = {Owusu, S. and GhanaOpenAI Contributors},
title = {Nkrane-MT: Contextual Lexical Disambiguation & Cross-Encoder Reranking for English-Asante Twi Translation},
year = {2026},
publisher = {Hugging Face},
howpublished = {\url{https://huggingface.co/ghanaopenai/nkrane-mt-reranker-afro-xlmr}}
}
GhanaOpenAI/nkrane-mtghanaopenai/nkrane-mt-parallel-corpus-eng-twimodel.safetensors 1.1 GBtraining_args.bin 4.9 kBDavlan/afro-xlmr-base