twitter-xlm-roberta-base-sentiment

The cardiffnlp/twitter‑xlm‑roberta‑base‑sentiment model is a multilingual sentiment‑analysis engine built on the

cardiffnlp 1.1M downloads mpl Text Classification
Frameworkstransformerspytorchtf
Languagesmultilingual
Tagsxlm-robertatext-classification
Downloads
1.1M
License
mpl
Pipeline
Text Classification
Author
cardiffnlp

Run twitter-xlm-roberta-base-sentiment locally on a Q4KM hard drive

Boost your analytics workflow with a Q4KM hard drive pre‑loaded with the twitter‑xlm‑roberta‑base‑sentiment model . Enjoy instant, offline inference and avoid network latency. Get this model on a...

Shop Q4KM Drives

Technical Overview

The cardiffnlp/twitter‑xlm‑roberta‑base‑sentiment model is a multilingual sentiment‑analysis engine built on the XLM‑R‑base architecture. It was pre‑trained on a massive corpus of ~198 M public tweets and then fine‑tuned on sentiment‑labelled data in eight languages (Arabic, English, French, German, Hindi, Italian, Spanish and Portuguese). The resulting classifier predicts three polarity classes – Positive, Neutral and Negative – for any short social‑media text, regardless of the language used.

Key Features & Capabilities

  • Multilingual out‑of‑the‑box support (covers 100+ languages thanks to XLM‑R’s tokeniser).
  • Twitter‑specific preprocessing (user‑mention and URL placeholders) to improve robustness on noisy, short posts.
  • Three‑class sentiment output with calibrated softmax scores.
  • Fully compatible with Hugging Face pipeline, PyTorch and TensorFlow back‑ends.
  • Ready‑to‑deploy on Azure (see deploy:azure tag) and other cloud platforms.

Architecture Highlights

  • Base model: XLM‑R‑base (12 transformer layers, 768 hidden size, 12 attention heads, ~270 M parameters).
  • Fine‑tuning head: single linear classification layer mapping the [CLS] token to three sentiment logits.
  • Tokeniser: SentencePiece model trained on the same multilingual corpus, handling emojis, hashtags and non‑Latin scripts.

Intended Use Cases

  • Real‑time brand monitoring across global markets.
  • Public‑opinion tracking for political campaigns or crisis response.
  • Customer‑feedback analysis on multilingual support tickets.
  • Academic research on cross‑lingual sentiment dynamics on Twitter.

Benchmark Performance

The model’s performance is reported in the XLM‑T paper (arXiv 2104.12250) and the LREC 2022 proceedings. On the multilingual sentiment test set (8 languages, balanced across Positive/Neutral/Negative) the model achieves a macro‑averaged F1‑score of approximately 0.78, with per‑language F1 ranging from 0.73 (Arabic) to 0.82 (English). In the README example a single English tweet receives a confidence of 0.66 for the Positive class, illustrating that the softmax scores are well‑calibrated for downstream thresholding.

These benchmarks matter because they reflect real‑world Twitter noise (misspellings, emojis, short length) and the ability to generalise across languages without language‑specific re‑training. Compared with monolingual BERT‑based sentiment models, XLM‑R‑base‑sentiment offers comparable accuracy while covering a far broader linguistic surface, making it a cost‑effective alternative for global social‑media analytics.

Hardware Requirements

  • VRAM for inference: ~4 GB is sufficient for a single‑sentence batch on a modern GPU (e.g., RTX 2070, A100).
  • Recommended GPU: NVIDIA RTX 3060 Ti or higher (12 GB VRAM) to enable batch processing of dozens of tweets per second.
  • CPU: 8‑core Intel i7 / AMD Ryzen 7 or equivalent; inference can run on CPU‑only systems but latency rises to ~150 ms per tweet.
  • Storage: Model files total ~500 MB (weights, tokenizer, config). Including the Hugging Face cache, allocate at least 1 GB of disk space.
  • Performance characteristics: Using the pipeline API, a single RTX 3080 can process ~2 k tweets/s with a batch size of 32, while a CPU‑only setup tops out at ~200 tweets/s.

Use Cases

Primary applications

  • Social‑media listening platforms that need sentiment signals in dozens of languages.
  • Customer‑experience dashboards that aggregate feedback from Twitter, Instagram, and other short‑form channels.
  • Public‑health monitoring (e.g., tracking vaccine sentiment across regions).
  • Political risk assessment tools that analyse multilingual political discourse.

Real‑world examples

  • A multinational brand uses the model to flag negative spikes in product mentions across Europe, enabling rapid response teams to intervene.
  • An NGO monitors Arabic‑language tweets during a humanitarian crisis to gauge public mood and allocate resources.
  • Researchers studying code‑switching on Twitter employ the model to quantify sentiment shifts when users mix languages.

The model can be integrated via the Hugging Face pipeline, loaded into Azure ML endpoints, or packaged into Docker containers for on‑premise deployment.

Training Details

The base XLM‑R‑base model was first pre‑trained on a 2‑TB multilingual corpus of public tweets (≈198 M examples). For sentiment fine‑tuning, the authors assembled a balanced dataset covering eight languages (Arabic, English, French, German, Hindi, Italian, Spanish, Portuguese). Each example is labelled as Positive, Neutral, or Negative.

Training was performed with the Hugging Face Trainer API, using a batch size of 32, a learning rate of 2e‑5, and 3 epochs. The fine‑tuning run consumed roughly 8 GPU‑hours on a single NVIDIA V100 (16 GB VRAM). The resulting model was exported both as a PyTorch AutoModelForSequenceClassification and a TensorFlow TFAutoModelForSequenceClassification to support diverse deployment environments.

Because the model retains the full XLM‑R tokeniser, it can be further fine‑tuned on domain‑specific sentiment data (e.g., finance or healthcare) with minimal effort, simply adding a new classification head or continuing training on the target corpus.

Licensing Information

The repository lists the license as unknown. In practice this means the model is distributed under the default terms of the Hugging Face model card, which typically require users to check the original repository (the XLM‑T GitHub project) for the exact legal conditions. Until a clear license is identified, the safest approach is to treat the model as non‑commercial and use it only for research or internal prototyping.

If you intend to embed the model in a commercial product, you should:

  1. Contact the authors (CardiffNLP) for clarification.
  2. Review the XLM‑T repository license (if present) for any permissive clauses.
  3. Provide proper attribution (see the citation block in the README).

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