Fill-Mask
Transformers
Safetensors
PyTorch
Arabic
bert
arabic
maghrebi-arabic
darija
arabizi
code-switching
algeria
morocco
tunisia
libya
masked-language-modeling
Instructions to use NumidiaNLP/MagharibiBERT with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use NumidiaNLP/MagharibiBERT with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("fill-mask", model="NumidiaNLP/MagharibiBERT")# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForMaskedLM tokenizer = AutoTokenizer.from_pretrained("NumidiaNLP/MagharibiBERT") model = AutoModelForMaskedLM.from_pretrained("NumidiaNLP/MagharibiBERT", device_map="auto") - Notebooks
- Google Colab
- Kaggle
File size: 4,434 Bytes
a5002e6 225d221 a5002e6 225d221 a5002e6 225d221 a5002e6 225d221 a5002e6 225d221 a5002e6 225d221 a5002e6 225d221 a5002e6 225d221 a5002e6 225d221 a5002e6 225d221 a5002e6 225d221 a5002e6 225d221 a5002e6 225d221 a5002e6 225d221 a5002e6 225d221 a5002e6 225d221 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 | ---
language:
- ar
library_name: transformers
pipeline_tag: fill-mask
base_model:
- UBC-NLP/MARBERT
tags:
- arabic
- maghrebi-arabic
- darija
- arabizi
- code-switching
- algeria
- morocco
- tunisia
- libya
- bert
- pytorch
- masked-language-modeling
---
<img src="https://i.imgur.com/cwgkvqe.png"
alt="MagharibiBERT" width="35%" align="right"/>
# MagharibiBERT
**MagharibiBERT** is a regionally adapted Transformer language model
for **Maghrebi Arabic**.
It is initialized from `UBC-NLP/MARBERT` and further adapted using
Masked Language Modeling (MLM) on a large multi-source corpus of
Maghrebi text.
The model targets the linguistic and orthographic diversity of
North African online communication, including Arabic-script dialect,
Arabizi, spelling variation, and Arabic-French/English code-switching.
MagharibiBERT is developed by **NumidiaNLP**.
---
## Model architecture
| Property | Value |
|---|---:|
| Architecture | BERT |
| Parent model | `UBC-NLP/MARBERT` |
| Objective | Masked Language Modeling |
| Parameters | 162,942,880 |
| Transformer layers | 12 |
| Hidden size | 768 |
| Attention heads | 12 |
| Vocabulary size | 100,000 |
| Maximum position embeddings | 512 |
---
## Regional continued pretraining
MagharibiBERT underwent additional regional continued pretraining on
a curated mixture of **17 corpora** covering Maghrebi Arabic and
North African social-media language.
The training mixture includes material associated with Algeria, Tunisia,
Morocco, Libya, and cross-regional Maghrebi sources, with explicit
coverage of Arabic script, Arabizi, and code-mixed text.
### Training configuration
- MLM sequence length: 128
- Optimizer steps: 120,000
- Effective batch size: 48
- Learning rate: 2e-5
- Warmup steps: 6,000
- Weight decay: 0.01
- Precision: BF16
- Random seed: 42
---
## How to use
### Fill-mask pipeline
```python
from transformers import pipeline
pipe = pipeline(
"fill-mask",
model="NumidiaNLP/MagharibiBERT"
)
results = pipe("واش راك [MASK]", top_k=5)
for result in results:
print(result["token_str"], result["score"])
```
### Example output
Output produced by the released MagharibiBERT checkpoint:
```text
{"token": "دير", "score": 0.277943}
{"token": "تهدر", "score": 0.071477}
{"token": "تدير", "score": 0.062739}
{"token": "تقول", "score": 0.047855}
{"token": "تحكي", "score": 0.038360}
```
> Scores depend on the complete masked context. The example above is
> provided only to demonstrate model usage rather than as an evaluation result.
### Load the model directly
```python
from transformers import AutoTokenizer, AutoModelForMaskedLM
model_name = "NumidiaNLP/MagharibiBERT"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForMaskedLM.from_pretrained(model_name)
```
---
## Intended use
MagharibiBERT is intended primarily for research involving Maghrebi Arabic,
including:
- hate and offensive language detection,
- sentiment analysis,
- dialect identification,
- Arabizi processing,
- code-switched text processing,
- social-media text classification,
- representation learning for Maghrebi Arabic.
---
## Intrinsic evaluation
On the fixed held-out MLM test set used during development, the released
checkpoint obtained:
| Metric | MagharibiBERT |
|---|---:|
| MLM loss | 2.8099 |
| Perplexity | 16.6080 |
| Masked-token accuracy | 52.42% |
Downstream evaluation against MARBERT and other Arabic language models
is being conducted separately.
---
## Limitations
Maghrebi Arabic is highly heterogeneous across countries, regions,
writing systems, platforms, and communities. Performance may therefore
vary across domains and linguistic varieties.
The model should not be interpreted as representing all North African
languages or all Maghrebi speakers equally.
---
## Citation
The citation for the accompanying MagharibiBERT paper will be added
following publication.
MagharibiBERT is initialized from MARBERT. Users should also cite the
original MARBERT work:
> Abdul-Mageed, M., Elmadany, A., and Nagoudi, E. M. B. (2021).
> ARBERT & MARBERT: Deep Bidirectional Transformers for Arabic.
> ACL-IJCNLP 2021.
---
## Organization
**NumidiaNLP — Language Intelligence for North Africa**
|