CAMeLBERT is a collection of BERT models pre-trained on Arabic texts with different sizes and variants.
We release pre-trained language models for Modern Standard Arabic (MSA), dialectal Arabic (DA), and classical Arabic (CA), in addition to a model pre-trained on a mix of the three.
We also provide additional models that are pre-trained on a scaled-down set of the MSA variant (half, quarter, eighth, and sixteenth).
The details are described in the paper
"The Interplay of Variant, Size, and Task Type in Arabic Pre-trained Language Models."
You can use the released model for either masked language modeling or next sentence prediction.
However, it is mostly intended to be fine-tuned on an NLP task, such as NER, POS tagging, sentiment analysis, dialect identification, and poetry classification.
We release our fine-tuninig code
here.
1>>> from transformers import pipeline
2>>> unmasker = pipeline('fill-mask', model='CAMeL-Lab/bert-base-arabic-camelbert-da')
3>>> unmasker("الهدف من الحياة هو [MASK] .")
4[{'sequence': '[CLS] الهدف من الحياة هو.. [SEP]',
5 'score': 0.062508225440979,
6 'token': 18,
7 'token_str': '.'},
8 {'sequence': '[CLS] الهدف من الحياة هو الموت. [SEP]',
9 'score': 0.033172328025102615,
10 'token': 4295,
11 'token_str': 'الموت'},
12 {'sequence': '[CLS] الهدف من الحياة هو الحياة. [SEP]',
13 'score': 0.029575437307357788,
14 'token': 3696,
15 'token_str': 'الحياة'},
16 {'sequence': '[CLS] الهدف من الحياة هو الرحيل. [SEP]',
17 'score': 0.02724040113389492,
18 'token': 11449,
19 'token_str': 'الرحيل'},
20 {'sequence': '[CLS] الهدف من الحياة هو الحب. [SEP]',
21 'score': 0.01564178802073002,
22 'token': 3088,
23 'token_str': 'الحب'}]
1from transformers import AutoTokenizer, AutoModel
2tokenizer = AutoTokenizer.from_pretrained('CAMeL-Lab/bert-base-arabic-camelbert-da')
3model = AutoModel.from_pretrained('CAMeL-Lab/bert-base-arabic-camelbert-da')
4text = "مرحبا يا عالم."
5encoded_input = tokenizer(text, return_tensors='pt')
6output = model(**encoded_input)
1from transformers import AutoTokenizer, TFAutoModel
2tokenizer = AutoTokenizer.from_pretrained('CAMeL-Lab/bert-base-arabic-camelbert-da')
3model = TFAutoModel.from_pretrained('CAMeL-Lab/bert-base-arabic-camelbert-da')
4text = "مرحبا يا عالم."
5encoded_input = tokenizer(text, return_tensors='tf')
6output = model(encoded_input)
We use
the original implementation released by Google for pre-training.
We follow the original English BERT model's hyperparameters for pre-training, unless otherwise specified.
[1]: Variant-wise-average refers to average over a group of tasks in the same language variant.
This research was supported with Cloud TPUs from Google’s TensorFlow Research Cloud (TFRC).
1@inproceedings{inoue-etal-2021-interplay,
2 title = "The Interplay of Variant, Size, and Task Type in {A}rabic Pre-trained Language Models",
3 author = "Inoue, Go and
4 Alhafni, Bashar and
5 Baimukan, Nurpeiis and
6 Bouamor, Houda and
7 Habash, Nizar",
8 booktitle = "Proceedings of the Sixth Arabic Natural Language Processing Workshop",
9 month = apr,
10 year = "2021",
11 address = "Kyiv, Ukraine (Online)",
12 publisher = "Association for Computational Linguistics",
13 abstract = "In this paper, we explore the effects of language variants, data sizes, and fine-tuning task types in Arabic pre-trained language models. To do so, we build three pre-trained language models across three variants of Arabic: Modern Standard Arabic (MSA), dialectal Arabic, and classical Arabic, in addition to a fourth language model which is pre-trained on a mix of the three. We also examine the importance of pre-training data size by building additional models that are pre-trained on a scaled-down set of the MSA variant. We compare our different models to each other, as well as to eight publicly available models by fine-tuning them on five NLP tasks spanning 12 datasets. Our results suggest that the variant proximity of pre-training data to fine-tuning data is more important than the pre-training data size. We exploit this insight in defining an optimized system selection model for the studied tasks.",
14}