xlm-roberta-base-language-detection

The xlm-roberta-base-language-detection model is a fine‑tuned version of the multilingual transformer xlm‑roberta‑base . It adds a lightweight classification head on top of the pooled output, turning the 125 M‑parameter encoder into a 20‑class language identifier. The model accepts a raw text string (up to 512 tokens) and returns the most likely ISO‑639‑1 language code together with a confidence score.

papluca 436K downloads mit Text Classification
Frameworkstransformerspytorchtfsafetensors
Languagesmultilingualarbgdeelen
Datasetspapluca/language-identification
Tagsxlm-robertatext-classificationgenerated_from_trainerbase_model:FacebookAI/xlm-roberta-basebase_model:finetune:FacebookAI/xlm-roberta-basedoi:10.57967/hf/2064text-embeddings-inference
Downloads
436K
License
mit
Pipeline
Text Classification
Author
papluca

Run xlm-roberta-base-language-detection locally on a Q4KM hard drive

Looking for ultra‑fast, on‑premise language detection? Q4KM offers high‑performance SSDs pre‑loaded with the xlm‑roberta‑base‑language‑detection model, ready for plug‑and‑play deployment in...

Shop Q4KM Drives

Technical Overview

The xlm-roberta-base-language-detection model is a fine‑tuned version of the multilingual transformer xlm‑roberta‑base. It adds a lightweight classification head on top of the pooled output, turning the 125 M‑parameter encoder into a 20‑class language identifier. The model accepts a raw text string (up to 512 tokens) and returns the most likely ISO‑639‑1 language code together with a confidence score.

Key capabilities include:

  • Support for 20 languages: Arabic (ar), Bulgarian (bg), German (de), 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).
  • Zero‑shot inference on any Unicode text – no preprocessing beyond tokenisation is required.
  • Fast inference with a single linear layer head, making it suitable for real‑time pipelines.

Architecture highlights:

  • Base model: XLM‑R (BERTa (12 transformer layers, 768 hidden size, 12 attention heads).
  • Classification head: a dense layer that maps the [CLS] token representation to 20 logits, followed by a soft‑max.
  • Training regime: supervised fine‑tuning on a balanced 20‑language dataset using cross‑entropy loss.

Intended use cases revolve around any scenario that needs rapid language detection – from routing user‑generated content to the appropriate localisation pipeline, to preprocessing steps in multilingual NLP workflows, to analytics dashboards that segment traffic by language.

Benchmark Performance

For language detection the most informative metrics are accuracy, precision, recall, and F1‑score computed per language and aggregated macro‑weighted. The model was evaluated on a held‑out test set of 10 000 sentences (500 per language) and achieved an overall accuracy of 99.6 %, with macro‑weighted F1 also at 99.6 %. Individual language scores exceed 0.98 for all classes, with perfect 1.00 for English, French, Dutch, Polish, Swahili, Thai, Urdu, and Chinese.

A direct comparison against the popular langid library (restricted to the same 20 languages) shows a boost of roughly 1 % absolute accuracy (98.5 % for langid vs. 99.6 % for this model). The higher precision and recall especially for low‑resource scripts (e.g., Hindi, Thai, Vietnamese) underline the benefit of a multilingual transformer fine‑tuned on a balanced corpus.

These benchmarks matter because language detection is often the first gate in multilingual pipelines; a 1 % error reduction can translate into millions of correctly routed messages in large‑scale services.

Hardware Requirements

Inference with xlm-roberta-base requires roughly 2 GB of VRAM for a batch size of 1 (single sentence). For higher throughput (e.g., batch size 16) plan on 4–5 GB of GPU memory. The model runs comfortably on consumer‑grade GPUs such as the NVIDIA RTX 3060 (12 GB) or RTX 2070 (8 GB). On CPUs, expect ~150 ms per sentence on a modern 8‑core Intel i7‑12700K; using torch.compile or ONNX Runtime can cut this to ~80 ms.

Storage: the model files (weights in safetensors format) occupy ≈ 500 MB. Including the tokenizer adds another ~30 MB. A typical deployment therefore needs ≈ 1 GB of disk space for the full package.

Performance tip: enable torch.backends.cudnn.benchmark = True and use half‑precision (float16) to halve memory usage and double throughput on recent GPUs.

Use Cases

Primary applications include:

  • Content routing – automatically send user‑generated text to language‑specific moderation or translation services.
  • Analytics & reporting – segment web traffic, social‑media streams, or call‑center transcripts by language for market insights.
  • Pre‑processing for multilingual NLP – feed the detected language into downstream models (e.g., sentiment analysis, NER) that require language‑specific pipelines.
  • Edge devices & mobile apps – lightweight inference enables on‑device language detection without network latency.

Industries that benefit include e‑commerce (localising product reviews), media streaming (subtitle selection), finance (monitoring multilingual news feeds), and government agencies (civic engagement platforms). Integration is straightforward via the transformers pipeline API or by loading the model directly with AutoModelForSequenceClassification.

Training Details

Fine‑tuning was performed on the papluca/language‑identification dataset, which provides 70 k training sentences (≈ 3 500 per language) and 10 k each for validation and testing. The training loop used the Trainer API from Hugging Face, with cross‑entropy loss and a learning‑rate schedule that warmed up over the first 10 % of steps and then decayed linearly.

Compute: the process ran on a single NVIDIA A100 GPU (40 GB VRAM) for roughly 2 hours, using a batch size of 32 and mixed‑precision (FP16) to accelerate training. The final checkpoint was saved in safetensors format for efficient loading.

Because the model retains the full XLM‑RoBERTa encoder, it can be further fine‑tuned on any downstream multilingual task (e.g., sentiment analysis) by replacing the classification head with a task‑specific one while keeping the pretrained weights frozen or partially trainable.

Licensing Information

The model is released under an MIT‑style license (the README lists “license: mit”), even though the Hugging Face card marks the overall license as “unknown”. The MIT licence is permissive: you may use, modify, distribute, and commercialise the model without paying royalties, provided you retain the original copyright notice.

No explicit restrictions are imposed on deployment (e.g., no “non‑commercial only” clause). However, you must still respect the underlying XLM‑RoBERTa paper’s terms and any third‑party data licences (the fine‑tuning dataset is public). Attribution is recommended but not mandatory under MIT; a simple credit line such as “Based on papluca/xlm‑roberta‑base‑language‑detection (MIT)” is sufficient.

Pre-loaded AI models. Ready to run.

Skip the downloads. Get a Q4KM hard drive with hundreds of models pre-configured and optimized.

Shop Q4KM Hard Drives