MostafaMaroof commited on
Commit
1b5f3aa
·
verified ·
1 Parent(s): 246cf28

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +192 -3
README.md CHANGED
@@ -1,3 +1,192 @@
1
- ---
2
- license: mit
3
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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.8176
25
+ name: Validation Macro F1
26
+ - type: accuracy
27
+ value: 0.9589
28
+ name: Validation Accuracy
29
+ ---
30
+
31
+ # Naqta
32
+
33
+ **Naqta** is an Arabic punctuation restoration model. It predicts missing punctuation marks in unpunctuated Arabic text using token-level sequence classification.
34
+
35
+ The model is designed to restore the following punctuation marks:
36
+
37
+ | Label | Meaning |
38
+ |---|---|
39
+ | `O` | No punctuation |
40
+ | `.` | Period |
41
+ | `،` | Arabic comma |
42
+ | `؟` | Arabic question mark |
43
+ | `!` | Exclamation mark |
44
+ | `:` | Colon |
45
+ | `؛` | Arabic semicolon |
46
+ | `-` | Dash |
47
+
48
+ ## Model Details
49
+
50
+ - **Model name:** Naqta
51
+ - **Task:** Arabic punctuation restoration
52
+ - **Architecture:** XLM-RoBERTa Large for token classification
53
+ - **Base model:** `xlm-roberta-large`
54
+ - **Maximum sequence length:** 384 tokens
55
+ - **Training objective:** token-level punctuation classification
56
+ - **Loss:** weighted focal loss during fine-tuning
57
+ - **Focal gamma:** 2.0
58
+
59
+ ## Training Summary
60
+
61
+ Naqta was trained on a mixed Arabic corpus built from multiple sources, including books, Arabic corpora, Wikipedia-style text, and question-answering data. The training pipeline used sliding-window context, class balancing, rare punctuation oversampling, and a two-phase training strategy.
62
+
63
+ ### Training Strategy
64
+
65
+ | Phase | Description |
66
+ |---|---|
67
+ | Phase 1 | General token-classification training for 2 epochs |
68
+ | Phase 2 | Focal-loss fine-tuning for 2 epochs with lower encoder layers frozen |
69
+
70
+ ### Data Balancing
71
+
72
+ The final training setup used stronger sampling for rare punctuation marks:
73
+
74
+ - Strong rare marks: `؟`, `!`
75
+ - Light rare marks: `؛`, `-`
76
+ - Sliding-window context was applied to training data only
77
+ - Validation and test data remained unwindowed to avoid leakage
78
+
79
+ ## Validation Results
80
+
81
+ Final best validation result:
82
+
83
+ | Metric | Score |
84
+ |---|---:|
85
+ | **Macro F1** | **0.8176** |
86
+ | Accuracy | 0.9589 |
87
+
88
+ ### Per-Class Validation F1
89
+
90
+ | Class | F1 |
91
+ |---|---:|
92
+ | `!` | 0.6512 |
93
+ | `؛` | 0.7180 |
94
+ | `؟` | 0.9066 |
95
+ | `-` | 0.8562 |
96
+ | `،` | 0.7422 |
97
+ | `.` | 0.8030 |
98
+
99
+ ## Example
100
+
101
+ Input:
102
+
103
+ ```text
104
+ اذا اردت ان تنجح في حياتك فعليك ان تفتح اهدافك واضحة وان تعمل بجد واستمرارية ولا تيأس عند اول عقبة تواجهها
105
+ ```
106
+
107
+ Possible output:
108
+
109
+ ```text
110
+ اذا اردت ان تنجح في حياتك، فعليك ان تفتح اهدافك واضحة، وان تعمل بجد واستمرارية، ولا تيأس عند اول عقبة تواجهها.
111
+ ```
112
+
113
+ ## Usage
114
+
115
+ ```python
116
+ from transformers import AutoTokenizer, AutoModelForTokenClassification
117
+ import torch
118
+
119
+ repo_id = "MostafaMaroof/Naqta"
120
+
121
+ tokenizer = AutoTokenizer.from_pretrained(repo_id)
122
+ model = AutoModelForTokenClassification.from_pretrained(repo_id)
123
+ model.eval()
124
+
125
+ id2label = model.config.id2label
126
+
127
+ text = "بلغت نسبة النمو الاقتصادي 4.7 بالمئة خلال الربع الثالث من عام 2024 وهو اعلى مستوى منذ خمس سنوات"
128
+ words = text.split()
129
+
130
+ inputs = tokenizer(
131
+ words,
132
+ is_split_into_words=True,
133
+ return_tensors="pt",
134
+ truncation=True,
135
+ max_length=384,
136
+ )
137
+
138
+ with torch.no_grad():
139
+ logits = model(**inputs).logits
140
+
141
+ pred_ids = logits.argmax(dim=-1)[0].tolist()
142
+ word_ids = inputs.word_ids(batch_index=0)
143
+
144
+ restored_words = []
145
+ previous_word_id = None
146
+ for token_id, word_id in zip(pred_ids, word_ids):
147
+ if word_id is None or word_id == previous_word_id:
148
+ continue
149
+
150
+ word = words[word_id]
151
+ label = id2label[token_id]
152
+ if label != "O":
153
+ word = word + label
154
+ restored_words.append(word)
155
+ previous_word_id = word_id
156
+
157
+ restored_text = " ".join(restored_words)
158
+ print(restored_text)
159
+ ```
160
+
161
+ ## Intended Use
162
+
163
+ Naqta can be used for:
164
+
165
+ - Restoring punctuation in Arabic ASR transcripts
166
+ - Improving readability of unpunctuated Arabic text
167
+ - Preprocessing Arabic text for downstream NLP tasks
168
+ - Educational or research applications involving Arabic punctuation
169
+
170
+ ## Limitations
171
+
172
+ - Punctuation restoration is partly stylistic, so multiple outputs may be valid.
173
+ - The model may over-insert commas in long literary or formal sentences.
174
+ - Very short or fragmented text may produce less reliable punctuation.
175
+ - Domain-specific text, such as legal, medical, or highly dialectal content, may require additional fine-tuning.
176
+ - The model predicts punctuation after words and does not perform full grammar correction.
177
+
178
+ ## Training Notes
179
+
180
+ The model was optimized to improve rare punctuation classes, especially `!`, `؟`, `؛`, and `-`. The final configuration achieved a validation Macro F1 above 0.81, with especially strong performance on question marks and dashes.
181
+
182
+ ## License
183
+
184
+ This model is released under the MIT License.
185
+
186
+ ## Citation
187
+
188
+ If you use this model, please cite or reference the Hugging Face repository:
189
+
190
+ ```text
191
+ MostafaMaroof/Naqta
192
+ ```