CAMeLBERT:面向阿拉伯语自然语言处理任务的预训练模型集
模型描述
CAMeLBERT 是一系列基于阿拉伯语文本预训练的BERT模型集合,包含不同规模与变体版本。我们发布了针对现代标准阿拉伯语(MSA)、阿拉伯语方言(DA)及古典阿拉伯语(CA)的预训练语言模型,以及融合三种变体的混合模型。此外还提供基于MSA变体缩减训练集(1/2、1/4、1/8、1/16比例)的衍生模型。技术细节详见论文《阿拉伯语预训练语言模型中变体、规模与任务类型的交互作用》。
本模型卡描述的是CAMeLBERT-CA(bert-base-arabic-camelbert-ca
),该模型基于古典阿拉伯语(CA)数据集预训练。
|
模型 |
变体 |
规模 |
词量 |
|
bert-base-arabic-camelbert-mix |
CA,DA,MSA |
167GB |
173亿 |
✔ |
bert-base-arabic-camelbert-ca |
CA |
6GB |
8.47亿 |
|
bert-base-arabic-camelbert-da |
DA |
54GB |
58亿 |
|
bert-base-arabic-camelbert-msa |
MSA |
107GB |
126亿 |
|
bert-base-arabic-camelbert-msa-half |
MSA |
53GB |
63亿 |
|
bert-base-arabic-camelbert-msa-quarter |
MSA |
27GB |
31亿 |
|
bert-base-arabic-camelbert-msa-eighth |
MSA |
14GB |
16亿 |
|
bert-base-arabic-camelbert-msa-sixteenth |
MSA |
6GB |
7.46亿 |
适用范围
本模型可直接用于掩码语言建模或下一句预测任务,但主要设计目的是在NER、词性标注、情感分析、方言识别及诗歌分类等NLP任务上进行微调。微调代码已发布于GitHub仓库。
使用方法
通过pipeline直接进行掩码预测:
>>> from transformers import pipeline
>>> unmasker = pipeline('fill-mask', model='CAMeL-Lab/bert-base-arabic-camelbert-ca')
>>> unmasker("الهدف من الحياة هو [MASK] .")
[{'sequence': '[CLS] الهدف من الحياة هو الحياة. [SEP]',
'score': 0.11048116534948349,
'token': 3696,
'token_str': 'الحياة'},
{'sequence': '[CLS] الهدف من الحياة هو الإسلام. [SEP]',
'score': 0.03481195122003555,
'token': 4677,
'token_str': 'الإسلام'},
{'sequence': '[CLS] الهدف من الحياة هو الموت. [SEP]',
'score': 0.03402028977870941,
'token': 4295,
'token_str': 'الموت'},
{'sequence': '[CLS] الهدف من الحياة هو العلم. [SEP]',
'score': 0.027655426412820816,
'token': 2789,
'token_str': 'العلم'},
{'sequence': '[CLS] الهدف من الحياة هو هذا. [SEP]',
'score': 0.023059621453285217,
'token': 2085,
'token_str': 'هذا'}]
注意:需使用transformers>=3.5.0
版本,或手动下载模型。
PyTorch特征提取示例:
from transformers import AutoTokenizer, AutoModel
tokenizer = AutoTokenizer.from_pretrained('CAMeL-Lab/bert-base-arabic-camelbert-ca')
model = AutoModel.from_pretrained('CAMeL-Lab/bert-base-arabic-camelbert-ca')
text = "مرحبا يا عالم."
encoded_input = tokenizer(text, return_tensors='pt')
output = model(**encoded_input)
TensorFlow示例:
from transformers import AutoTokenizer, TFAutoModel
tokenizer = AutoTokenizer.from_pretrained('CAMeL-Lab/bert-base-arabic-camelbert-ca')
model = TFAutoModel.from_pretrained('CAMeL-Lab/bert-base-arabic-camelbert-ca')
text = "مرحبا يا عالم."
encoded_input = tokenizer(text, return_tensors='tf')
output = model(encoded_input)
训练数据
训练流程
采用Google发布的原始BERT实现,除特别说明外均遵循英文BERT的超参数设置。
预处理
- 使用原始BERT工具清除无效字符并规范化空格
- 移除非阿拉伯字符行
- 通过CAMeL工具集去除变音符号和连接线
- 基于启发式规则分句
- 使用HuggingFace tokenizers在全数据集(167GB)上训练30,000词表的WordPiece分词器
- 保留字母大小写及重音符号
预训练
- 单块v3-8云TPU训练100万步
- 前90,000步batch size为1,024,后续调整为256
- 90%步数采用128token序列长度,10%采用512长度
- 采用全词掩码,重复因子10
- 128长度序列最大预测20词,512长度预测80词
- 随机种子12345,掩码概率15%,短序列概率10%
- 使用Adam优化器(学习率1e-4,β₁=0.9,β₂=0.999),权重衰减0.01,10,000步学习率预热后线性衰减
评估结果
在NER、词性标注、情感分析、方言识别和诗歌分类5类任务(12个数据集)上评估,使用HuggingFace transformers v3.1.0+PyTorch v1.5.1微调,采用F₁分数作为评估指标。
详细结果
任务 |
数据集 |
变体 |
混合 |
CA |
DA |
MSA |
MSA-1/2 |
MSA-1/4 |
MSA-1/8 |
MSA-1/16 |
NER |
ANERcorp |
MSA |
80.8% |
67.9% |
74.1% |
82.4% |
82.0% |
82.1% |
82.6% |
80.8% |
词性标注 |
PATB (MSA) |
MSA |
98.1% |
97.8% |
97.7% |
98.3% |
98.2% |
98.3% |
98.2% |
98.2% |
|
ARZTB (埃及) |
DA |
93.6% |
92.3% |
92.7% |
93.6% |
93.6% |
93.7% |
93.6% |
93.6% |
|
Gumar (海湾) |
DA |
97.3% |
97.7% |
97.9% |
97.9% |
97.9% |
97.9% |
97.9% |
97.9% |
情感分析 |
ASTD |
MSA |
76.3% |
69.4% |
74.6% |
76.9% |
76.0% |
76.8% |
76.7% |
75.3% |
|
ArSAS |
MSA |
92.7% |
89.4% |
91.8% |
93.0% |
92.6% |
92.5% |
92.5% |
92.3% |
|
SemEval |
MSA |
69.0% |
58.5% |
68.4% |
72.1% |
70.7% |
72.8% |
71.6% |
71.2% |
方言识别 |
MADAR-26 |
DA |
62.9% |
61.9% |
61.8% |
62.6% |
62.0% |
62.8% |
62.0% |
62.2% |
|
MADAR-6 |
DA |
92.5% |
91.5% |
92.2% |
91.9% |
91.8% |
92.2% |
92.1% |
92.0% |
|
MADAR-Twitter-5 |
MSA |
75.7% |
71.4% |
74.2% |
77.6% |
78.5% |
77.3% |
77.7% |
76.2% |
|
NADI |
DA |
24.7% |
17.3% |
20.1% |
24.9% |
24.6% |
24.6% |
24.9% |
23.8% |
诗歌分类 |
APCD |
CA |
79.8% |
80.9% |
79.6% |
79.7% |
79.9% |
80.0% |
79.7% |
79.8% |
平均结果
|
变体 |
混合 |
CA |
DA |
MSA |
MSA-1/2 |
MSA-1/4 |
MSA-1/8 |
MSA-1/16 |
变体平均[1] |
MSA |
82.1% |
75.7% |
80.1% |
83.4% |
83.0% |
83.3% |
83.2% |
82.3% |
|
DA |
74.4% |
72.1% |
72.9% |
74.2% |
74.0% |
74.3% |
74.1% |
73.9% |
|
CA |
79.8% |
80.9% |
79.6% |
79.7% |
79.9% |
80.0% |
79.7% |
79.8% |
宏观平均 |
全部 |
78.7% |
74.7% |
77.1% |
79.2% |
79.0% |
79.2% |
79.1% |
78.6% |
[1]:变体平均指同语言变体任务组的平均得分
致谢
本研究使用Google TensorFlow研究云(TFRC)提供的Cloud TPU完成。
引用
@inproceedings{inoue-etal-2021-interplay,
title = "阿拉伯语预训练语言模型中变体、规模与任务类型的交互作用",
author = "井上豪 和 Alhafni, Bashar 和 Baimukan, Nurpeiis 和 Bouamor, Houda 和 Habash, Nizar",
booktitle = "第六届阿拉伯自然语言处理研讨会论文集",
month = "4月",
year = "2021",
address = "乌克兰基辅(线上)",
publisher = "计算语言学协会",
abstract = "本文通过构建现代标准阿拉伯语、阿拉伯语方言及古典阿拉伯语的预训练模型,探究语言变体、数据规模与微调任务类型的影响。结果表明:微调数据与预训练数据的变体相近性比预训练数据规模更重要,据此我们建立了针对研究任务的优化系统选择模型。",
}