模型:
facebook/xlm-roberta-xxl
XLM-RoBERTa-XL 模型是在 2.5TB 的经过筛选的 CommonCrawl 数据上进行预训练的,包含 100 种语言。该模型首次在 Naman Goyal、Jingfei Du、Myle Ott、Giri Anantharaman 和 Alexis Conneau 的论文中提出,并在 this repository 中首次发布。
免责声明:发布 XLM-RoBERTa-XL 的团队并未为该模型编写模型卡片,因此该模型卡片由 Hugging Face 团队编写。
XLM-RoBERTa-XL 是 RoBERTa 的特大型多语言版本。它是在 2.5TB 的经过筛选的 CommonCrawl 数据,包含 100 种语言上进行预训练的。
RoBERTa 是一个以自监督方式在大型语料库上进行预训练的转换器模型。这意味着它仅使用原始文本进行预训练,并没有以任何方式人工标注这些数据(这就是它可以使用大量公开可用数据的原因),该模型使用自动化过程从这些文本中生成输入和标签。
更具体地说,它是使用掩码语言模型(Masked Language Modeling, MLM)目标进行预训练的。模型随机屏蔽输入中的 15% 单词,然后将完整的屏蔽句子输入模型,并预测被屏蔽的单词。这与传统的递归神经网络(RNN)通常一次只看到一个单词,或者与内部屏蔽未来标记的自回归模型(如 GPT)不同。它使得模型可以学习到句子的双向表示。
这种方式可以让模型学习到 100 种语言的内部表示,然后可以用于提取对下游任务有用的特征:例如,如果你有一个有标签的句子数据集,则可以使用 XLM-RoBERTa-XL 模型生成的特征作为输入训练标准分类器。
您可以使用原始模型进行掩码语言建模,但它主要用于在下游任务上进行微调。请查看 model hub ,以寻找您感兴趣的任务的微调版本。
请注意,该模型主要用于在使用整个句子(可能是掩码的)进行决策的任务上进行微调,例如序列分类、标记分类或问题回答。对于文本生成等任务,您应该查看 GPT2 等模型。
您可以使用此模型直接进行掩码语言建模的流水线:
>>> from transformers import pipeline
>>> unmasker = pipeline('fill-mask', model='facebook/xlm-roberta-xxl')
>>> unmasker("Europe is a <mask> continent.")
[{'score': 0.22996895015239716,
'token': 28811,
'token_str': 'European',
'sequence': 'Europe is a European continent.'},
{'score': 0.14307449758052826,
'token': 21334,
'token_str': 'large',
'sequence': 'Europe is a large continent.'},
{'score': 0.12239163368940353,
'token': 19336,
'token_str': 'small',
'sequence': 'Europe is a small continent.'},
{'score': 0.07025063782930374,
'token': 18410,
'token_str': 'vast',
'sequence': 'Europe is a vast continent.'},
{'score': 0.032869212329387665,
'token': 6957,
'token_str': 'big',
'sequence': 'Europe is a big continent.'}]
以下是如何在 PyTorch 中使用此模型获取给定文本的特征:
from transformers import AutoTokenizer, AutoModelForMaskedLM
tokenizer = AutoTokenizer.from_pretrained('facebook/xlm-roberta-xxl')
model = AutoModelForMaskedLM.from_pretrained("facebook/xlm-roberta-xxl")
# prepare input
text = "Replace me by any text you'd like."
encoded_input = tokenizer(text, return_tensors='pt')
# forward pass
output = model(**encoded_input)
@article{DBLP:journals/corr/abs-2105-00572,
author = {Naman Goyal and
Jingfei Du and
Myle Ott and
Giri Anantharaman and
Alexis Conneau},
title = {Larger-Scale Transformers for Multilingual Masked Language Modeling},
journal = {CoRR},
volume = {abs/2105.00572},
year = {2021},
url = {https://arxiv.org/abs/2105.00572},
eprinttype = {arXiv},
eprint = {2105.00572},
timestamp = {Wed, 12 May 2021 15:54:31 +0200},
biburl = {https://dblp.org/rec/journals/corr/abs-2105-00572.bib},
bibsource = {dblp computer science bibliography, https://dblp.org}
}