模型概述
模型特點
模型能力
使用案例
🚀 ALBERT XLarge v2
ALBERT XLarge v2是一個基於掩碼語言建模(MLM)目標在英文語料上進行預訓練的模型。它能學習到英文語言的內在表示,可用於提取對下游任務有用的特徵,在多個自然語言處理任務中表現出色。
🚀 快速開始
你可以直接使用該模型進行掩碼語言建模或下一句預測,但它主要用於在下游任務上進行微調。你可以在模型中心查找針對你感興趣任務的微調版本。
✨ 主要特性
- 自監督預訓練:在大量英文數據上以自監督方式進行預訓練,學習到英文語言的內在表示。
- 獨特架構:在Transformer中共享層,所有層具有相同的權重,內存佔用小。
- 版本優化:版本2與版本1相比,由於不同的丟棄率、額外的訓練數據和更長的訓練時間,在幾乎所有下游任務中都有更好的表現。
📦 安裝指南
文檔未提及具體安裝步驟,可參考Hugging Face的transformers庫安裝說明。
💻 使用示例
基礎用法
你可以使用管道直接進行掩碼語言建模:
>>> 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)
📚 詳細文檔
模型描述
ALBERT是一個在大量英文數據上以自監督方式進行預訓練的Transformer模型。它通過兩個目標進行預訓練:
- 掩碼語言建模(MLM):隨機掩蓋輸入句子中15%的單詞,然後讓模型預測這些被掩蓋的單詞,從而學習句子的雙向表示。
- 句子順序預測(SOP):基於預測兩個連續文本片段的順序的預訓練損失。
ALBERT的特殊之處在於它在Transformer中共享層,所有層具有相同的權重。使用重複層可以減少內存佔用,但計算成本與具有相同隱藏層數的BERT架構相似。
這是xlarge模型的第二個版本。版本2與版本1不同,由於不同的丟棄率、額外的訓練數據和更長的訓練時間,在幾乎所有下游任務中都有更好的表現。
該模型具有以下配置:
屬性 | 詳情 |
---|---|
層數 | 24個重複層 |
嵌入維度 | 128 |
隱藏維度 | 2048 |
注意力頭 | 16 |
參數數量 | 5800萬 |
預期用途與限制
該模型主要用於在使用整個句子(可能是掩碼的)進行決策的任務上進行微調,如序列分類、標記分類或問答。對於文本生成等任務,你應該考慮使用GPT2等模型。
侷限性和偏差
即使該模型使用的訓練數據可以被描述為相當中立,但該模型仍可能存在有偏差的預測:
>>> 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和英文維基百科(不包括列表、表格和標題)上進行預訓練。
訓練過程
預處理
文本先轉換為小寫,然後使用SentencePiece進行分詞,詞彙表大小為30,000。模型的輸入形式如下:
[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許可證。



