🚀 ALBERT Large v1
ALBERT Large v1是一個基於英語語料庫,採用掩碼語言模型(MLM)目標進行預訓練的模型。它能學習英語語言的內在表示,為下游任務提取有用特徵,在自然語言處理領域有廣泛應用。
🚀 快速開始
你可以直接使用此模型進行掩碼語言建模,也可以將其微調用於下游任務。以下是使用示例:
>>> from transformers import pipeline
>>> unmasker = pipeline('fill-mask', model='albert-large-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"
}
]
✨ 主要特性
- 雙向表示學習:通過掩碼語言建模(MLM),模型可以學習句子的雙向表示,這與傳統的循環神經網絡(RNN)和自迴歸模型(如GPT)不同。
- 句子順序預測:使用句子順序預測(SOP)損失,進一步學習文本的語義和結構。
- 參數共享:ALBERT在Transformer層之間共享權重,減少了內存佔用,但計算成本與具有相同隱藏層數的BERT架構相似。
📦 安裝指南
文檔未提及安裝步驟,故跳過此章節。
💻 使用示例
基礎用法
以下是使用此模型獲取給定文本特徵的PyTorch代碼示例:
from transformers import AlbertTokenizer, AlbertModel
tokenizer = AlbertTokenizer.from_pretrained('albert-large-v1')
model = AlbertModel.from_pretrained("albert-large-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-large-v1')
model = TFAlbertModel.from_pretrained("albert-large-v1")
text = "Replace me by any text you'd like."
encoded_input = tokenizer(text, return_tensors='tf')
output = model(encoded_input)
📚 詳細文檔
模型描述
ALBERT是一個基於大規模英語語料庫,以自監督方式進行預訓練的Transformer模型。它通過掩碼語言建模(MLM)和句子順序預測(SOP)兩個目標進行訓練,學習英語語言的內在表示,可用於下游任務的特徵提取。
此模型是大模型的第一個版本,版本2由於不同的丟棄率、額外的訓練數據和更長的訓練時間,在幾乎所有下游任務中都有更好的表現。
該模型具有以下配置:
- 24個重複層
- 128維嵌入維度
- 1024維隱藏維度
- 16個注意力頭
- 1700萬個參數
預期用途和限制
你可以使用原始模型進行掩碼語言建模或下一句預測,但它主要用於下游任務的微調。此模型主要針對需要使用整個句子(可能被掩碼)進行決策的任務,如序列分類、標記分類或問答任務。對於文本生成任務,建議使用GPT2等模型。
侷限性和偏差
儘管此模型的訓練數據相對中立,但它仍可能產生有偏差的預測。這種偏差也會影響該模型的所有微調版本。
訓練數據
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}
}
🔧 技術細節
ALBERT通過共享Transformer層的權重,減少了模型的內存佔用。其掩碼語言建模(MLM)和句子順序預測(SOP)的訓練目標,使得模型能夠學習到句子的雙向表示和文本的語義結構。在訓練過程中,採用了特定的掩碼策略,以提高模型的性能。
📄 許可證
本項目採用Apache-2.0許可證。