模型:
deepmind/language-perceiver
Perceiver IO模型是在 BERT 中建议的掩码语言建模(MLM)任务上进行预训练的,使用了通过合并 English Wikipedia 和 C4 获得的大型文本语料库。它是由Jaegle等人在 Perceiver IO: A General Architecture for Structured Inputs & Outputs 论文中提出的,并于 this repository 首次发布。
免责声明:发布Perceiver IO的团队没有为该模型编写模型卡片,因此本模型卡片由Hugging Face团队编写。
Perceiver IO是一种可以应用于任何形式(文本、图像、音频、视频等)的Transformer编码器模型。其核心思想是在一组不太大的潜在向量上使用自注意机制,并且仅使用输入与潜在向量进行交叉注意力。这样可以使自注意机制的时间和内存需求不依赖于输入的大小。
为了解码,作者使用所谓的解码器查询,它可以灵活地解码最终的潜在隐藏状态,以生成任意大小和语义的输出。对于掩码语言建模,输出是一个包含语言建模头的预测分数的张量,形状为(批处理大小,序列长度,词汇表大小)。
Perceiver IO架构。
由于自注意机制的时间和内存需求不依赖于输入的大小,Perceiver IO的作者直接在原始的UTF-8字节上训练模型,而不是像BERT、RoBERTa和GPT-2等模型那样在子词上进行训练。这样做有很多好处:在训练模型之前不需要训练分词器,不需要维护一个(固定的)词汇表文件,而且正如 Bostrom et al., 2020 所示,这也不会损害模型性能。
通过预训练模型,它学习了语言的内在表示,然后可以用于提取对下游任务有用的特征:例如,如果你有一个带标签的句子数据集,可以使用Perceiver模型生成的特征作为分类器的输入进行训练。
您可以使用原始模型进行掩码语言建模,但该模型旨在在标记的数据集上进行微调。查看 model hub 以寻找您感兴趣的任务的微调版本。
以下是在PyTorch中使用此模型的方法:
from transformers import PerceiverTokenizer, PerceiverForMaskedLM tokenizer = PerceiverTokenizer.from_pretrained("deepmind/language-perceiver") model = PerceiverForMaskedLM.from_pretrained("deepmind/language-perceiver") text = "This is an incomplete sentence where some words are missing." # prepare input encoding = tokenizer(text, padding="max_length", return_tensors="pt") # mask " missing.". Note that the model performs much better if the masked span starts with a space. encoding.input_ids[0, 52:61] = tokenizer.mask_token_id inputs, input_mask = encoding.input_ids.to(device), encoding.attention_mask.to(device) # forward pass outputs = model(inputs=inputs, attention_mask=input_mask) logits = outputs.logits masked_tokens_predictions = logits[0, 51:61].argmax(dim=-1) print(tokenizer.decode(masked_tokens_predictions)) >>> should print " missing."
该模型是在 English Wikipedia 和 C4 的组合上进行预训练的。训练词元的70%取自C4数据集,剩余30%取自维基百科。作者在分割成片段之前将10个文档进行连接,以减少对填充词元的不必要计算。
文本预处理非常简单:只需将文本编码为UTF-8字节,并将其填充到相同长度(2048)。
超参数详细信息可以在 paper 的表格9中找到。
该模型能够在GLUE上实现81.8的平均得分。有关更多详情,请参阅原始论文的表格3。
@article{DBLP:journals/corr/abs-2107-14795, author = {Andrew Jaegle and Sebastian Borgeaud and Jean{-}Baptiste Alayrac and Carl Doersch and Catalin Ionescu and David Ding and Skanda Koppula and Daniel Zoran and Andrew Brock and Evan Shelhamer and Olivier J. H{\'{e}}naff and Matthew M. Botvinick and Andrew Zisserman and Oriol Vinyals and Jo{\~{a}}o Carreira}, title = {Perceiver {IO:} {A} General Architecture for Structured Inputs {\&} Outputs}, journal = {CoRR}, volume = {abs/2107.14795}, year = {2021}, url = {https://arxiv.org/abs/2107.14795}, eprinttype = {arXiv}, eprint = {2107.14795}, timestamp = {Tue, 03 Aug 2021 14:53:34 +0200}, biburl = {https://dblp.org/rec/journals/corr/abs-2107-14795.bib}, bibsource = {dblp computer science bibliography, https://dblp.org} }