Aller au contenu
ModelVérifiéExterne
Télécharger

Xlm Roberta Base Language Detection ONNX

This is an ONNX version of papluca/xlm-roberta-base-language-detection. It was automatically converted and uploaded using this Hugging Face Space.

TypeObject detectorModèle de basepapluca/xlm-roberta-base-language-detectionVersionRevision 919c87aÉditeur@onnx-communityCClasse

Source du modèle

Type
Object detector
Taille du fichier
266 MB–1,04 GB
Modèle de base
papluca/xlm-roberta-base-language-detection
Version
vRevision 919c87a
Mis à jour
3 oct. 2026
Téléchargements
274
Source
Hugging Face

Description de la source

xlm-roberta-base-language-detection (ONNX)

This is an ONNX version of papluca/xlm-roberta-base-language-detection. It was automatically converted and uploaded using this Hugging Face Space.

Usage with Transformers.js

See the pipeline documentation for text-classification: https://huggingface.co/docs/transformers.js/api/pipelines#module_pipelines.TextClassificationPipeline


xlm-roberta-base-language-detection

This model is a fine-tuned version of xlm-roberta-base on the Language Identification dataset.

Model description

This model is an XLM-RoBERTa transformer model with a classification head on top (i.e. a linear layer on top of the pooled output). For additional information please refer to the xlm-roberta-base model card or to the paper Unsupervised Cross-lingual Representation Learning at Scale by Conneau et al.

Intended uses & limitations

You can directly use this model as a language detector, i.e. for sequence classification tasks. Currently, it supports the following 20 languages:

arabic (ar), bulgarian (bg), german (de), modern greek (el), english (en), spanish (es), french (fr), hindi (hi), italian (it), japanese (ja), dutch (nl), polish (pl), portuguese (pt), russian (ru), swahili (sw), thai (th), turkish (tr), urdu (ur), vietnamese (vi), and chinese (zh)

Training and evaluation data

The model was fine-tuned on the Language Identification dataset, which consists of text sequences in 20 languages. The training set contains 70k samples, while the validation and test sets 10k each. The average accuracy on the test set is 99.6% (this matches the average macro/weighted F1-score being the test set perfectly balanced). A more detailed evaluation is provided by the following table.

LanguagePrecisionRecallF1-scoresupport
ar0.9980.9960.997500
bg0.9980.9640.981500
de0.9980.9960.997500
el0.9961.0000.998500
en1.0001.0001.000500
es0.9671.0000.983500
fr1.0001.0001.000500
hi0.9940.9920.993500
it1.0000.9920.996500
ja0.9960.9960.996500
nl1.0001.0001.000500
pl1.0001.0001.000500
pt0.9881.0000.994500
ru1.0000.9940.997500
sw1.0001.0001.000500
th1.0000.9980.999500
tr0.9940.9920.993500
ur1.0001.0001.000500
vi0.9921.0000.996500
zh1.0001.0001.000500

Benchmarks

As a baseline to compare xlm-roberta-base-language-detection against, we have used the Python langid library. Since it comes pre-trained on 97 languages, we have used its .set_languages() method to constrain the language set to our 20 languages. The average accuracy of langid on the test set is 98.5%. More details are provided by the table below.

LanguagePrecisionRecallF1-scoresupport
ar0.9900.9700.980500
bg0.9980.9640.981500
de0.9920.9440.967500
el1.0000.9980.999500
en1.0001.0001.000500
es1.0000.9680.984500
fr0.9961.0000.998500
hi0.9490.9760.963500
it0.9900.9800.985500
ja0.9270.9880.956500
nl0.9801.0000.990500
pl0.9860.9960.991500
pt0.9500.9960.973500
ru0.9960.9740.985500
sw1.0001.0001.000500
th1.0000.9960.998500
tr0.9900.9680.979500
ur0.9980.9960.997500
vi0.9710.9900.980500
zh1.0001.0001.000500

How to get started with the model

The easiest way to use the model is via the high-level pipeline API:

from transformers import pipeline

text = [
    "Brevity is the soul of wit.",
    "Amor, ch'a nullo amato amar perdona."
]

model_ckpt = "papluca/xlm-roberta-base-language-detection"
pipe = pipeline("text-classification", model=model_ckpt)
pipe(text, top_k=1, truncation=True)

Or one can proceed with the tokenizer and model separately:

import torch
from transformers import AutoModelForSequenceClassification, AutoTokenizer

text = [
    "Brevity is the soul of wit.",
    "Amor, ch'a nullo amato amar perdona."
]

model_ckpt = "papluca/xlm-roberta-base-language-detection"
tokenizer = AutoTokenizer.from_pretrained(model_ckpt)
model = AutoModelForSequenceClassification.from_pretrained(model_ckpt)

inputs = tokenizer(text, padding=True, truncation=True, return_tensors="pt")

with torch.no_grad():
    logits = model(**inputs).logits

preds = torch.softmax(logits, dim=-1)

# Map raw predictions to languages
id2lang = model.config.id2label
vals, idxs = torch.max(preds, dim=1)
{id2lang[k.item()]: v.item() for k, v in zip(idxs, vals)}

Training procedure

Fine-tuning was done via the Trainer API. Here is the Colab notebook with the training code.

Training hyperparameters

The following hyperparameters were used during training:

  • learning_rate: 2e-05
  • train_batch_size: 64
  • eval_batch_size: 128
  • seed: 42
  • optimizer: Adam with betas=(0.9,0.999) and epsilon=1e-08
  • lr_scheduler_type: linear
  • num_epochs: 2
  • mixed_precision_training: Native AMP

Training results

The validation results on the valid split of the Language Identification dataset are summarised here below.

Training LossEpochStepValidation LossAccuracyF1
0.24921.010940.01490.99690.9969
0.01012.021880.01030.99770.9977

In short, it achieves the following results on the validation set:

  • Loss: 0.0101
  • Accuracy: 0.9977
  • F1: 0.9977

Framework versions

  • Transformers 4.12.5
  • Pytorch 1.10.0+cu111
  • Datasets 1.15.1
  • Tokenizers 0.10.3

Sources

1 source
Hugging FacePrincipalVersion 919c87aa2749131ae1ab709931a16bf1cc9774ea
huggingface.co/onnx-community/xlm-roberta-base-language-detection-ONNX/tree/919c87aa2749131ae1ab709931a16bf1cc9774ea

Vérifié 3 oct.

Artefacts du modèle

8 artefacts

onnx/model_bnb4.onnx

onnx · 788 MB · SHA-256 82d7a4a7ca35…bb33 · Hugging Face

Télécharger

onnx/model_fp16.onnx

onnx · 531 MB · SHA-256 737de4df3189…4a60 · Hugging Face

Télécharger

onnx/model_int8.onnx

onnx · 266 MB · SHA-256 e3a2f1b44ea6…82c9 · Hugging Face

Télécharger

onnx/model_q4.onnx

onnx · 788 MB · SHA-256 82d7a4a7ca35…bb33 · Hugging Face

Télécharger

onnx/model_q4f16.onnx

onnx · 414 MB · SHA-256 ab5cd7bfa334…f859 · Hugging Face

Télécharger

onnx/model_quantized.onnx

onnx · 266 MB · SHA-256 e3a2f1b44ea6…82c9 · Hugging Face

Télécharger

onnx/model_uint8.onnx

onnx · 266 MB · SHA-256 5f469c14e9ec…9212 · Hugging Face

Télécharger

onnx/model.onnx

onnx · 1,04 GB · SHA-256 15ef7f8c637a…f621 · Hugging Face

Télécharger

Extraits de sources

3 extraits

--- language: - multilingual - ar - bg - de - el - en - es - fr - hi - it - ja - nl - pl - pt - ru - sw - th - tr - ur - vi - zh license: mit tags: - generated_from_trainer datasets: papluca/language-identification metrics: - accuracy - f1 base_model: - papluca/xlm-roberta-base-language-detection model-index: - name: xlm-roberta-base-language-detection results: [] library_name: transformers.js pipeline_tag: text-classification --- # xlm-roberta-base-language-detection (ONNX) This is an ONNX version of [papluca/xlm-roberta-base-language-detection](https://huggingface.co/papluca/xlm-roberta-base-language-detection). It was automatically converted and uploaded using [this Hugging Face Space](https://huggingface.co/spaces/onnx-community/convert-to-onnx). ## Usage with Transformers.js See the pipeline documentation for `text-classification`: https://huggingface.co/docs/transformers.js/api/pipelines#module_pipelines.TextClassificationPipeline --- # xlm-roberta-base-language-detection This model is a fine-tuned version of [xlm-roberta-base](https://huggingface.co/xlm-roberta-base) on the [Language Identification](https://huggingface.co/datasets/papluca/language-identification#additional-information) dataset. ## Model description This model is an XLM-RoBERTa transformer model with a classification head on top (i.e. a linear layer on top of the pooled output). For additional information please refer to the [xlm-roberta-base](https://huggingface.co/xlm-roberta-base) model card or to the paper [Unsupervised Cross-lingual Representation Learning at Scale](https://arxiv.org/abs/1911.02116) by Conneau et al. ## Intended uses & limitations You can directly use this model as a language detector, i.e. for sequence classification tasks. Currently, it supports the following 20 languages: `arabic (ar), bulgarian (bg), german (de), modern greek (el), english (en), spanish (es), french (fr), hindi (hi), italian (it), japanese (ja), dutch (nl), polish (pl), portuguese (pt), russian (ru), swahili (sw), thai (th), turkish (tr), urdu (ur), vietnamese (vi), and chinese (zh)` ## Training and evaluation data The model was fine-tuned on the [Language Identification](https://huggingface.co/datasets/papluca/language-identification#additional-information) dataset, which consists of text sequences in 20 languages. The training set contains 70k samples, while the validation...

Source context: 274 downloads · 1 likes · Pipeline text-classification · Library transformers.js · Repo onnx-community/xlm-roberta-base-language-detection-ONNX

Source context: 49 downloads · 0 likes · Pipeline text-classification · Library transformers.js · Repo onnx-community/xlm-roberta-base-language-detection-ONNX