Downloads · 30 days
53
58% of all-time downloads
TigreGotico/afrolid_1.5-onnx
afrolid_1.5-onnx is a text classification model from TigreGotico. Use it when you need a label for a piece of text. It is set up for onnx. The card lists the license as apache-2.0.
ONNX export of UBC-NLP/afrolid1.5, a neural LID model covering 517 African languages and varieties, fine-tuned from SERENGETI (a massively multilingual XLM-RoBERTa-family encoder for African languages). This is by far…
Downloads · 30 days
53
58% of all-time downloads
All-time downloads
91
Public
Repo size
1.4 GB
Likes
0
Public
Click a slice to open those files.
.onnx1.4 GB · 97%
From the Hugging Face model README
ONNX export of UBC-NLP/afrolid_1.5,
a neural LID model covering 517 African languages and varieties, fine-tuned
from SERENGETI (a massively
multilingual XLM-RoBERTa-family encoder for African languages). This is by
far the broadest African-language LID coverage in this org's inventory,
complementing GlotLID/lid176/lid218e for continent-specific work.
Licence: Apache-2.0. The Hub card of UBC-NLP/afrolid_1.5 declares no
licence. The UBC-NLP/afrolid repository
ships an Apache-2.0 LICENSE, and its README says: "afrolid(-py) is Apache-2.0
licensed. The license applies to the pre-trained models as well." The
UBC-NLP/serengeti repository of the
base model is Apache-2.0 too.
Unlike the fastText-based LID models in this org (glotlid-onnx, lid176-onnx,
lid218e-onnx), AfroLID is a standard XLMRobertaForSequenceClassification
encoder classifier: optimum-cli export onnx --task text-classification
applies directly, no custom hashing/graph-splitting needed.
| File | Size | Purpose |
|---|---|---|
model.onnx | 1.06 GB | fp32 graph |
model.int8.onnx | 267 MB | dynamic int8 graph |
config.json | id2label map, 518 labels | |
tokenizer.json, sentencepiece.bpe.model, tokenizer_config.json, special_tokens_map.json | XLM-R tokenizer |
import numpy as np
import onnxruntime as ort
from transformers import AutoTokenizer, AutoConfig
from huggingface_hub import snapshot_download
d = snapshot_download("TigreGotico/afrolid_1.5-onnx")
tok = AutoTokenizer.from_pretrained(d)
config = AutoConfig.from_pretrained(d)
sess = ort.InferenceSession(f"{d}/model.onnx", providers=["CPUExecutionProvider"])
def detect(text):
enc = tok(text, return_tensors="np", truncation=True)
inputs = {k: v for k, v in enc.items() if k in [i.name for i in sess.get_inputs()]}
logits = sess.run(None, inputs)[0]
idx = int(np.argmax(logits, axis=-1)[0])
return config.id2label[idx]
print(detect("Leo hali ya hewa ni nzuri sana Nairobi."))
# -> swh
For the int8 build, load model.int8.onnx instead.
5 sentences across 5 different African languages/scripts (Dinka, Swahili,
Hausa, a Yoruba sample, Zulu), compared against the original model's own
transformers.pipeline("text-classification", model="UBC-NLP/afrolid_1.5").
parity:
sample_size: 5
metric: top1_exact_match
fp32: 1.00 # 5/5
int8: 1.00 # 5/5
| Model | Top-1 agreement with reference |
|---|---|
model.onnx (fp32) | 100.00% (5/5) |
model.int8.onnx | 100.00% (5/5) |
Differential check (per this org's multi-target verification standard): all 5 distinct-language inputs produced 5 distinct predicted labels in the fp32 build - no passthrough/collapse-to-one-language bug.
A finding worth reporting honestly, not hiding: the Yoruba test
sentence used here ("Loni ni ojo to dara pupo ni Eko.") was classified as
wol (Wolof) by the original PyTorch model itself, and the ONNX
exports (fp32 and int8) reproduce that identically - so this is a
limitation of the underlying AfroLID checkpoint on this particular input,
not a defect introduced by the ONNX conversion. Reported per this org's
policy of recording what the detector actually says on a mismatch rather
than silently calling it a conversion defect.
Caveat on sample size: n=5 is a small smoke-test, not a systematic accuracy evaluation across the 517 supported languages. It establishes fp32/int8 conversion fidelity against the original model, not real-world accuracy - see the AfroLID paper (Adebara et al., EMNLP 2022) for the authors' own benchmark (macro-F1 97.41 for v1.5, per the source README).
@article{adebara2022afrolid,
title={AfroLID: A Neural Language Identification Tool for African Languages},
author={Adebara, Ife and Elmadany, AbdelRahim and Abdul-Mageed, Muhammad and Inciarte, Alcides Alcoba},
booktitle = "Proceedings of the 2022 Conference on Empirical Methods in Natural Language Processing (EMNLP)",
month = December,
year = "2022",
}
@inproceedings{adebara-etal-2023-serengeti,
title = "{SERENGETI}: Massively Multilingual Language Models for {A}frica",
author = "Adebara, Ife and others",
}