英文

ALBERT Base v1

在英语文本上使用掩码语言建模 (MLM) 目标进行预训练的模型。它在 this paper 中被介绍并首次发布于 this repository 。与所有的ALBERT模型一样,这个模型是非大小写区分的:它不区分英文和English。

免责声明:ALBERT团队并没有为这个模型编写模型卡片,所以这个模型卡片是由Hugging Face团队编写的。

模型描述

ALBERT是一个基于大量英文数据进行自我监督预训练的transformers模型。这意味着它仅基于原始文本进行预训练,而没有人为地对其进行任何方式的标注(这就是为什么它可以使用大量公开可用的数据),并通过自动生成输入和标签的过程从这些文本中生成输入和标签。更准确地说,它是通过以下两个目标进行预训练的:

  • 掩码语言建模 (MLM):将一个句子,模型会随机屏蔽输入中15%的单词,然后将整个屏蔽的句子通过模型,并预测屏蔽的单词。这与通常以一个接一个地看到单词的传统递归神经网络(RNN)或像GPT那样在内部屏蔽未来令牌的自回归模型不同。它使模型能够学习句子的双向表示。
  • 句子顺序预测 (SOP):ALBERT使用基于预测两个连续文本段的顺序的预训练损失函数。

如此一来,该模型学习到了英语语言的内在表示,可以用于提取对下游任务有用的特征:如果你有一个带有标记句子的数据集,你可以使用ALBERT模型生成的特征作为分类器的输入进行训练。

ALBERT的独特之处在于它在它的Transformer中共享其层。因此,所有层都具有相同的权重。使用重复的层可以减少内存占用,但计算成本与具有相同数量隐藏层的BERT-like结构相似,因为它必须遍历相同数量的(重复的)层。

这是基础模型的第一个版本。版本2与版本1不同,具有不同的丢弃率、额外的训练数据和更长的训练时间。在几乎所有下游任务中,它在性能上有了更好的表现。

该模型的配置如下:

  • 12个重复层
  • 128个嵌入维度
  • 768个隐藏维度
  • 12个注意力头
  • 1100万参数

预期用途和局限性

您可以将原始模型用于掩码语言建模或下一个句子预测,但它主要用于在下游任务上进行微调。查看 model hub 以寻找您感兴趣的任务的微调版本。

需要注意的是,这个模型主要用于在整个句子(可能是掩码的)上做出决策的任务,例如序列分类、标记分类或问答。对于文本生成等任务,您应该查看像GPT2这样的模型。

如何使用

您可以直接使用掩码语言建模的流水线来使用这个模型:

>>> from transformers import pipeline
>>> unmasker = pipeline('fill-mask', model='albert-base-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-base-v1')
model = AlbertModel.from_pretrained("albert-base-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-base-v1')
model = TFAlbertModel.from_pretrained("albert-base-v1")
text = "Replace me by any text you'd like."
encoded_input = tokenizer(text, return_tensors='tf')
output = model(encoded_input)

局限性和偏差

即使用于这个模型的训练数据可以被认为是相当中立的,这个模型也可能产生有偏见的预测:

>>> from transformers import pipeline
>>> unmasker = pipeline('fill-mask', model='albert-base-v1')
>>> unmasker("The man worked as a [MASK].")

[
   {
      "sequence":"[CLS] the man worked as a chauffeur.[SEP]",
      "score":0.029577180743217468,
      "token":28744,
      "token_str":"▁chauffeur"
   },
   {
      "sequence":"[CLS] the man worked as a janitor.[SEP]",
      "score":0.028865724802017212,
      "token":29477,
      "token_str":"▁janitor"
   },
   {
      "sequence":"[CLS] the man worked as a shoemaker.[SEP]",
      "score":0.02581118606030941,
      "token":29024,
      "token_str":"▁shoemaker"
   },
   {
      "sequence":"[CLS] the man worked as a blacksmith.[SEP]",
      "score":0.01849772222340107,
      "token":21238,
      "token_str":"▁blacksmith"
   },
   {
      "sequence":"[CLS] the man worked as a lawyer.[SEP]",
      "score":0.01820771023631096,
      "token":3672,
      "token_str":"▁lawyer"
   }
]

>>> unmasker("The woman worked as a [MASK].")

[
   {
      "sequence":"[CLS] the woman worked as a receptionist.[SEP]",
      "score":0.04604868218302727,
      "token":25331,
      "token_str":"▁receptionist"
   },
   {
      "sequence":"[CLS] the woman worked as a janitor.[SEP]",
      "score":0.028220869600772858,
      "token":29477,
      "token_str":"▁janitor"
   },
   {
      "sequence":"[CLS] the woman worked as a paramedic.[SEP]",
      "score":0.0261906236410141,
      "token":23386,
      "token_str":"▁paramedic"
   },
   {
      "sequence":"[CLS] the woman worked as a chauffeur.[SEP]",
      "score":0.024797942489385605,
      "token":28744,
      "token_str":"▁chauffeur"
   },
   {
      "sequence":"[CLS] the woman worked as a waitress.[SEP]",
      "score":0.024124596267938614,
      "token":13678,
      "token_str":"▁waitress"
   }
]

这种偏见也会影响到该模型的所有微调版本。

训练数据

ALBERT模型是在 BookCorpus 上进行预训练的,该数据集包括11,038本未发表的书籍和 English Wikipedia (不包括列表、表格和标题)。

训练过程

预处理

文本经过小写处理,并使用SentencePiece进行分词,词汇表大小为30,000。模型的输入形式如下:

[CLS] Sentence A [SEP] Sentence B [SEP]

训练

ALBERT的训练过程遵循BERT的设置。

每个句子的掩码过程的细节如下:

  • 15%的令牌被屏蔽。
  • 在80%的情况下,屏蔽的令牌被替换为 [MASK]。
  • 在10%的情况下,屏蔽的令牌被一个与其不同的随机令牌替换。
  • 在剩下的10%的情况下,屏蔽的令牌保持不变。

评估结果

当在下游任务上进行微调时,ALBERT模型实现了以下结果:

Average 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}
}