🚀 AraBERT v1 & v2:用于阿拉伯语理解的BERT预训练模型
AraBERT是一个基于谷歌的BERT架构的阿拉伯语预训练语言模型。它采用了与BERT - Base相同的配置。更多详细信息可查看《AraBERT论文》和《AraBERT线上研讨会》。
该模型有两个版本,即AraBERTv0.1和AraBERTv1,区别在于AraBERTv1使用预分割文本,其中前缀和后缀使用Farasa分割器进行分割。
我们在不同的下游任务上评估了AraBERT模型,并将其与mBERT和其他最先进的模型进行了比较(就我们所知)。这些任务包括在6个不同数据集上的情感分析(HARD、ASTD - Balanced、ArsenTD - Lev、LABR)、使用ANERcorp进行的命名实体识别,以及在Arabic - SQuAD和ARCD上进行的阿拉伯语问答。
✨ 主要特性
AraBERTv2
新增内容
AraBERT现在有4个新变体来取代旧的v1版本:
更多细节可在AraBERT文件夹、README和《AraBERT论文》中查看。
模型 |
HuggingFace模型名称 |
大小 (MB/参数) |
预分割 |
数据集 (句子数/大小/单词数) |
AraBERTv0.2 - base |
[bert - base - arabertv02](https://huggingface.co/aubmindlab/bert - base - arabertv02) |
543MB / 136M |
否 |
2亿 / 77GB / 86亿 |
AraBERTv0.2 - large |
[bert - large - arabertv02](https://huggingface.co/aubmindlab/bert - large - arabertv02) |
1.38G / 371M |
否 |
2亿 / 77GB / 86亿 |
AraBERTv2 - base |
[bert - base - arabertv2](https://huggingface.co/aubmindlab/bert - base - arabertv2) |
543MB / 136M |
是 |
2亿 / 77GB / 86亿 |
AraBERTv2 - large |
[bert - large - arabertv2](https://huggingface.co/aubmindlab/bert - large - arabertv2) |
1.38G / 371M |
是 |
2亿 / 77GB / 86亿 |
AraBERTv0.1 - base |
[bert - base - arabertv01](https://huggingface.co/aubmindlab/bert - base - arabertv01) |
543MB / 136M |
否 |
7700万 / 23GB / 27亿 |
AraBERTv1 - base |
[bert - base - arabert](https://huggingface.co/aubmindlab/bert - base - arabert) |
543MB / 136M |
是 |
7700万 / 23GB / 27亿 |
所有模型都可以在HuggingFace
模型页面的aubmindlab名下找到。检查点有PyTorch、TF2和TF1格式。
更好的预处理和新词汇表
我们发现了AraBERTv1的词块词汇表存在一个问题。该问题源于在学习词块词汇表时,标点符号和数字仍然与单词相连。现在,我们在数字和字符之间以及标点字符周围插入了一个空格。
新的词汇表是使用tokenizers
库中的BertWordpieceTokenizer
学习得到的,现在应该支持transformers
库中的快速分词器实现。
注意:所有旧的BERT代码应该可以与新的BERT一起使用,只需更改模型名称并检查新的预处理函数。请阅读关于如何使用预处理函数的部分。
更大的数据集和更多的计算资源
我们使用了大约3.5倍的数据,并进行了更长时间的训练。
有关数据集来源,请参阅数据集部分。
模型 |
硬件 |
序列长度为(128 / 512)的示例数量 |
128 (批量大小/步数) |
512 (批量大小/步数) |
总步数 |
总时间 (天) |
AraBERTv0.2 - base |
TPUv3 - 8 |
4.2亿 / 2.07亿 |
2560 / 100万 |
384 / 200万 |
300万 |
- |
AraBERTv0.2 - large |
TPUv3 - 128 |
4.2亿 / 2.07亿 |
13440 / 25万 |
2056 / 30万 |
55万 |
7 |
AraBERTv2 - base |
TPUv3 - 8 |
4.2亿 / 2.07亿 |
2560 / 100万 |
384 / 200万 |
300万 |
- |
AraBERTv2 - large |
TPUv3 - 128 |
5.2亿 / 2.45亿 |
13440 / 25万 |
2056 / 30万 |
55万 |
7 |
AraBERT - base (v1/v0.1) |
TPUv2 - 8 |
- |
512 / 90万 |
128 / 30万 |
120万 |
4 |
数据集
用于新AraBERT模型的预训练数据也用于阿拉伯语GPT2和ELECTRA。
该数据集包含77GB、200,095,961行、8,655,948,860个单词或82,232,988,358个字符(在应用Farasa分割之前)。
对于新数据集,我们在之前用于AraBERTv1的数据集基础上添加了未打乱的OSCAR语料库,但去掉了之前爬取的网站:
- 未打乱并经过过滤的OSCAR语料库。
- [2020/09/01的阿拉伯语维基百科转储](https://archive.org/details/arwiki - 20190201)
- [15亿单词的阿拉伯语语料库](https://www.semanticscholar.org/paper/1.5 - billion - words - Arabic - Corpus - El - Khair/f3eeef4afb81223df96575adadf808fe7fe440b4)
- [OSIAN语料库](https://www.aclweb.org/anthology/W19 - 4619)
- Assafir新闻文章。非常感谢Assafir提供数据。
📦 安装指南
建议在任何数据集上进行训练/测试之前应用我们的预处理函数。
安装farasapy以对AraBERT v1 & v2进行文本分割 pip install farasapy
💻 使用示例
基础用法
from arabert.preprocess import ArabertPreprocessor
model_name="bert-large-arabertv02"
arabert_prep = ArabertPreprocessor(model_name=model_name)
text = "ولن نبالغ إذا قلنا إن هاتف أو كمبيوتر المكتب في زمننا هذا ضروري"
arabert_prep.preprocess(text)
支持的模型
bert-base-arabertv01
bert-base-arabert
bert-base-arabertv02
bert-base-arabertv2
bert-large-arabertv02
bert-large-arabertv2
araelectra-base
aragpt2-base
aragpt2-medium
aragpt2-large
aragpt2-mega
📚 详细文档
TensorFlow 1.x模型
TF1.x模型可在HuggingFace模型仓库中找到。
你可以按以下方式下载它们:
curl -s https://packagecloud.io/install/repositories/github/git-lfs/script.deb.sh | sudo bash
sudo apt-get install git-lfs
git lfs install
git clone https://huggingface.co/aubmindlab/MODEL_NAME
tar -C ./MODEL_NAME -zxvf /content/MODEL_NAME/tf1_model.tar.gz
其中MODEL_NAME
是aubmindlab
名下的任何模型。
- 通过
wget
:
- 访问huggingface.co/models/aubmindlab/MODEL_NAME上的tf1_model.tar.gz文件。
- 复制
oid sha256
。
- 然后运行
wget https://cdn-lfs.huggingface.co/aubmindlab/aragpt2-base/INSERT_THE_SHA_HERE
(例如,对于aragpt2 - base
:wget https://cdn-lfs.huggingface.co/aubmindlab/aragpt2-base/3766fc03d7c2593ff2fb991d275e96b81b0ecb2098b71ff315611d052ce65248
)
引用
如果你使用了这个模型,请按以下方式引用我们:
谷歌学术的Bibtex引用有误(缺少名称),请使用以下内容:
@inproceedings{antoun2020arabert,
title={AraBERT: Transformer-based Model for Arabic Language Understanding},
author={Antoun, Wissam and Baly, Fady and Hajj, Hazem},
booktitle={LREC 2020 Workshop Language Resources and Evaluation Conference 11--16 May 2020},
pages={9}
}
致谢
感谢TensorFlow研究云(TFRC)免费提供Cloud TPU访问权限,没有这个项目我们无法完成这项工作;感谢AUB MIND实验室成员的持续支持。此外,感谢Yakshof和Assafir提供数据和存储访问权限。还要感谢Habib Rahal(https://www.behance.net/rahalhabib)为AraBERT设计了形象。
联系方式
Wissam Antoun:领英 | 推特 | Github | wfa07@mail.aub.edu | wissam.antoun@gmail.com
Fady Baly:领英 | 推特 | Github | fgb06@mail.aub.edu | baly.fady@gmail.com