Update card for v12 (evaluation, limitations, windowed inference)
Browse files
README.md
CHANGED
|
@@ -1,290 +1,58 @@
|
|
| 1 |
---
|
| 2 |
-
language:
|
| 3 |
-
|
| 4 |
-
license: mit
|
| 5 |
-
tags:
|
| 6 |
-
- arabic
|
| 7 |
-
- punctuation-restoration
|
| 8 |
-
- token-classification
|
| 9 |
-
- xlm-roberta
|
| 10 |
-
- natural-language-processing
|
| 11 |
pipeline_tag: token-classification
|
| 12 |
-
|
| 13 |
-
model-index:
|
| 14 |
-
- name: Naqta
|
| 15 |
-
results:
|
| 16 |
-
- task:
|
| 17 |
-
type: token-classification
|
| 18 |
-
name: Arabic Punctuation Restoration
|
| 19 |
-
dataset:
|
| 20 |
-
name: Mixed Arabic punctuation restoration corpus
|
| 21 |
-
type: custom
|
| 22 |
-
metrics:
|
| 23 |
-
- type: f1
|
| 24 |
-
value: 0.8960
|
| 25 |
-
name: Validation Macro F1
|
| 26 |
-
- type: accuracy
|
| 27 |
-
value: 0.9714
|
| 28 |
-
name: Validation Accuracy
|
| 29 |
---
|
| 30 |
|
| 31 |
-
|
| 32 |
|
| 33 |
-
|
| 34 |
|
| 35 |
-
|
|
|
|
|
|
|
|
|
|
| 36 |
|
| 37 |
-
|
| 38 |
-
[](https://huggingface.co/MostafaMaroof/Naqta)
|
| 39 |
-
[](https://huggingface.co/MostafaMaroof/Naqta)
|
| 40 |
-
[](https://opensource.org/licenses/MIT)
|
| 41 |
-
[](https://huggingface.co/MostafaMaroof/Naqta)
|
| 42 |
-
|
| 43 |
-
</div>
|
| 44 |
-
|
| 45 |
-
---
|
| 46 |
-
|
| 47 |
-
**Naqta** (Arabic: ููุทุฉ, "dot/period") is a high-performance Arabic punctuation restoration model. Given plain unpunctuated Arabic text, it predicts the correct punctuation mark after each word using token-level sequence classification on top of **XLM-RoBERTa Large**.
|
| 48 |
-
|
| 49 |
-
> ๐ก **Try it live** on the [Hugging Face Space](https://huggingface.co/spaces/MostafaMaroof/Naqta)
|
| 50 |
-
|
| 51 |
-
---
|
| 52 |
-
|
| 53 |
-
## โจ What Does It Restore?
|
| 54 |
-
|
| 55 |
-
| Symbol | Name | Example |
|
| 56 |
-
|:---:|---|---|
|
| 57 |
-
| `.` | Period | ููุงูุฉ ุงูุฌู
ูุฉ |
|
| 58 |
-
| `ุ` | Arabic comma | ูุงุตูุฉ ุนุฑุจูุฉ |
|
| 59 |
-
| `ุ` | Arabic question mark | ุนูุงู
ุฉ ุงุณุชููุงู
|
|
| 60 |
-
| `!` | Exclamation mark | ุนูุงู
ุฉ ุชุนุฌุจ |
|
| 61 |
-
| `:` | Colon | ููุทุชุงู |
|
| 62 |
-
| `ุ` | Arabic semicolon | ูุงุตูุฉ ู
ูููุทุฉ |
|
| 63 |
-
| `-` | Dash | ุดุฑุทุฉ |
|
| 64 |
-
|
| 65 |
-
---
|
| 66 |
-
|
| 67 |
-
## ๐ Results
|
| 68 |
-
|
| 69 |
-
### Validation Metrics (v11d โ Final)
|
| 70 |
-
|
| 71 |
-
| Metric | Score |
|
| 72 |
-
|---|---:|
|
| 73 |
-
| ๐ฏ **Macro F1** | **0.8960** |
|
| 74 |
-
| โ
Accuracy | 0.9714 |
|
| 75 |
-
|
| 76 |
-
### Per-Class F1 Score
|
| 77 |
-
|
| 78 |
-
| Class | Symbol | F1 | Performance |
|
| 79 |
-
|---|:---:|---:|---|
|
| 80 |
-
| Exclamation | `!` | 0.8897 | ๐ข Excellent |
|
| 81 |
-
| Arabic semicolon | `ุ` | 0.8042 | ๐ข Excellent |
|
| 82 |
-
| Question mark | `ุ` | 0.9665 | ๐ข Excellent |
|
| 83 |
-
| Dash | `-` | 0.9007 | ๐ข Excellent |
|
| 84 |
-
| Arabic comma | `ุ` | 0.8100 | ๐ข Excellent |
|
| 85 |
-
| Period | `.` | 0.8968 | ๐ข Excellent |
|
| 86 |
-
|
| 87 |
-
---
|
| 88 |
-
|
| 89 |
-
## ๐๏ธ Training Data
|
| 90 |
-
|
| 91 |
-
The model was trained on a large multi-source Arabic corpus totaling over **1.4 million paragraphs** from six diverse sources, covering a broad range of Arabic writing styles and domains.
|
| 92 |
-
|
| 93 |
-
### Corpus Sources
|
| 94 |
-
|
| 95 |
-
| Source | Rows | Domain |
|
| 96 |
-
|---|---:|---|
|
| 97 |
-
| **ABC / UNPC** | ~1,020,000 | News & formal Arabic (United Nations Parallel Corpus) |
|
| 98 |
-
| **HF Tashkeel** | ~151,000 | Vocalized Arabic text (diacritized corpus) |
|
| 99 |
-
| **Hindawi E-Books** | ~100,000 | Literary Arabic prose (novels & non-fiction) |
|
| 100 |
-
| **Wikipedia (AR)** | ~98,500 | Encyclopedia articles |
|
| 101 |
-
| **CBT** | ~69,000 | Classical Arabic books & religious texts |
|
| 102 |
-
| **ARCD + XQuAD** | ~2,050 | Arabic QA pairs (rich in question marks `ุ`) |
|
| 103 |
-
| **Total (raw)** | **~1,441,000** | โ |
|
| 104 |
-
|
| 105 |
-
> All paragraphs were filtered to contain at least one Arabic letter and one target punctuation mark. Non-target punctuation (e.g., `ยซยป`, `โฆ`, parentheses) was removed before training.
|
| 106 |
-
|
| 107 |
-
### Punctuation Coverage (raw corpus)
|
| 108 |
-
|
| 109 |
-
| Mark | Name | Paragraphs | Coverage |
|
| 110 |
-
|:---:|---|---:|---:|
|
| 111 |
-
| `ุ` | Arabic comma | 922,721 | 64.0% |
|
| 112 |
-
| `:` | Colon | 230,150 | 16.0% |
|
| 113 |
-
| `ุ` | Arabic semicolon | 128,744 | 8.9% |
|
| 114 |
-
| `ุ` | Question mark | 50,282 | 3.5% |
|
| 115 |
-
| `!` | Exclamation | 15,976 | 1.1% |
|
| 116 |
-
| `-` | Dash | ~1 | <0.1% |
|
| 117 |
-
|
| 118 |
-
### Data Balance Strategy
|
| 119 |
-
|
| 120 |
-
To prevent the model from ignoring rare punctuation marks, a targeted oversampling strategy was applied:
|
| 121 |
-
|
| 122 |
-
| Strategy | Marks | Multiplier | Cap |
|
| 123 |
-
|---|:---:|:---:|---:|
|
| 124 |
-
| Strong oversampling | `ุ` `!` | ร8 | 80,000 rows |
|
| 125 |
-
| Light oversampling | `ุ` `-` | ร6 | 80,000 rows |
|
| 126 |
-
|
| 127 |
-
After oversampling, the combined training pool grew to **~2.4 million paragraphs**.
|
| 128 |
-
|
| 129 |
-
### Dataset Splits
|
| 130 |
-
|
| 131 |
-
| Split | Sequences | Share |
|
| 132 |
-
|---|---:|---:|
|
| 133 |
-
| Train (capped) | 1,000,000 | 85% |
|
| 134 |
-
| Validation | 40,000 | 10% |
|
| 135 |
-
| Test | โ | 5% |
|
| 136 |
-
|
| 137 |
-
- **Sliding-window context** (window=3 sentences, stride=2) was applied to training data only
|
| 138 |
-
- Validation and test sets remain un-windowed for clean, unbiased evaluation
|
| 139 |
-
- Splits were stratified by the rarest punctuation mark in each sequence
|
| 140 |
-
|
| 141 |
-
### Preprocessing
|
| 142 |
-
|
| 143 |
-
- Arabic normalization: alef variants โ `ุง`, ya variants โ `ู`, diacritics stripped
|
| 144 |
-
- Label assigned per word = punctuation mark **following** that word
|
| 145 |
-
- Multi-subword words: only the first subword receives the label; others are masked (`-100`)
|
| 146 |
-
|
| 147 |
-
---
|
| 148 |
-
|
| 149 |
-
## โ๏ธ Model Architecture & Training
|
| 150 |
-
|
| 151 |
-
| Setting | Value |
|
| 152 |
-
|---|---|
|
| 153 |
-
| Base model | `xlm-roberta-large` (~560M params) |
|
| 154 |
-
| Task | Token classification (8 labels) |
|
| 155 |
-
| Max sequence length | 384 tokens |
|
| 156 |
-
| Training examples | 1,000,000 (capped) |
|
| 157 |
-
| Validation examples | 40,000 |
|
| 158 |
-
|
| 159 |
-
### Two-Phase Training
|
| 160 |
-
|
| 161 |
-
| Phase | Epochs | LR | Loss | Notes |
|
| 162 |
-
|---|:---:|---|---|---|
|
| 163 |
-
| Phase 1 | 2 | 2e-5 | Cross-entropy + label smoothing | Full model fine-tuning |
|
| 164 |
-
| Phase 2 | 1 | 6e-6 | Focal loss (ฮณ=2.0) + class weights | Bottom 12 layers frozen |
|
| 165 |
-
|
| 166 |
-
### Class Weights
|
| 167 |
-
|
| 168 |
-
Rare class weights were additionally boosted:
|
| 169 |
-
|
| 170 |
-
| Class | Boost |
|
| 171 |
-
|:---:|---|
|
| 172 |
-
| `ุ` | ร1.2 |
|
| 173 |
-
| `!` | ร3.0 |
|
| 174 |
-
| `ุ` | ร2.0 |
|
| 175 |
-
| `-` | ร1.3 |
|
| 176 |
-
|
| 177 |
-
---
|
| 178 |
-
|
| 179 |
-
## ๐ Quick Start
|
| 180 |
|
| 181 |
```python
|
| 182 |
-
from transformers import
|
| 183 |
-
import torch
|
| 184 |
-
|
| 185 |
-
repo_id = "MostafaMaroof/Naqta"
|
| 186 |
-
|
| 187 |
-
tokenizer = AutoTokenizer.from_pretrained(repo_id)
|
| 188 |
-
model = AutoModelForTokenClassification.from_pretrained(repo_id)
|
| 189 |
-
model.eval()
|
| 190 |
-
|
| 191 |
-
id2label = model.config.id2label
|
| 192 |
|
| 193 |
-
|
| 194 |
-
|
| 195 |
|
| 196 |
-
|
| 197 |
-
|
| 198 |
-
|
| 199 |
-
return_tensors="pt",
|
| 200 |
-
truncation=True,
|
| 201 |
-
max_length=384,
|
| 202 |
-
)
|
| 203 |
-
|
| 204 |
-
with torch.no_grad():
|
| 205 |
-
logits = model(**inputs).logits
|
| 206 |
-
|
| 207 |
-
pred_ids = logits.argmax(dim=-1)[0].tolist()
|
| 208 |
-
word_ids = inputs.word_ids(batch_index=0)
|
| 209 |
-
|
| 210 |
-
restored_words = []
|
| 211 |
-
previous_word_id = None
|
| 212 |
-
for token_id, word_id in zip(pred_ids, word_ids):
|
| 213 |
-
if word_id is None or word_id == previous_word_id:
|
| 214 |
-
continue
|
| 215 |
-
word = words[word_id]
|
| 216 |
-
label = id2label[token_id]
|
| 217 |
-
if label != "O":
|
| 218 |
-
word = word + label
|
| 219 |
-
restored_words.append(word)
|
| 220 |
-
previous_word_id = word_id
|
| 221 |
-
|
| 222 |
-
restored_text = " ".join(restored_words)
|
| 223 |
-
print(restored_text)
|
| 224 |
-
# โ ุจูุบุช ูุณุจุฉ ุงููู
ู ุงูุงูุชุตุงุฏู 4.7 ุจุงูู
ุฆุฉ ุฎูุงู ุงูุฑุจุน ุงูุซุงูุซ ู
ู ุนุงู
2024ุ ููู ุงุนูู ู
ุณุชูู ู
ูุฐ ุฎู
ุณ ุณููุงุช.
|
| 225 |
```
|
| 226 |
|
| 227 |
-
--
|
|
|
|
|
|
|
| 228 |
|
| 229 |
-
##
|
| 230 |
|
| 231 |
-
|
| 232 |
-
|
| 233 |
-
ุงุฐุง ุงุฑุฏุช ุงู ุชูุฌุญ ูู ุญูุงุชู ูุนููู ุงู ุชุญุฏุฏ ุงูุฏุงูู ูุงุถุญุฉ ูุงู ุชุนู
ู ุจุฌุฏ ูุงุณุชู
ุฑุงุฑูุฉ ููุง ุชูุฃุณ ุนูุฏ ุงูู ุนูุจุฉ ุชูุงุฌููุง
|
| 234 |
-
```
|
| 235 |
|
| 236 |
-
|
| 237 |
-
|
| 238 |
-
|
| 239 |
-
|
|
|
|
| 240 |
|
| 241 |
-
|
| 242 |
-
```
|
| 243 |
-
ู
ู ุงุฎุชุฑุน ุงููุงุชู ููู ุงู ุณูุฉ ุชู
ุฐูู ูู
ุง ูู ุงูู
ูุฉ ูุฐุง ุงูุงุฎุชุฑุงุน
|
| 244 |
-
```
|
| 245 |
-
```
|
| 246 |
-
ู
ู ุงุฎุชุฑุน ุงููุงุชูุ ููู ุงู ุณูุฉ ุชู
ุฐููุ ูู
ุง ูู ุงูู
ูุฉ ูุฐุง ุงูุงุฎุชุฑุงุนุ
|
| 247 |
-
```
|
| 248 |
-
|
| 249 |
-
---
|
| 250 |
-
|
| 251 |
-
## ๐ฏ Intended Use
|
| 252 |
-
|
| 253 |
-
Naqta is well-suited for:
|
| 254 |
-
|
| 255 |
-
- ๐๏ธ **ASR post-processing** โ restoring punctuation in Arabic speech transcripts
|
| 256 |
-
- ๐ **Readability enhancement** โ making raw Arabic text easier to read
|
| 257 |
-
- ๐ง **NLP preprocessing** โ improving text quality for downstream Arabic NLP tasks
|
| 258 |
-
- ๐ฌ **Research** โ Arabic punctuation restoration benchmark evaluation
|
| 259 |
-
|
| 260 |
-
---
|
| 261 |
|
| 262 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 263 |
|
| 264 |
-
|
| 265 |
-
- Performance may degrade on highly dialectal, technical, or domain-specific text.
|
| 266 |
-
- The model does not predict quotation marks or dialogue markers (`ยซยป`).
|
| 267 |
-
- Very short or fragmented text (< 5 words) may produce less reliable results.
|
| 268 |
-
- The model predicts punctuation position only and does not perform grammar correction.
|
| 269 |
|
| 270 |
-
---
|
| 271 |
-
|
| 272 |
-
|
| 273 |
-
|
| 274 |
-
This model is released under the **MIT License**.
|
| 275 |
-
|
| 276 |
-
---
|
| 277 |
-
|
| 278 |
-
## ๐ Citation
|
| 279 |
-
|
| 280 |
-
If you use Naqta in your work, please reference:
|
| 281 |
-
|
| 282 |
-
```bibtex
|
| 283 |
-
@misc{naqta2025,
|
| 284 |
-
title = {Naqta: Arabic Punctuation Restoration with XLM-RoBERTa},
|
| 285 |
-
author = {MostafaMaroof},
|
| 286 |
-
year = {2025},
|
| 287 |
-
publisher = {Hugging Face},
|
| 288 |
-
url = {https://huggingface.co/MostafaMaroof/Naqta}
|
| 289 |
-
}
|
| 290 |
-
```
|
|
|
|
| 1 |
---
|
| 2 |
+
language: ar
|
| 3 |
+
license: apache-2.0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
pipeline_tag: token-classification
|
| 5 |
+
tags: [arabic, punctuation-restoration, xlm-roberta, token-classification]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
---
|
| 7 |
|
| 8 |
+
# Naqta - Arabic Punctuation Restoration
|
| 9 |
|
| 10 |
+
Restores punctuation in Modern Standard Arabic. Two components in one repo:
|
| 11 |
|
| 12 |
+
| component | path | task |
|
| 13 |
+
|---|---|---|
|
| 14 |
+
| point-mark model | repo root | 8 classes (XLM-RoBERTa-large) |
|
| 15 |
+
| span tagger | `span-tagger/` | paired interjection dashes (BIO, XLM-RoBERTa-base) |
|
| 16 |
|
| 17 |
+
## Usage
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
|
| 19 |
```python
|
| 20 |
+
from transformers import AutoModelForTokenClassification, AutoTokenizer
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
|
| 22 |
+
tok = AutoTokenizer.from_pretrained("MostafaMaroof/Naqta")
|
| 23 |
+
model = AutoModelForTokenClassification.from_pretrained("MostafaMaroof/Naqta")
|
| 24 |
|
| 25 |
+
span_tok = AutoTokenizer.from_pretrained("MostafaMaroof/Naqta", subfolder="span-tagger")
|
| 26 |
+
span_model = AutoModelForTokenClassification.from_pretrained(
|
| 27 |
+
"MostafaMaroof/Naqta", subfolder="span-tagger")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
```
|
| 29 |
|
| 30 |
+
**Use sliding-window inference for long text.** The model was fine-tuned on short
|
| 31 |
+
windows; a single truncated pass leaves everything past roughly 230 words
|
| 32 |
+
unpunctuated. See `app.py` in the Space for a reference implementation.
|
| 33 |
|
| 34 |
+
## Evaluation
|
| 35 |
|
| 36 |
+
Held-out set of 91 Modern Standard Arabic passages annotated to a published
|
| 37 |
+
punctuation guideline (about 27k tokens):
|
|
|
|
|
|
|
| 38 |
|
| 39 |
+
| metric | previous | current |
|
| 40 |
+
|---|---|---|
|
| 41 |
+
| Macro F1 | 54.64 | **61.60** |
|
| 42 |
+
| Weighted F1 | 89.90 | **91.54** |
|
| 43 |
+
| Token accuracy | 90.96 | **91.33** |
|
| 44 |
|
| 45 |
+
## Limitations
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
|
| 47 |
+
- Exclamation and semicolon are over-predicted (precision 20.4 and 36.2): the
|
| 48 |
+
model finds these marks but does not withhold them reliably.
|
| 49 |
+
- Brackets and quotation marks are not produced. The span tagger covers them in
|
| 50 |
+
training but their precision is too low to enable in production.
|
| 51 |
+
- Punctuation conventions vary across Arabic sources; performance is highest on
|
| 52 |
+
text punctuated to a consistent editorial guideline.
|
| 53 |
|
| 54 |
+
## Training
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
|
| 56 |
+
XLM-RoBERTa-large fine-tuned on about 1.3M paragraphs (classical and modern
|
| 57 |
+
books, Wikipedia, news, QA corpora) with weighted focal loss, oversampling of
|
| 58 |
+
rare marks, and a final adaptation stage on guideline-conforming data.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|