Instructions to use kerasformers/xlm_roberta_base with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- KerasFormers
How to use kerasformers/xlm_roberta_base with KerasFormers:
# No code snippets available yet for this library. # To use this model, check the repository files and the library's documentation. # Want to help? PRs adding snippets are welcome at: # https://github.com/huggingface/huggingface.js
- Keras
How to use kerasformers/xlm_roberta_base with Keras:
# Available backend options are: "jax", "torch", "tensorflow". import os os.environ["KERAS_BACKEND"] = "jax" import keras model = keras.saving.load_model("hf://kerasformers/xlm_roberta_base") - Notebooks
- Google Colab
- Kaggle
See our collection for all versions of XLM-RoBERTa.
Run XLM-RoBERTa with Keras 3: JAX, PyTorch, or TensorFlow
kerasformers/xlm_roberta_base
Paper: Unsupervised Cross-lingual Representation Learning at Scale (arXiv:1911.02116) · HF Papers
XLM-RoBERTa is the multilingual RoBERTa: same encoder architecture, pretrained on 2.5TB CommonCrawl across 100 languages, with a 250k SentencePiece vocabulary (mask token <mask>).
For more details on the model, please go to the upstream model card.
Pure-Keras 3 conversion of FacebookAI/xlm-roberta-base for kerasformers. One implementation runs unmodified on TensorFlow / Torch / JAX.
This is a fill-mask / encoder checkpoint (XLMRobertaMaskedLM, base). Task heads load via hf: fine-tunes.
✨ Quick start (multilingual fill-mask)
import os
os.environ["KERAS_BACKEND"] = "torch" # or "jax" / "tensorflow"
from kerasformers.models.xlm_roberta import (
XLMRobertaMaskedLM,
XLMRobertaTokenizer,
)
mlm = XLMRobertaMaskedLM.from_weights("kerasformers/xlm_roberta_base")
tokenizer = XLMRobertaTokenizer.from_weights("kerasformers/xlm_roberta_base")
# Multilingual: same <mask> API as RoBERTa, 100-language SentencePiece vocab.
inputs = tokenizer("La capitale de la France est <mask>.")
logits = mlm(inputs) # (1, L, vocab_size)
mask = int((inputs["input_ids"][0] == tokenizer.mask_token_id).argmax())
print(tokenizer.decode([int(logits[0, mask].argmax())]))
Load any XLM-RoBERTa variant the same way with from_weights("kerasformers/<variant>"):
| Variant | Hub |
|---|---|
xlm_roberta_base |
kerasformers/xlm_roberta_base |
xlm_roberta_large |
kerasformers/xlm_roberta_large |
Tips
- Set
KERAS_BACKENDbefore importing Keras / kerasformers. - Prefer
XLMRobertaTokenizer.from_weights(...)so the SentencePiece vocab matches. - Use
<mask>(not[MASK]). - See XLM-RoBERTa docs and Loading Weights.
- Community / upstream safetensors still work via the
hf:prefix, e.g.XLMRobertaMaskedLM.from_weights("hf:FacebookAI/xlm-roberta-base").
Special Thanks
A huge thank you to the Facebook AI XLM-RoBERTa authors for creating and releasing these models.
License: MIT.
- Downloads last month
- -
Model tree for kerasformers/xlm_roberta_base
Base model
FacebookAI/xlm-roberta-base