MostafaMaroof commited on
Commit
c5322f3
ยท
verified ยท
1 Parent(s): 373c17b

Update card for v12 (evaluation, limitations, windowed inference)

Browse files
Files changed (1) hide show
  1. README.md +38 -270
README.md CHANGED
@@ -1,290 +1,58 @@
1
  ---
2
- language:
3
- - ar
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
- base_model: xlm-roberta-large
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
- <div align="center">
32
 
33
- # ๐Ÿ”ค Naqta โ€” ู†ู‚ุทุฉ
34
 
35
- ### Arabic Punctuation Restoration
 
 
 
36
 
37
- [![Model](https://img.shields.io/badge/๐Ÿค—%20Model-MostafaMaroof%2FNaqta-blue)](https://huggingface.co/MostafaMaroof/Naqta)
38
- [![Language](https://img.shields.io/badge/Language-Arabic-green)](https://huggingface.co/MostafaMaroof/Naqta)
39
- [![Task](https://img.shields.io/badge/Task-Token%20Classification-orange)](https://huggingface.co/MostafaMaroof/Naqta)
40
- [![License](https://img.shields.io/badge/License-MIT-yellow)](https://opensource.org/licenses/MIT)
41
- [![Macro F1](https://img.shields.io/badge/Macro%20F1-89.6%25-brightgreen)](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 AutoTokenizer, AutoModelForTokenClassification
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
- text = "ุจู„ุบุช ู†ุณุจุฉ ุงู„ู†ู…ูˆ ุงู„ุงู‚ุชุตุงุฏูŠ 4.7 ุจุงู„ู…ุฆุฉ ุฎู„ุงู„ ุงู„ุฑุจุน ุงู„ุซุงู„ุซ ู…ู† ุนุงู… 2024 ูˆู‡ูˆ ุงุนู„ู‰ ู…ุณุชูˆู‰ ู…ู†ุฐ ุฎู…ุณ ุณู†ูˆุงุช"
194
- words = text.split()
195
 
196
- inputs = tokenizer(
197
- words,
198
- is_split_into_words=True,
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
- ## ๐Ÿ“– Example
230
 
231
- **Input** (unpunctuated):
232
- ```
233
- ุงุฐุง ุงุฑุฏุช ุงู† ุชู†ุฌุญ ููŠ ุญูŠุงุชูƒ ูุนู„ูŠูƒ ุงู† ุชุญุฏุฏ ุงู‡ุฏุงููƒ ูˆุงุถุญุฉ ูˆุงู† ุชุนู…ู„ ุจุฌุฏ ูˆุงุณุชู…ุฑุงุฑูŠุฉ ูˆู„ุง ุชูŠุฃุณ ุนู†ุฏ ุงูˆู„ ุนู‚ุจุฉ ุชูˆุงุฌู‡ู‡ุง
234
- ```
235
 
236
- **Output** (restored):
237
- ```
238
- ุงุฐุง ุงุฑุฏุช ุงู† ุชู†ุฌุญ ููŠ ุญูŠุงุชูƒุŒ ูุนู„ูŠูƒ ุงู† ุชุญุฏุฏ ุงู‡ุฏุงููƒ ูˆุงุถุญุฉุŒ ูˆุงู† ุชุนู…ู„ ุจุฌุฏ ูˆุงุณุชู…ุฑุงุฑูŠุฉุŒ ูˆู„ุง ุชูŠุฃุณ ุนู†ุฏ ุงูˆู„ ุนู‚ุจุฉ ุชูˆุงุฌู‡ู‡ุง.
239
- ```
 
240
 
241
- **Question example:**
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
- ## โš ๏ธ Limitations
 
 
 
 
 
263
 
264
- - Punctuation restoration is partly stylistic โ€” multiple valid outputs may exist for a single input.
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
- ## ๐Ÿ“œ License
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.