模型简介
模型特点
模型能力
使用案例
🚀 用于语言处理的Perceiver IO模型
Perceiver IO是一种预训练模型,它基于BERT中提出的掩码语言建模(MLM)任务进行训练。训练使用的大型文本语料库由英文维基百科和C4组合而成。该模型由Jaegle等人在论文Perceiver IO: A General Architecture for Structured Inputs & Outputs中提出,并首次在这个仓库发布。
声明:发布Perceiver IO的团队并未为该模型撰写模型卡片,此模型卡片由Hugging Face团队编写。
✨ 主要特性
Perceiver IO是一种Transformer编码器模型,可应用于任何模态(文本、图像、音频、视频等)。其核心思想是在一组规模不大的潜在向量(如256或512个)上应用自注意力机制,仅使用输入与潜在向量进行交叉注意力计算。这使得自注意力机制的时间和内存需求不依赖于输入的大小。
在解码时,作者采用了所谓的解码器查询,它可以灵活地对潜在向量的最终隐藏状态进行解码,以生成任意大小和语义的输出。对于掩码语言建模,输出是一个张量,包含语言建模头的预测分数,形状为(batch_size, seq_length, vocab_size)。
由于自注意力机制的时间和内存需求不依赖于输入大小,Perceiver IO的作者直接在原始UTF - 8字节上训练模型,而不是像BERT、RoBERTa和GPT - 2等模型那样在子词上训练。这样做有很多好处:训练模型前无需训练分词器,无需维护(固定的)词汇文件,并且如Bostrom等人,2020所示,这也不会损害模型性能。
通过预训练,模型学习到语言的内部表示,可用于提取对下游任务有用的特征。例如,如果有一个带标签的句子数据集,可以使用Perceiver模型生成的特征作为输入来训练一个标准分类器。
🚀 快速开始
预期用途和限制
可以使用原始模型进行掩码语言建模,但该模型旨在在带标签的数据集上进行微调。请查看模型中心,寻找针对感兴趣任务的微调版本。
如何使用
以下是在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."
📦 安装指南
文档未提及安装步骤,故跳过此章节。
💻 使用示例
基础用法
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."
📚 详细文档
训练数据
该模型在英文维基百科和C4的组合数据集上进行预训练。训练令牌的70%从C4数据集中采样,其余30%从维基百科中采样。作者在分割成作物之前将10个文档连接起来,以减少对填充令牌的浪费计算。
训练过程
预处理
文本预处理很简单:仅涉及将文本编码为UTF - 8字节,并将它们填充到相同的长度(2048)。
预训练
超参数的详细信息可以在论文的表9中找到。
评估结果
该模型在GLUE上能够达到平均81.8分。更多详细信息,请参考原论文的表3。
BibTeX引用和引用信息
@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}
}
📄 许可证
本模型采用Apache - 2.0许可证。
属性 | 详情 |
---|---|
模型类型 | Transformer编码器模型 |
训练数据 | 结合了英文维基百科和C4数据集,70%的训练令牌来自C4数据集,30%来自维基百科 |



