🚀 ALBERT XLarge v1
ALBERT XLarge v1是一个基于掩码语言建模(MLM)目标在英文语料上预训练的模型。它能够学习英语语言的内在表示,可用于下游任务特征提取,如文本分类、问答系统等。
🚀 快速开始
你可以直接使用该模型进行掩码语言建模任务,也可以对其进行微调以应用于下游任务。具体使用方法如下:
直接使用掩码语言建模管道
>>> from transformers import pipeline
>>> unmasker = pipeline('fill-mask', model='albert-xlarge-v1')
>>> unmasker("Hello I'm a [MASK] model.")
[
{
"sequence":"[CLS] hello i'm a modeling model.[SEP]",
"score":0.05816134437918663,
"token":12807,
"token_str":"â–modeling"
},
{
"sequence":"[CLS] hello i'm a modelling model.[SEP]",
"score":0.03748830780386925,
"token":23089,
"token_str":"â–modelling"
},
{
"sequence":"[CLS] hello i'm a model model.[SEP]",
"score":0.033725276589393616,
"token":1061,
"token_str":"â–model"
},
{
"sequence":"[CLS] hello i'm a runway model.[SEP]",
"score":0.017313428223133087,
"token":8014,
"token_str":"â–runway"
},
{
"sequence":"[CLS] hello i'm a lingerie model.[SEP]",
"score":0.014405295252799988,
"token":29104,
"token_str":"â–lingerie"
}
]
在PyTorch中获取给定文本的特征
from transformers import AlbertTokenizer, AlbertModel
tokenizer = AlbertTokenizer.from_pretrained('albert-xlarge-v1')
model = AlbertModel.from_pretrained("albert-xlarge-v1")
text = "Replace me by any text you'd like."
encoded_input = tokenizer(text, return_tensors='pt')
output = model(**encoded_input)
在TensorFlow中获取给定文本的特征
from transformers import AlbertTokenizer, TFAlbertModel
tokenizer = AlbertTokenizer.from_pretrained('albert-xlarge-v1')
model = TFAlbertModel.from_pretrained("albert-xlarge-v1")
text = "Replace me by any text you'd like."
encoded_input = tokenizer(text, return_tensors='tf')
output = model(encoded_input)
✨ 主要特性
- 双向表示学习:通过掩码语言建模(MLM)任务,模型能够学习句子的双向表示,这与传统的循环神经网络(RNN)和自回归模型(如GPT)不同。
- 句子顺序预测:ALBERT使用基于预测两个连续文本段顺序的预训练损失,有助于模型理解句子之间的逻辑关系。
- 参数共享:该模型在Transformer层之间共享参数,使得内存占用较小,但计算成本与具有相同隐藏层数的BERT架构相似。
📚 详细文档
模型描述
ALBERT是一个基于自监督学习方式在大量英文语料上预训练的Transformer模型。它通过以下两个目标进行预训练:
- 掩码语言建模(MLM):随机掩盖输入句子中15%的单词,然后让模型预测这些被掩盖的单词,从而学习句子的双向表示。
- 句子顺序预测(SOP):基于预测两个连续文本段的顺序来进行预训练。
通过这种方式,模型学习到英语语言的内在表示,可用于下游任务的特征提取。
模型配置
- 24个重复层
- 128维嵌入维度
- 2048维隐藏维度
- 16个注意力头
- 5800万个参数
预期用途和限制
该模型可用于掩码语言建模或下一句预测,但主要用于下游任务的微调。需要注意的是,该模型主要针对使用整个句子(可能被掩码)进行决策的任务,如序列分类、标记分类或问答系统。对于文本生成任务,建议使用GPT2等模型。
局限性和偏差
尽管该模型的训练数据相对中立,但仍可能存在有偏差的预测。这种偏差也会影响该模型的所有微调版本。
训练数据
ALBERT模型在BookCorpus(包含11038本未出版书籍的数据集)和英文维基百科(不包括列表、表格和标题)上进行预训练。
训练过程
预处理
文本先转换为小写,然后使用SentencePiece进行分词,词汇表大小为30000。模型的输入形式为:
[CLS] Sentence A [SEP] Sentence B [SEP]
训练
ALBERT的训练过程遵循BERT的设置。每个句子的掩码过程细节如下:
- 15%的标记被掩码。
- 80%的情况下,被掩码的标记被替换为
[MASK]
。
- 10%的情况下,被掩码的标记被替换为一个随机标记。
- 10%的情况下,被掩码的标记保持不变。
评估结果
当在下游任务上进行微调时,ALBERT模型取得了以下结果:
版本 |
平均 |
SQuAD1.1 |
SQuAD2.0 |
MNLI |
SST - 2 |
RACE |
V2 |
|
|
|
|
|
|
ALBERT - base |
82.3 |
90.2/83.2 |
82.1/79.3 |
84.6 |
92.9 |
66.8 |
ALBERT - large |
85.7 |
91.8/85.2 |
84.9/81.8 |
86.5 |
94.9 |
75.2 |
ALBERT - xlarge |
87.9 |
92.9/86.4 |
87.9/84.1 |
87.9 |
95.4 |
80.7 |
ALBERT - xxlarge |
90.9 |
94.6/89.1 |
89.8/86.9 |
90.6 |
96.8 |
86.8 |
V1 |
|
|
|
|
|
|
ALBERT - base |
80.1 |
89.3/82.3 |
80.0/77.1 |
81.6 |
90.3 |
64.0 |
ALBERT - large |
82.4 |
90.6/83.9 |
82.3/79.4 |
83.5 |
91.7 |
68.5 |
ALBERT - xlarge |
85.5 |
92.5/86.1 |
86.1/83.1 |
86.4 |
92.4 |
74.8 |
ALBERT - xxlarge |
91.0 |
94.8/89.3 |
90.2/87.4 |
90.8 |
96.9 |
86.5 |
BibTeX引用
@article{DBLP:journals/corr/abs-1909-11942,
author = {Zhenzhong Lan and
Mingda Chen and
Sebastian Goodman and
Kevin Gimpel and
Piyush Sharma and
Radu Soricut},
title = {{ALBERT:} {A} Lite {BERT} for Self-supervised Learning of Language
Representations},
journal = {CoRR},
volume = {abs/1909.11942},
year = {2019},
url = {http://arxiv.org/abs/1909.11942},
archivePrefix = {arXiv},
eprint = {1909.11942},
timestamp = {Fri, 27 Sep 2019 13:04:21 +0200},
biburl = {https://dblp.org/rec/journals/corr/abs-1909-11942.bib},
bibsource = {dblp computer science bibliography, https://dblp.org}
}
📄 许可证
本项目采用Apache 2.0许可证。