🚀 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許可證。