说明文档
XLM-RoBERTa(基础规模模型)
XLM-RoBERTa 模型基于 2.5TB 经过筛选的 CommonCrawl 数据进行预训练,这些数据涵盖了 100 种语言。该模型由 Conneau 等人在论文 Unsupervised Cross-lingual Representation Learning at Scale 中提出,并首次发布于此仓库。
免责声明:发布 XLM-RoBERTa 的团队并未为该模型编写模型卡片,因此本模型卡片由 Hugging Face 团队撰写。
模型描述
XLM-RoBERTa 是 RoBERTa 的多语言版本。它基于 2.5TB 经过筛选的 CommonCrawl 数据进行预训练,这些数据涵盖了 100 种语言。
RoBERTa 是一种基于 Transformer 架构的模型,采用自监督方式在大规模语料上进行预训练。这意味着它仅在原始文本上进行预训练,无需人工对文本进行任何标注(正因如此,它可以使用大量公开可用的数据),并通过自动流程从这些文本中生成输入和标签。
更准确地说,它使用掩码语言建模(MLM)目标进行预训练。具体做法是:取一个句子,随机遮盖(mask)其中 15% 的单词,然后将整个被遮盖的句子传入模型,让模型预测被遮盖的单词。这与传统的循环神经网络(RNN,通常逐个查看单词)不同,也与内部遮盖未来标记的自回归模型(如 GPT)不同。这种方式使模型能够学习句子的双向表示。
通过这种方式,模型学习到了 100 种语言的内部表示,这些表示随后可用于提取对下游任务有用的特征:例如,如果你有一个带标签的句子数据集,你可以使用 XLM-RoBERTa 模型生成的特征作为输入来训练一个标准的分类器。
预期用途与局限性
你可以将原始模型用于掩码语言建模,但它主要用于在下游任务上进行微调。请访问 模型库 查找你感兴趣的任务的微调版本。
请注意,该模型主要针对使用整个句子(可能是被遮盖的)进行决策的任务进行微调,例如序列分类、标记分类或问答。对于文本生成等任务,你应该查看 GPT2 等模型。
使用方法
你可以直接使用该模型配合管道(pipeline)进行掩码语言建模:
>>> from transformers import pipeline
>>> unmasker = pipeline('fill-mask', model='xlm-roberta-base')
>>> unmasker("Hello I'm a <mask> model.")
[{'score': 0.10563907772302628,
'sequence': "Hello I'm a fashion model.",
'token': 54543,
'token_str': 'fashion'},
{'score': 0.08015287667512894,
'sequence': "Hello I'm a new model.",
'token': 3525,
'token_str': 'new'},
{'score': 0.033413201570510864,
'sequence': "Hello I'm a model model.",
'token': 3299,
'token_str': 'model'},
{'score': 0.030217764899134636,
'sequence': "Hello I'm a French model.",
'token': 92265,
'token_str': 'French'},
{'score': 0.026436051353812218,
'sequence': "Hello I'm a sexy model.",
'token': 17473,
'token_str': 'sexy'}]
以下是使用该模型获取 PyTorch 中给定文本特征的方法:
from transformers import AutoTokenizer, AutoModelForMaskedLM
tokenizer = AutoTokenizer.from_pretrained('xlm-roberta-base')
model = AutoModelForMaskedLM.from_pretrained("xlm-roberta-base")
# 准备输入
text = "Replace me by any text you'd like."
encoded_input = tokenizer(text, return_tensors='pt')
# 前向传播
output = model(**encoded_input)
BibTeX 引用信息
@article{DBLP:journals/corr/abs-1911-02116,
author = {Alexis Conneau and
Kartikay Khandelwal and
Naman Goyal and
Vishrav Chaudhary and
Guillaume Wenzek and
Francisco Guzm{\'{a}}n and
Edouard Grave and
Myle Ott and
Luke Zettlemoyer and
Veselin Stoyanov},
title = {Unsupervised Cross-lingual Representation Learning at Scale},
journal = {CoRR},
volume = {abs/1911.02116},
year = {2019},
url = {http://arxiv.org/abs/1911.02116},
eprinttype = {arXiv},
eprint = {1911.02116},
timestamp = {Mon, 11 Nov 2019 18:38:09 +0100},
biburl = {https://dblp.org/rec/journals/corr/abs-1911-02116.bib},
bibsource = {dblp computer science bibliography, https://dblp.org}
}
<a href="https://huggingface.co/exbert/?model=xlm-roberta-base"> <img width="300px" src="https://cdn-media.huggingface.co/exbert/button.png"> </a>
FacebookAI/xlm-roberta-base
作者 FacebookAI
创建时间: 2022-03-02 23:29:04+00:00
更新时间: 2024-02-19 12:48:21+00:00
在 Hugging Face 上查看