Home

Awesome

ARBERT & MARBERT: Deep Bidirectional Transformers for Arabic

<img src="ARBERT_MARBERT.jpg" alt="drawing" width="30%" height="30%" align="right"/>

What is the repository is about?

This is the repository accompanying our ACL 2021 paper ARBERT & MARBERT: Deep Bidirectional Transformers for Arabic. In the paper, we:

Our models establish new state-of-the-art (SOTA) on all 5 tasks/task clusters on 37 out of the 41 datasets. Our language models are publicaly available for research (see below). The rest of this repository provides more information about our new language models, benchmark, and experiments.


Table of Contents


1. Our Language Models

1.1 ARBERT & MARBERT

ARBERT is a large scale pre-training masked language model focused on Modern Standard Arabic (MSA). To train ARBERT, we use the same architecture as BERT-base: 12 attention layers, each has 12 attention heads and 768 hidden dimensions, a vocabulary of 100K WordPieces, making ∼163M parameters. We train ARBERT on a collection of Arabic datasets comprising 61GB of text (6.2B tokens)

MARBERT is a large scale pre-training masked language model focused on both Dialectal Arabic (DA) and MSA. Arabic has multiple varieties. To train MARBERT, we randomly sample 1B Arabic tweets from a large in-house dataset of about 6B tweets. We only include tweets with at least 3 Arabic words, based on character string matching, regardless whether the tweet has non-Arabic string or not. That is, we do not remove non-Arabic so long as the tweet meets the 3 Arabic word criterion. The dataset makes up 128GB of text (15.6B tokens). We use the same network architecture as ARBERT (BERT-base), but without the next sentence prediction (NSP) objective since tweets are short. See our repo for modifying BERT code to remove NSP.

1.2 Training Data and Vocabulary

The following table shows a comparison between ARBERT and MARBERT, on the one hand, and mBERT, XLM-R, and AraBERT, on the other hand. We compare in terms of pre-training data sources and size, vocabulary size, and model parameter size.

Data Source#Tokens(ar/all)TokanizationVocab Size(ar/all)CasedArch.#Param
mBERTWikipedia153M/1.5BWordPiece5K/110Kyesbase110M
XLM-R<sub>B</sub>CommonCrawl2.9B/295BSentencePiece14K/250Kyesbase270M
XLM-R<sub>L</sub>CommonCrawl2.9B/295BSentencePiece14K/250Kyeslarge550M
AraBERTSeveral (3 sources)2.5B/2.5BSentencePiece60K/64Knobase135M
ARBERTSeveral (6 sources)6.2B/6.2BWordPiece100K/100Knobase163M
MARBERTArabic Twitter15.6B/15.6BWordPiece100K/100Knobase163M

2. Our Benchmark: ArBench

To evaluate our models, we also introduce ArBench, a new benchmark for multi-dialectal Arabic language understanding. ArBench is built using 41 datasets targeting 5 different tasks/task clusters, allowing us to offer a series of standardized experiments under rich conditions. The following are the different tasks/task clusers covered by ArBench:

2.1 Sentiment Analysis

ReferenceData (#classes)TRAINDEVTEST
Alomari et al. (2017)AJGT (2)1.4K-361
Abdul-Mageed et al. (2020b)AraNET<sub>Sent</sub> (2)100K14.3K11.8K
Al-Twairesh et al. (2017)AraSenTi (3)11,1171,4071,382
Abu Farha and Magdy (2017)ArSarcasm<sub>Sent</sub> (3)8.4K-2.K
Elmadany et al. (2018)ArSAS (3)24.7K-3.6K
Baly et al. (2019)ArsenTD-LEV (5)3.2K-801
Nabil et al. (2015)ASTD (3)24.7K-664
Nabil et al. (2015)ASTD-B (2)1.06K-267
Abdul-Mageed and Diab (2012)AWATIF (4)2.28K288284
Salameh et al. (2015)BBN (3)960125116
Elnagar et al. (2018) HARD (2)84.5K-21.1K
Nabil et al. (2015)LABR (2)13.1K3.28K
Abdul-Mageed and Diab (2014)SAMAR (5)2.49K310316
Rosenthal et al. (2017)SemEval (3)24.7K-6.10K
Salameh et al. (2015)SYTS(3)960202199
Saad (2019)Twitter<sub>Saad</sub> (2)1.5K202190
Abdullah et al. (2013)Twitter<sub>Abdullah</sub> (2)46k5.77k5.82k

2.2 Social Meaning

ReferenceTaskData (#classes)TRAINDEVTEST
Zaghouani and Charfi (2018)AgeArap-Tweet (3)1.28M160K160K
Zaghouani and Charfi (2018)GenderArap-Tweet (2)1.28M160K160K
Abdul-Mageed et al. (2020b)EmotionAraNET<sub>Emo</sub> (8)189K911942
Abu Farha and Magdy (2017)SarcasmAraSarcasm (2)8.4K-2.1K
Alshehri et al. (2020a)DangerousAraDang (2)3.4K616664
Ghanem et al. (2019)IronyFIRE2019 (2)3.6K-404
Mubarak et al. (2020)OffensiveOSACT-A (2)10K1K2K
Mubarak et al. (2020)Hate SpeechOSACT-B - (2)10K1K2K

2.3 Topic Classification

ReferenceData (#classes)TRAINDEVTEST
Saad and Ashour (2010)OSAC (10)17.9K2.24K2.24K
Abbas et al. (2011)Khallej (4)4.55K570570
Chouigui et al. (2017)ANT(5)25.2K31.5K31.5K

2.4 Dialect Identification

ReferenceData (#classes)TaskTRAINDEVTEST
Zaidan and Callison-Burch (2014)AOC (2)Binary86.5K10.8K10.8K
Zaidan and Callison-Burch (2014)AOC (3)Region35.7K4.46K4.45K
Zaidan and Callison-Burch (2014)AOC (4)Region86.5K10.8K10.8K
Farha and Magdy (2020)ArSarcasm<sub>Dia</sub> (5)Regoin8.43K-2.11K
Bouamor et al. (2019)MADAR-TL (21)Country193K26.6K43.9K
Abdul-Mageed et al. (2020)NADI (21)Country2.1K4.96K5K
Abdul-Mageed et al. (2020)NADI (100)Province2.1K4.96K5K
Abdelali et al. (2020)QADI (18)Country498K-3.5K

2.5 Named Entity Recogntion

ReferenceDataset#Tokens#PER#LOC#ORG
Benajiba and Rosso (2007)ANERCorp150K6.50K5.01K3.43K
Mitchell et al. (2004)ACE-2003BN15K8321.22K288
Mitchell et al. (2004)ACE-2003NW27K1.14K1.14K893
Mitchell et al. (2005)ACE-2004BN70K3.20K3.92K2.23K
Darwish (2013)TW-NER81K1.25K1.30K765

3 Model Evaluation

When fine-tuned on ArBench, ARBERT and MARBERT collectively achieve new SOTA with sizeable margins compared to all existing models such as mBERT, XLM-R (Base and Large), and AraBERT on 37 out of 45 classification tasks on the 41 datasets (82.22%). We present our results on the different TEST sets in the subsections below. For performance on DEV sets, please see appendixes in our paper.

3.1 Sentiment Analysis

Dataset (#classes)mBERTXLM-R<sub>B</sub>XLM-R<sub>L</sub>AraBERTARBERTMARBERT
AJGT (2)86.6789.4491.9492.2294.4496.11
HARD (2)95.5495.7495.9695.8996.1296.17
ArsenTD-LEV (5)50.5055.2562.0056.1361.3860.38
LABR (2)91.2091.2392.2091.9792.5192.49
ASTD-B(2)79.3287.5977.4483.0893.2396.24

Results reported based on Acc. score

Dataset (#classes)mBERTXLM-R<sub>B</sub>XLM-R<sub>L</sub>AraBERTARBERTMARBERT
ArSAS (3)87.5090.0091.5091.0092.0093.00
ASTD (3)67.0060.6767.6772.0076.5078.00
SemEval (3)57.0064.0067.0062.0069.0071.00
AraNET<sub>Sent</sub> (2)84.0092.0093.0086.5089.0092.00
ArSarcasm<sub>Sent</sub> (3)60.5063.5070.0063.5068.0071.50
AraSenTi (noura) (3)89.5092.0093.5091.0090.0090.00
BBN(3)55.5069.5046.5070.0076.5079.00
SYTS(3)67.0078.0040.5075.5079.0076.50
Twitter<sub>Saad</sub> (2)79.0095.0095.0081.0090.0096.00
SAMAR(5)22.5054.0057.0036.5043.5055.50
AWATIF(4)60.5063.5068.5066.5071.5072.50
Twitter<sub>Abdullah</sub> (2)81.5091.0092.0089.5091.5095.00

Results reported based on F<sub>1</sub><sup>NP</sup> score.

3.2 Social Meaning

Task (#classes)DatasetmBERTXLM-R<sub>B</sub>XLM-R<sub>L</sub>AraBERTARBERTMARBERT
Offensive (2)OSACT-A84.2585.2688.2886.5790.3892.41
Hate Speech(2)OSACT-B72.8171.3379.3178.8983.0284.79
Dangerous (2)Dangerous62.6662.7665.0164.3763.2167.53
Sarcasm (2)AraSarcasm68.2066.7669.2372.2375.0476.30
Emotion (8)AraNET<sub>Emo</sub>65.7970.6774.8965.6867.7375.83
Irony (2)FIRE201980.9681.9782.52%83.0185.5985.33
Age (3)Arab_Tweet56.3559.7353.6057.7258.9562.27
Gender (2)Arab_Tweet68.0671.0071.1467.7569.8672.62

Results reported based on F<sub>1</sub> score.

3.3 Topic Classification

Dataset (#classes)mBERTXLM-R<sub>B</sub>XLM-R<sub>L</sub>AraBERTARBERTMARBERT
OSAC (10)96.8497.1598.2097.0397.5097.23
Khallej (4)92.8191.8793.5693.8394.5393.63
ANT<sub>Text</sub> (5)84.8985.7786.7288.1786.8785.27
ANT<sub>Title</sub> (5)78.2979.9681.2581.0381.7081.19
ANT<sub>Text+Title</sub> (5)84.6786.2186.9687.2287.2185.60

Results reported based on F<sub>1</sub> score.

3.4 Dialect Identification

Task (#classes)DatasetmBERTXLM-R<sub>B</sub>XLM-R<sub>L</sub>AraBERTARBERTMARBERT
Regoin (5)ArSarcasm<sub>Dia</sub>43.8141.7141.8347.5451.2754.70
Country (21)MADAR-TL34.9235.9135.1434.8737.9040.40
Region (4)AOC77.2777.3478.7779.2081.0982.37
Region (3)AOC85.7686.3987.5687.6889.0690.85
Binary (4)AOC86.1986.8587.3087.7688.4688.59
Country(18)QADI66.5777.0082.7372.2388.6390.89
Country(21)NADI13.3216.3617.1717.4622.5629.14
Province (100 )NADI2.134.120.323.136.106.28

Results reported based on F<sub>1</sub> score.

3.5 Named Entity Recogntion

DatasetmBERTXLM-R<sub>B</sub>XLM-R<sub>L</sub>AraBERTARBERTMARBERT
ANERcorp.86.7887.2489.9489.1384.3880.64
ACE 2004 NW86.3789.9389.8989.0388.2485.02
ACE 2003BN91.2353.9785.4191.9496.1879.05
ACE 2003NW81.4087.2490.6288.0990.0987.76
TW-NER36.8349.1654.4441.2659.1767.39

Results reported based on F<sub>1</sub> score.


4. How to use ARBERT and MARBERT

4.1 Loading directly from Huggingface

You can use ARBERT and MARBERT with Hugging Face's Transformers library as follow.

   from transformers import AutoTokenizer, AutoModel
   #load AEBERT model from huggingface
   ARBERT_tokenizer = AutoTokenizer.from_pretrained("UBC-NLP/ARBERT")
   ARBERT_model = AutoModel.from_pretrained("UBC-NLP/ARBERT")
 
   #load MAEBERT model from huggingface
   MARBERT_tokenizer = AutoTokenizer.from_pretrained("UBC-NLP/MARBERT")
   MARBERT_model = AutoModel.from_pretrained("UBC-NLP/MARBERT") 

4.2 Example: Fine-tuning MARBERT for Sentiment Analysis

MARBERT Fine-Tuning demo with PyTorch checkpoint for Sentiment Analysis on the AJGT dataset Open In Colab

5. Ethics

Our models are developed using data from the public domain. We provide access to our models to accelerate scientific research with no liability on our part. Please use our models and benchmark only ethically. This includes, for example, respect and protection of people's privacy. We encourage all researchers who decide to use our models to adhere to the highest standards. For example, if you apply our models on Twitter data, we encourage you to review Twitter policy at Twitter policy. For example, Twitter provides the following policy around use of sensitive information:

Sensitive information

You should be careful about using Twitter data to derive or infer potentially sensitive characteristics about Twitter users. Never derive or infer, or store derived or inferred, information about a Twitter user’s:


6. Download ARBERT and MARBERT Checkpoints

ARBERT and MARBERT Pytorch and Tenserflow checkpoints are available on Huggingface website for direct download and use exclusively for research. For commercial use, please contact the authors via email @ (*muhammad.mageed[at]ubc[dot]ca*).

ModelPytorch CheckpointTensorflow Checkpoint
ARBERTDownloadDownload
MARBERTDownloadDownload

7. Citation

If you use our models (ARBERT or MARBERT) for your scientific publication, or if you find the resources in this repository useful, please cite our paper as follows (to be updated):

@inproceedings{abdul-mageed-etal-2021-arbert,
    title = "{ARBERT} {\&} {MARBERT}: Deep Bidirectional Transformers for {A}rabic",
    author = "Abdul-Mageed, Muhammad  and
      Elmadany, AbdelRahim  and
      Nagoudi, El Moatez Billah",
    booktitle = "Proceedings of the 59th Annual Meeting of the Association for Computational Linguistics and the 11th International Joint Conference on Natural Language Processing (Volume 1: Long Papers)",
    month = aug,
    year = "2021",
    address = "Online",
    publisher = "Association for Computational Linguistics",
    url = "https://aclanthology.org/2021.acl-long.551",
    doi = "10.18653/v1/2021.acl-long.551",
    pages = "7088--7105",
    abstract = "Pre-trained language models (LMs) are currently integral to many natural language processing systems. Although multilingual LMs were also introduced to serve many languages, these have limitations such as being costly at inference time and the size and diversity of non-English data involved in their pre-training. We remedy these issues for a collection of diverse Arabic varieties by introducing two powerful deep bidirectional transformer-based models, ARBERT and MARBERT. To evaluate our models, we also introduce ARLUE, a new benchmark for multi-dialectal Arabic language understanding evaluation. ARLUE is built using 42 datasets targeting six different task clusters, allowing us to offer a series of standardized experiments under rich conditions. When fine-tuned on ARLUE, our models collectively achieve new state-of-the-art results across the majority of tasks (37 out of 48 classification tasks, on the 42 datasets). Our best model acquires the highest ARLUE score (77.40) across all six task clusters, outperforming all other models including XLM-R Large ( 3.4x larger size). Our models are publicly available at https://github.com/UBC-NLP/marbert and ARLUE will be released through the same repository.",
}


8. Acknowledgments

We gratefully acknowledge support from the Natural Sciences and Engineering Research Council of Canada, the Social Sciences and Humanities Research Council of Canada, Canadian Foundation for Innovation, ComputeCanada and UBC ARC-Sockeye. We also thank the Google TensorFlow Research Cloud (TFRC) program for providing us with free TPU access.