CAMeLBERT: A collection of pre-trained models for Arabic NLP tasks
Model description
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
."
This model card describes
CAMeLBERT-DA
(
bert-base-arabic-camelbert-da
), a model pre-trained on the DA (dialectal Arabic) dataset.
Model
Variant
Size
#Word
bert-base-arabic-camelbert-mix
CA,DA,MSA
167GB
17.3B
bert-base-arabic-camelbert-ca
CA
6GB
847M
✔
bert-base-arabic-camelbert-da
DA
54GB
5.8B
bert-base-arabic-camelbert-msa
MSA
107GB
12.6B
bert-base-arabic-camelbert-msa-half
MSA
53GB
6.3B
bert-base-arabic-camelbert-msa-quarter
MSA
27GB
3.1B
bert-base-arabic-camelbert-msa-eighth
MSA
14GB
1.6B
bert-base-arabic-camelbert-msa-sixteenth
MSA
6GB
746M
Intended uses
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
.
How to use
You can use this model directly with a pipeline for masked language modeling:
>>> from transformers import pipeline
>>> unmasker = pipeline('fill-mask', model='CAMeL-Lab/bert-base-arabic-camelbert-da')
>>> unmasker("الهدف من الحياة هو [MASK] .")
[{'sequence': '[CLS] الهدف من الحياة هو.. [SEP]',
'score': 0.062508225440979,
'token': 18,
'token_str': '.'},
{'sequence': '[CLS] الهدف من الحياة هو الموت. [SEP]',
'score': 0.033172328025102615,
'token': 4295,
'token_str': 'الموت'},
{'sequence': '[CLS] الهدف من الحياة هو الحياة. [SEP]',
'score': 0.029575437307357788,
'token': 3696,
'token_str': 'الحياة'},
{'sequence': '[CLS] الهدف من الحياة هو الرحيل. [SEP]',
'score': 0.02724040113389492,
'token': 11449,
'token_str': 'الرحيل'},
{'sequence': '[CLS] الهدف من الحياة هو الحب. [SEP]',
'score': 0.01564178802073002,
'token': 3088,
'token_str': 'الحب'}]
Note
: to download our models, you would need
transformers>=3.5.0
. Otherwise, you could download the models manually.
Here is how to use this model to get the features of a given text in PyTorch:
from transformers import AutoTokenizer, AutoModel
tokenizer = AutoTokenizer.from_pretrained('CAMeL-Lab/bert-base-arabic-camelbert-da')
model = AutoModel.from_pretrained('CAMeL-Lab/bert-base-arabic-camelbert-da')
text = "مرحبا يا عالم."
encoded_input = tokenizer(text, return_tensors='pt')
output = model(**encoded_input)
and in TensorFlow:
from transformers import AutoTokenizer, TFAutoModel
tokenizer = AutoTokenizer.from_pretrained('CAMeL-Lab/bert-base-arabic-camelbert-da')
model = TFAutoModel.from_pretrained('CAMeL-Lab/bert-base-arabic-camelbert-da')
text = "مرحبا يا عالم."
encoded_input = tokenizer(text, return_tensors='tf')
output = model(encoded_input)
Training data
DA (dialectal Arabic)
A collection of dialectal Arabic data described in
our paper
.
Training procedure
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.
Preprocessing
After extracting the raw text from each corpus, we apply the following pre-processing.
We also remove lines without any Arabic characters.
We then remove diacritics and kashida using
CAMeL Tools
.
Finally, we split each line into sentences with a heuristics-based sentence segmenter.
We train a WordPiece tokenizer on the entire dataset (167 GB text) with a vocabulary size of 30,000 using
HuggingFace's tokenizers
.
We do not lowercase letters nor strip accents.
Pre-training
The model was trained on a single cloud TPU (
v3-8
) for one million steps in total.
The first 90,000 steps were trained with a batch size of 1,024 and the rest was trained with a batch size of 256.
The sequence length was limited to 128 tokens for 90% of the steps and 512 for the remaining 10%.
We use whole word masking and a duplicate factor of 10.
We set max predictions per sequence to 20 for the dataset with max sequence length of 128 tokens and 80 for the dataset with max sequence length of 512 tokens.
We use a random seed of 12345, masked language model probability of 0.15, and short sequence probability of 0.1.
The optimizer used is Adam with a learning rate of 1e-4,
β
1
=
0.9
and
β
2
=
0.999
, a weight decay of 0.01, learning rate warmup for 10,000 steps and linear decay of the learning rate after.
Evaluation results
We evaluate our pre-trained language models on five NLP tasks: NER, POS tagging, sentiment analysis, dialect identification, and poetry classification.
We fine-tune and evaluate the models using 12 dataset.
We used Hugging Face's transformers to fine-tune our CAMeLBERT models.
We used transformers
v3.1.0
along with PyTorch
v1.5.1
.
The fine-tuning was done by adding a fully connected linear layer to the last hidden state.
[1]
: Variant-wise-average refers to average over a group of tasks in the same language variant.
Acknowledgements
This research was supported with Cloud TPUs from Google’s TensorFlow Research Cloud (TFRC).
Citation
@inproceedings{inoue-etal-2021-interplay,
title = "The Interplay of Variant, Size, and Task Type in {A}rabic Pre-trained Language Models",
author = "Inoue, Go and
Alhafni, Bashar and
Baimukan, Nurpeiis and
Bouamor, Houda and
Habash, Nizar",
booktitle = "Proceedings of the Sixth Arabic Natural Language Processing Workshop",
month = apr,
year = "2021",
address = "Kyiv, Ukraine (Online)",
publisher = "Association for Computational Linguistics",
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.",
}
Runs of CAMeL-Lab bert-base-arabic-camelbert-da on huggingface.co
2.1K
Total runs
-20
24-hour runs
-7
3-day runs
-179
7-day runs
-722
30-day runs
More Information About bert-base-arabic-camelbert-da huggingface.co Model
More bert-base-arabic-camelbert-da license Visit here:
bert-base-arabic-camelbert-da huggingface.co is an AI model on huggingface.co that provides bert-base-arabic-camelbert-da's model effect (), which can be used instantly with this CAMeL-Lab bert-base-arabic-camelbert-da model. huggingface.co supports a free trial of the bert-base-arabic-camelbert-da model, and also provides paid use of the bert-base-arabic-camelbert-da. Support call bert-base-arabic-camelbert-da model through api, including Node.js, Python, http.
bert-base-arabic-camelbert-da huggingface.co is an online trial and call api platform, which integrates bert-base-arabic-camelbert-da's modeling effects, including api services, and provides a free online trial of bert-base-arabic-camelbert-da, you can try bert-base-arabic-camelbert-da online for free by clicking the link below.
CAMeL-Lab bert-base-arabic-camelbert-da online free url in huggingface.co:
bert-base-arabic-camelbert-da is an open source model from GitHub that offers a free installation service, and any user can find bert-base-arabic-camelbert-da on GitHub to install. At the same time, huggingface.co provides the effect of bert-base-arabic-camelbert-da install, users can directly use bert-base-arabic-camelbert-da installed effect in huggingface.co for debugging and trial. It also supports api for free installation.
bert-base-arabic-camelbert-da install url in huggingface.co: