Encoder-only PLM RoBERTa & ALBERT (BERT的变体)

发布于:2025-06-26 ⋅ 阅读:(21) ⋅ 点赞:(0)

目录

RoBERTa

去除 NSP 任务

改进MLM

数据量:扩展无监督语料

增大 batch size

更长的训练周期与统一的序列长度

优化了子词编码策略(BPE)

ALBERT

嵌入参数分解

跨层参数共享

提出 SOP 预训练任务

参考文章


RoBERTa

去除 NSP 任务

We find that this setting outperforms the originally published BERT BASE results and that removing the NSP loss matches or slightly improves downstream task performance, in contrast to Devlin et al. (2019).

RoBERTa 通过实验发现 NSP 任务对模型性能无显著提升,甚至可能产生负面影响。论文对比了四种实验组:

  • 段落构建的 MLM + NSP(BERT 原始设置)
  • 文档对构建的 MLM + NSP(增大 Batch Size)
  • 跨文档的 MLM(去 NSP,输入来自多个文档)
  • 单文档的 MLM(去 NSP,输入仅限单文档)

实验结果显示,后两组(仅 MLM)显著优于前两组,且单文档 MLM 表现最佳。因此,RoBERTa 移除了 NSP 任务,仅保留 MLM

Finally we find that restricting sequences to come from a single document (DOC-SENTENCES) performs slightly better than packing sequences from multiple documents (FULL-SENTENCES).

单个文档的设置略优于从多个文档中拼接的设置,而 RoBERTa 为了实验对比的方便,选择了 从多个文档中拼接

改进MLM

The original BERT implementation performed masking once during data preprocessing, resulting in a single static mask.

BERT 的原始实现采用 静态掩码(Static Masking),即在数据预处理阶段一次性生成掩码(masking pattern),导致每个训练序列在多个 epoch 中重复使用相同的掩码模式

We compare this strategy with dynamic mask ing where we generate the masking pattern every time we feed a sequence to the model. This be comes crucial when pretraining for more steps or with larger datasets.

RoBERTa 采用 动态掩码(Dynamic Masking),即在每次将序列输入模型时 实时生成掩码模式,而非预处理阶段固定掩码

更高的多样性:每次训练迭代中,同一序列会以不同的掩码方式输入模型,迫使模型学习更鲁棒的上下文表示

适应更长的预训练和更大数据集:动态掩码避免了静态掩码导致的过拟合问题,尤其在长时间预训练或大规模数据集中效果显著

RoBERTa 的动态掩码策略被后续模型(如 ALBERT)广泛采用,成为 MLM 预训练的标准实践

数据量:扩展无监督语料

Past work in Neural Machine Translation has shown that training with very large mini-batches can both improve optimization speed and end-task performance when the learning rate is increased appropriately (Ott et al., 2018).

RoBERTa 使用了比 BERT 多十倍的无监督数据(160GB),新增了 CC-NEWS、OPENWEBTEXT 和 STORIES 等数据集

增大 batch size

We observe that training with large batches improves perplexity for the masked language modeling objective, as well as end-task accuracy. Large batches are also easier to parallelize via distributed data parallel training...

优化速度:大批次训练可充分利用分布式硬件(如 GPU/TPU 集群),加速计算

模型性能:论文实验证明,大批次能降低 MLM 目标的困惑度(perplexity),并提升下游任务的准确率

更长的训练周期与统一的序列长度

更多训练步数:RoBERTa 的 500K 步(66 个 Epoch)远超 BERT 的 1M 步(1 个 Epoch),使模型更充分地学习语言模式

统一序列长度:512 长度能捕捉更长的上下文依赖(如长文档或复杂句子),而 BERT 的 256 长度限制了上下文建模能力。BERT 采用的是在 256 长度上进行大部分训练再在 512 长度上完成训练的策略

优化了子词编码策略(BPE)

BERT使用的是字符级的BPE(Character-Level BPE),其词表大小为30K。这种编码方式依赖于字符级别的统计分析,通过预处理规则(如分词)生成子词单元。例如,英文单词“unhappiness”可能被切分为“un”,“happi”,“ness”等子词单元

Following Radford et al. (2019), we instead consider training BERT with a larger byte-level BPE vocabulary containing 50K sub word units, without any additional preprocessing or tokenization of the input.

RoBERTa改用字节级的BPE(Byte-Level BPE),其词表大小为50K。字节级BPE以字节(8-bit单位)作为基础单元,无需依赖字符或分词规则。例如,UTF-8编码中的汉字“我”会被表示为字节序列“E6 88 91”,BPE可能将其切分为“E688”和“91”两个子词单元


ALBERT

嵌入参数分解

在BERT中,词汇嵌入(WordPiece embedding)的维度E与隐藏层维度H是绑定的(即E=H)。这种设计导致参数量爆炸,尤其是当H增大时,嵌入矩阵的规模V×H会急剧增长(V为词表大小)。例如,BERT-large的V=30,000,H=1024,嵌入参数量高达30,000×1024=30.72M

Instead of projecting the one-hot vectors directly into the hidden space of size H, we first project them into a lower dimensional embedding space of size E, and then project it to the hidden space.

BERT的嵌入参数量为O(VH)。

ALBERT将其分解为O(VE+EH)。当H远大于E时,参数量显著减少。例如,若E=128,H=1024,则参数量从30,000×1024=30.72M降至30,000×128+128×1024=3.84+131=3.97M

跨层参数共享

BERT的每一层encoder都有独立的参数,导致参数量随层数线性增长。例如,BERT-large有24层,参数量达334M

For ALBERT, we propose cross-layer parameter sharing (跨层参数共享) as an other way to improve parameter efficiency.The default decision for ALBERT is to share all parameters across layers.

仅初始化一个encoder层,但在计算时重复使用该层24次。例如,ALBERT-large的参数量仅为18M,而BERT-large为334M

通过共享参数,ALBERT-xlarge的参数量(59M)仅为BERT-large的1/6,但模型效果更优

提出 SOP 预训练任务

NSP任务过于简单,模型可能仅依赖主题预测(topic prediction)而非连贯性(coherence)

SOP 任务提出的改进是,正例同样由两个连续句子组成,但负例是将这两个的顺序反过来

参考文章

Liu, Y., Ott, M., Goyal, N., Du, J., Joshi, M., Chen, D., ..., & Stoyanov, V. (2019). RoBERTa: A robustly optimized BERT pretraining approach. arXiv preprint arXiv:1907.11692.

datawhale.com happy-llm

happy-llm/docs/chapter3/第三章 预训练语言模型.md at main · datawhalechina/happy-llmhttps://github.com/datawhalechina/happy-llm/blob/main/docs/chapter3/%E7%AC%AC%E4%B8%89%E7%AB%A0%20%E9%A2%84%E8%AE%AD%E7%BB%83%E8%AF%AD%E8%A8%80%E6%A8%A1%E5%9E%8B.md#312-robertaLan Z , Chen M , Goodman S ,et al.ALBERT: A Lite BERT for Self-supervised Learning of Language Representations[J]. 2019.DOI:10.48550/arXiv.1909.11942.


网站公告

今日签到

点亮在社区的每一天
去签到