The Latest AIs, every day
AIs with the most favorites on Toolify
AIs with the highest website traffic (monthly visits)
AI Tools by Apps
Discover the Discord of AI
AI Tools by browser extensions
GPTs from GPT Store
Discover The Best Model For AI
Top AI lists by month and monthly visits.
Top AI lists by category and monthly visits.
Top AI lists by region and monthly visits.
Top AI lists by source and monthly visits.
Top AI lists by revenue and real traffic.

This model is a fine-tuned version of xlm-roberta-base on the Language Identification dataset.
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.
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)
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.
| Language | Precision | Recall | F1-score | support |
|---|---|---|---|---|
| ar | 0.998 | 0.996 | 0.997 | 500 |
| bg | 0.998 | 0.964 | 0.981 | 500 |
| de | 0.998 | 0.996 | 0.997 | 500 |
| el | 0.996 | 1.000 | 0.998 | 500 |
| en | 1.000 | 1.000 | 1.000 | 500 |
| es | 0.967 | 1.000 | 0.983 | 500 |
| fr | 1.000 | 1.000 | 1.000 | 500 |
| hi | 0.994 | 0.992 | 0.993 | 500 |
| it | 1.000 | 0.992 | 0.996 | 500 |
| ja | 0.996 | 0.996 | 0.996 | 500 |
| nl | 1.000 | 1.000 | 1.000 | 500 |
| pl | 1.000 | 1.000 | 1.000 | 500 |
| pt | 0.988 | 1.000 | 0.994 | 500 |
| ru | 1.000 | 0.994 | 0.997 | 500 |
| sw | 1.000 | 1.000 | 1.000 | 500 |
| th | 1.000 | 0.998 | 0.999 | 500 |
| tr | 0.994 | 0.992 | 0.993 | 500 |
| ur | 1.000 | 1.000 | 1.000 | 500 |
| vi | 0.992 | 1.000 | 0.996 | 500 |
| zh | 1.000 | 1.000 | 1.000 | 500 |
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.
| Language | Precision | Recall | F1-score | support |
|---|---|---|---|---|
| ar | 0.990 | 0.970 | 0.980 | 500 |
| bg | 0.998 | 0.964 | 0.981 | 500 |
| de | 0.992 | 0.944 | 0.967 | 500 |
| el | 1.000 | 0.998 | 0.999 | 500 |
| en | 1.000 | 1.000 | 1.000 | 500 |
| es | 1.000 | 0.968 | 0.984 | 500 |
| fr | 0.996 | 1.000 | 0.998 | 500 |
| hi | 0.949 | 0.976 | 0.963 | 500 |
| it | 0.990 | 0.980 | 0.985 | 500 |
| ja | 0.927 | 0.988 | 0.956 | 500 |
| nl | 0.980 | 1.000 | 0.990 | 500 |
| pl | 0.986 | 0.996 | 0.991 | 500 |
| pt | 0.950 | 0.996 | 0.973 | 500 |
| ru | 0.996 | 0.974 | 0.985 | 500 |
| sw | 1.000 | 1.000 | 1.000 | 500 |
| th | 1.000 | 0.996 | 0.998 | 500 |
| tr | 0.990 | 0.968 | 0.979 | 500 |
| ur | 0.998 | 0.996 | 0.997 | 500 |
| vi | 0.971 | 0.990 | 0.980 | 500 |
| zh | 1.000 | 1.000 | 1.000 | 500 |
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)}
Fine-tuning was done via the
Trainer
API. Here is the
Colab notebook
with the training code.
The following hyperparameters were used during training:
The validation results on the
valid
split of the Language Identification dataset are summarised here below.
| Training Loss | Epoch | Step | Validation Loss | Accuracy | F1 |
|---|---|---|---|---|---|
| 0.2492 | 1.0 | 1094 | 0.0149 | 0.9969 | 0.9969 |
| 0.0101 | 2.0 | 2188 | 0.0103 | 0.9977 | 0.9977 |
In short, it achieves the following results on the validation set:
xlm-roberta-base-language-detection huggingface.co is an AI model on huggingface.co that provides xlm-roberta-base-language-detection's model effect (), which can be used instantly with this papluca xlm-roberta-base-language-detection model. huggingface.co supports a free trial of the xlm-roberta-base-language-detection model, and also provides paid use of the xlm-roberta-base-language-detection. Support call xlm-roberta-base-language-detection model through api, including Node.js, Python, http.
xlm-roberta-base-language-detection huggingface.co is an online trial and call api platform, which integrates xlm-roberta-base-language-detection's modeling effects, including api services, and provides a free online trial of xlm-roberta-base-language-detection, you can try xlm-roberta-base-language-detection online for free by clicking the link below.
xlm-roberta-base-language-detection is an open source model from GitHub that offers a free installation service, and any user can find xlm-roberta-base-language-detection on GitHub to install. At the same time, huggingface.co provides the effect of xlm-roberta-base-language-detection install, users can directly use xlm-roberta-base-language-detection installed effect in huggingface.co for debugging and trial. It also supports api for free installation.
