HuggingFace镜像/albert-xlarge-v2
模型介绍文件和版本分析
下载使用量0

ALBERT XLarge v2

基于英语语言的预训练模型,采用掩码语言模型(MLM)目标进行训练。与所有 ALBERT 模型一样,本模型不区分大小写:“english”和“English”对模型而言没有区别。

模型说明

ALBERT 是一种基于 Transformer 的模型,在大规模英语语料库上以自监督方式进行预训练。这意味着它仅在原始文本上进行预训练,无需人工对文本进行任何形式的标注(因此可以利用大量公开可用的数据),并通过自动流程从这些文本中生成输入和标签。更准确地说,它通过两个目标进行预训练:

  • 掩码语言模型(MLM):对于一个句子,模型随机掩盖输入中 15% 的词语,然后将整个被掩盖的句子输入模型,模型需要预测被掩盖的词语。这与传统的循环神经网络(RNNs)通常逐个处理词语,或者与像 GPT 这样的自回归模型在内部掩盖未来标记的方式不同。这种方式使模型能够学习句子的双向表示。
  • 句子顺序预测(SOP):ALBERT 使用一种基于预测两个连续文本片段顺序的预训练损失函数。

通过这种方式,模型学习到英语语言的内部表示,该表示可用于提取对下游任务有用的特征:例如,如果您有一个带标签的句子数据集,您可以使用 ALBERT 模型生成的特征作为输入来训练一个标准分类器。

ALBERT 的特别之处在于其 Transformer 的层是共享的。因此,所有层都具有相同的权重。使用重复层可以减小内存占用,然而,其计算成本仍与具有相同隐藏层数的类 BERT 架构相似,因为它必须迭代相同数量的(重复)层。

这是 xlarge 模型的第二个版本。版本 2 与版本 1 的区别在于不同的 dropout 率、额外的训练数据以及更长的训练时间。它在几乎所有下游任务中都取得了更好的结果。

该模型具有以下配置:

  • 24 个重复层
  • 128 维嵌入维度
  • 2048 维隐藏层维度
  • 16 个注意力头
  • 5800 万参数

预期用途和局限性

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

请注意,此模型主要用于在需要使用整个句子(可能带有掩码)来做出决策的任务上进行微调,例如序列分类、 token 分类或问答任务。对于文本生成等任务,您应考虑 GPT2 等模型。

使用方法

您可以直接通过管道将此模型用于掩码语言建模:

>>> from transformers import pipeline
>>> unmasker = pipeline('fill-mask', model='albert-xlarge-v2')
>>> 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-v2')
model = AlbertModel.from_pretrained("albert-xlarge-v2")
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-v2')
model = TFAlbertModel.from_pretrained("albert-xlarge-v2")
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-xlarge-v2')
>>> 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 和 English Wikipedia(不包含列表、表格和标题)上进行预训练的。其中,BookCorpus 是一个包含 11,038 本未出版书籍的数据集。

训练过程

预处理

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

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

训练

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

每个句子的掩码处理细节如下:

  • 15% 的 token 被掩码。
  • 80% 的情况下,被掩码的 token 会替换为 [MASK]。
  • 10% 的情况下,被掩码的 token 会替换为一个随机的(不同的)token。
  • 剩余 10% 的情况下,被掩码的 token 保持不变。

评估结果

在下游任务上进行微调后,ALBERT 模型取得了以下结果:

平均值SQuAD1.1SQuAD2.0MNLISST-2RACE
V2
ALBERT-base82.390.2/83.282.1/79.384.692.966.8
ALBERT-large85.791.8/85.284.9/81.886.594.975.2
ALBERT-xlarge87.992.9/86.487.9/84.187.995.480.7
ALBERT-xxlarge90.994.6/89.189.8/86.990.696.886.8
V1
ALBERT-base80.189.3/82.380.0/77.181.690.364.0
ALBERT-large82.490.6/83.982.3/79.483.591.768.5
ALBERT-xlarge85.592.5/86.186.1/83.186.492.474.8
ALBERT-xxlarge91.094.8/89.390.2/87.490.896.986.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}
}