You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Unsupervised Cross-lingual Representation Learning at Scale (XLM-RoBERTa)
Introduction
XLM-R (XLM-RoBERTa) is scaled cross lingual sentence encoder. It is trained on 2.5T of data across 100 languages data filtered from Common Crawl. XLM-R achieves state-of-the-arts results on multiple cross lingual benchmarks.
importtorchxlmr=torch.hub.load('pytorch/fairseq', 'xlmr.large.v0')
xlmr.eval() # disable dropout (or leave in train mode to finetune)
Load XLM-R (for PyTorch 1.0 or custom models):
# Download xlmr.large modelwgethttps://dl.fbaipublicfiles.com/fairseq/models/xlmr.large.v0.tar.gztar-xzvfxlmr.large.v0.tar.gz# Load the model in fairseqfromfairseq.models.robertaimportXLMRModelxlmr=XLMRModel.from_pretrained('/path/to/xlmr.large.v0', checkpoint_file='model.pt')
xlmr.eval() # disable dropout (or leave in train mode to finetune)
Apply sentence-piece-model (SPM) encoding to input text:
# Extract the last layer's featureslast_layer_features=xlmr.extract_features(zh_tokens)
assertlast_layer_features.size() ==torch.Size([1, 6, 1024])
# Extract all layer's features (layer 0 is the embedding layer)all_layers=xlmr.extract_features(zh_tokens, return_all_hiddens=True)
assertlen(all_layers) ==25asserttorch.all(all_layers[-1] ==last_layer_features)
Citation
@article{,
title = {Unsupervised Cross-lingual Representation Learning at Scale},
author = {Alexis Conneau and Kartikay Khandelwal and Naman Goyal and Vishrav Chaudhary and Guillaume Wenzek and Francisco Guzm\'an and Edouard Grave and Myle Ott and Luke Zettlemoyer and Veselin Stoyanov},
journal={},
year = {2019},
}