arapreplab 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- arapreplab-0.1.0/LICENSE +21 -0
- arapreplab-0.1.0/PKG-INFO +271 -0
- arapreplab-0.1.0/README.md +220 -0
- arapreplab-0.1.0/pyproject.toml +71 -0
- arapreplab-0.1.0/setup.cfg +4 -0
- arapreplab-0.1.0/src/arapreplab/__init__.py +2 -0
- arapreplab-0.1.0/src/arapreplab/__main__.py +13 -0
- arapreplab-0.1.0/src/arapreplab/core/__init__.py +21 -0
- arapreplab-0.1.0/src/arapreplab/core/audit.py +120 -0
- arapreplab-0.1.0/src/arapreplab/core/auto.py +171 -0
- arapreplab-0.1.0/src/arapreplab/core/dialect.py +92 -0
- arapreplab-0.1.0/src/arapreplab/core/experiment.py +364 -0
- arapreplab-0.1.0/src/arapreplab/core/final_model.py +113 -0
- arapreplab-0.1.0/src/arapreplab/core/labels.py +53 -0
- arapreplab-0.1.0/src/arapreplab/core/models.py +67 -0
- arapreplab-0.1.0/src/arapreplab/core/negation.py +51 -0
- arapreplab-0.1.0/src/arapreplab/core/normalize.py +145 -0
- arapreplab-0.1.0/src/arapreplab/core/pipeline.py +110 -0
- arapreplab-0.1.0/src/arapreplab/core/seed.py +18 -0
- arapreplab-0.1.0/src/arapreplab/core/stats.py +66 -0
- arapreplab-0.1.0/src/arapreplab/core/stemming.py +83 -0
- arapreplab-0.1.0/src/arapreplab/core/stopwords.py +34 -0
- arapreplab-0.1.0/src/arapreplab/core/topics.py +72 -0
- arapreplab-0.1.0/src/arapreplab/core/transformer.py +258 -0
- arapreplab-0.1.0/src/arapreplab/data/__init__.py +1 -0
- arapreplab-0.1.0/src/arapreplab/data/sample_reviews.csv +601 -0
- arapreplab-0.1.0/src/arapreplab/gui/__init__.py +1 -0
- arapreplab-0.1.0/src/arapreplab/gui/app.py +270 -0
- arapreplab-0.1.0/src/arapreplab/gui/auto_window.py +183 -0
- arapreplab-0.1.0/src/arapreplab/gui/help_text.py +82 -0
- arapreplab-0.1.0/src/arapreplab/gui/rtl.py +54 -0
- arapreplab-0.1.0/src/arapreplab/gui/state.py +80 -0
- arapreplab-0.1.0/src/arapreplab/gui/tabs/__init__.py +1 -0
- arapreplab-0.1.0/src/arapreplab/gui/tabs/cleaning_tab.py +125 -0
- arapreplab-0.1.0/src/arapreplab/gui/tabs/data_tab.py +164 -0
- arapreplab-0.1.0/src/arapreplab/gui/tabs/experiment_tab.py +259 -0
- arapreplab-0.1.0/src/arapreplab/gui/tabs/export_tab.py +274 -0
- arapreplab-0.1.0/src/arapreplab/gui/tabs/results_tab.py +155 -0
- arapreplab-0.1.0/src/arapreplab/gui/tabs/topics_tab.py +99 -0
- arapreplab-0.1.0/src/arapreplab/gui/tabs/transformer_tab.py +212 -0
- arapreplab-0.1.0/src/arapreplab/gui/widgets.py +123 -0
- arapreplab-0.1.0/src/arapreplab/gui/worker.py +71 -0
- arapreplab-0.1.0/src/arapreplab/io/__init__.py +10 -0
- arapreplab-0.1.0/src/arapreplab/io/action_log.py +249 -0
- arapreplab-0.1.0/src/arapreplab/io/console.py +17 -0
- arapreplab-0.1.0/src/arapreplab/io/loaders.py +97 -0
- arapreplab-0.1.0/src/arapreplab/io/reports.py +116 -0
- arapreplab-0.1.0/src/arapreplab/io/session.py +69 -0
- arapreplab-0.1.0/src/arapreplab.egg-info/PKG-INFO +271 -0
- arapreplab-0.1.0/src/arapreplab.egg-info/SOURCES.txt +65 -0
- arapreplab-0.1.0/src/arapreplab.egg-info/dependency_links.txt +1 -0
- arapreplab-0.1.0/src/arapreplab.egg-info/entry_points.txt +2 -0
- arapreplab-0.1.0/src/arapreplab.egg-info/requires.txt +31 -0
- arapreplab-0.1.0/src/arapreplab.egg-info/top_level.txt +1 -0
- arapreplab-0.1.0/tests/test_action_log.py +94 -0
- arapreplab-0.1.0/tests/test_audit_topics_model.py +80 -0
- arapreplab-0.1.0/tests/test_auto.py +76 -0
- arapreplab-0.1.0/tests/test_dialect_session.py +116 -0
- arapreplab-0.1.0/tests/test_effects_are_found.py +44 -0
- arapreplab-0.1.0/tests/test_experiment.py +97 -0
- arapreplab-0.1.0/tests/test_gui_helpers.py +29 -0
- arapreplab-0.1.0/tests/test_io.py +74 -0
- arapreplab-0.1.0/tests/test_normalize.py +66 -0
- arapreplab-0.1.0/tests/test_pipeline_stats.py +73 -0
- arapreplab-0.1.0/tests/test_stemming_stopwords.py +57 -0
- arapreplab-0.1.0/tests/test_transformer_check.py +55 -0
- arapreplab-0.1.0/tests/test_unseen_files.py +80 -0
arapreplab-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Fatima Zeidan and Leen El Sakka
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: arapreplab
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Offline, no-code workbench that shows which Arabic text preprocessing choices help on your data
|
|
5
|
+
Author: Fatima Zeidan, Leen El Sakka
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/fatima-zeidan/arapreplab
|
|
8
|
+
Project-URL: Issues, https://github.com/fatima-zeidan/arapreplab/issues
|
|
9
|
+
Keywords: Arabic NLP,text preprocessing,text classification,topic modeling,GUI,reproducibility
|
|
10
|
+
Classifier: Programming Language :: Python :: 3
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
15
|
+
Classifier: Operating System :: Microsoft :: Windows
|
|
16
|
+
Classifier: Operating System :: POSIX :: Linux
|
|
17
|
+
Classifier: Natural Language :: Arabic
|
|
18
|
+
Classifier: Intended Audience :: Science/Research
|
|
19
|
+
Classifier: Topic :: Text Processing :: Linguistic
|
|
20
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
21
|
+
Requires-Python: >=3.10
|
|
22
|
+
Description-Content-Type: text/markdown
|
|
23
|
+
License-File: LICENSE
|
|
24
|
+
Requires-Dist: numpy>=1.23
|
|
25
|
+
Requires-Dist: pandas>=1.5
|
|
26
|
+
Requires-Dist: scipy>=1.9
|
|
27
|
+
Requires-Dist: scikit-learn>=1.2
|
|
28
|
+
Requires-Dist: nltk>=3.8
|
|
29
|
+
Requires-Dist: joblib>=1.2
|
|
30
|
+
Requires-Dist: openpyxl>=3.1
|
|
31
|
+
Requires-Dist: matplotlib>=3.6
|
|
32
|
+
Requires-Dist: customtkinter>=5.2
|
|
33
|
+
Requires-Dist: arabic-reshaper>=3.0
|
|
34
|
+
Requires-Dist: python-bidi>=0.4
|
|
35
|
+
Provides-Extra: dev
|
|
36
|
+
Requires-Dist: pytest>=7; extra == "dev"
|
|
37
|
+
Requires-Dist: pytest-cov>=4; extra == "dev"
|
|
38
|
+
Requires-Dist: build; extra == "dev"
|
|
39
|
+
Requires-Dist: twine; extra == "dev"
|
|
40
|
+
Provides-Extra: notebook
|
|
41
|
+
Requires-Dist: notebook; extra == "notebook"
|
|
42
|
+
Requires-Dist: ipykernel; extra == "notebook"
|
|
43
|
+
Provides-Extra: camel
|
|
44
|
+
Requires-Dist: camel-tools; extra == "camel"
|
|
45
|
+
Provides-Extra: bert
|
|
46
|
+
Requires-Dist: torch>=2.1; extra == "bert"
|
|
47
|
+
Requires-Dist: transformers>=4.40; extra == "bert"
|
|
48
|
+
Provides-Extra: app
|
|
49
|
+
Requires-Dist: pyinstaller; extra == "app"
|
|
50
|
+
Dynamic: license-file
|
|
51
|
+
|
|
52
|
+
# AraPrepLab
|
|
53
|
+
|
|
54
|
+
[](https://doi.org/10.5281/zenodo.24765356)
|
|
55
|
+
|
|
56
|
+
AraPrepLab is a desktop tool for Arabic text classification that answers one practical question: which cleaning
|
|
57
|
+
steps actually improve results on my data?
|
|
58
|
+
|
|
59
|
+
Arabic text is written in many ways. The same word can appear with or without diacritics, with different alef or
|
|
60
|
+
hamza forms, with stretched letters, or in a dialect spelling. Studies disagree on which of these to normalize, and
|
|
61
|
+
whether to stem, because the answer changes from one dataset to another. AraPrepLab lets you load your own
|
|
62
|
+
spreadsheet, test the cleaning choices on it, and see which ones make a real difference. You don't need to write
|
|
63
|
+
any code, and nothing leaves your computer.
|
|
64
|
+
|
|
65
|
+

|
|
66
|
+
|
|
67
|
+
More screenshots: [data and audit](https://raw.githubusercontent.com/fatima-zeidan/arapreplab/main/docs/screenshots/data.png), [cleaning preview](https://raw.githubusercontent.com/fatima-zeidan/arapreplab/main/docs/screenshots/cleaning.png),
|
|
68
|
+
[model check](https://raw.githubusercontent.com/fatima-zeidan/arapreplab/main/docs/screenshots/check.png), [BERT check](https://raw.githubusercontent.com/fatima-zeidan/arapreplab/main/docs/screenshots/bert.png),
|
|
69
|
+
[Auto analysis](https://raw.githubusercontent.com/fatima-zeidan/arapreplab/main/docs/screenshots/auto.png),
|
|
70
|
+
[experiment running](https://raw.githubusercontent.com/fatima-zeidan/arapreplab/main/docs/screenshots/experiment.png), [topics](https://raw.githubusercontent.com/fatima-zeidan/arapreplab/main/docs/screenshots/topics.png),
|
|
71
|
+
[prediction and export](https://raw.githubusercontent.com/fatima-zeidan/arapreplab/main/docs/screenshots/export.png).
|
|
72
|
+
|
|
73
|
+
## What it does
|
|
74
|
+
|
|
75
|
+
- **Data audit:** class balance, the score you would get by always guessing the largest class, exact and near
|
|
76
|
+
duplicates, duplicates with different labels, Arabizi rows, empty rows.
|
|
77
|
+
- **Cleaning steps you can switch on and off:**
|
|
78
|
+
- 12 normalization steps, two of them dialect aware;
|
|
79
|
+
- an MSA stopword list;
|
|
80
|
+
- two stemmers (light10 and ISRI);
|
|
81
|
+
- negation marking, which tags the two words after ما، مش، لا، لم and similar words so that "مش طيب" is not
|
|
82
|
+
read as "طيب".
|
|
83
|
+
|
|
84
|
+
Negation words are never removed or stemmed.
|
|
85
|
+
- **The experiment:**
|
|
86
|
+
- trains a classifier on many cleaning combinations with the same repeated cross-validation folds;
|
|
87
|
+
- measures the effect of each step from pairs of setups that differ only in that step;
|
|
88
|
+
- tests each effect with the corrected resampled t-test (Nadeau and Bengio, 2003) and Holm's correction, so a
|
|
89
|
+
lucky difference isn't reported as a real one;
|
|
90
|
+
- runs one planned test of "all steps vs raw text", and shows the best setup with a note that picking it from
|
|
91
|
+
many setups makes its gap look larger than it is.
|
|
92
|
+
- **Models:** linear SVM, logistic regression and complement naive Bayes, on word or character TF-IDF features.
|
|
93
|
+
The vectorizer is fitted on the training folds only. You can register any scikit-learn classifier from Python.
|
|
94
|
+
- **Topics** with NMF or LDA, a final model you can try on new sentences, and model save/load.
|
|
95
|
+
- **Model check:** a confusion matrix and the list of texts the model gets wrong, each predicted by a model that
|
|
96
|
+
never saw it.
|
|
97
|
+
- **BERT check (optional):** compares your chosen TF-IDF setup (usually the best one from the experiment) with a pretrained Arabic BERT model (CAMeLBERT,
|
|
98
|
+
AraBERT or MARBERT) on the same folds, with the same corrected t-test. The model is downloaded once and then
|
|
99
|
+
runs offline.
|
|
100
|
+
- **Auto analysis:** the whole workflow with one click, ending in a short plain-language summary that can be
|
|
101
|
+
saved as text or as a full JSON report.
|
|
102
|
+
- **Help as you go:** a bar at the bottom shows which steps are done and what to do next, every setting has a
|
|
103
|
+
tooltip, and the results open with a short summary in plain words.
|
|
104
|
+
- **Reproducibility:**
|
|
105
|
+
- one random seed for everything;
|
|
106
|
+
- saved sessions;
|
|
107
|
+
- a JSON report of every run;
|
|
108
|
+
- every action in the app (loading, cleaning, experiment, topics, training, predictions, exports) is logged, and
|
|
109
|
+
the log can be saved as a Python script or a Jupyter notebook that repeats the whole session without the app;
|
|
110
|
+
- an environment capsule with package versions and `pip freeze`.
|
|
111
|
+
|
|
112
|
+
## Install
|
|
113
|
+
|
|
114
|
+
You need Python 3.10 or newer, on Windows or Linux.
|
|
115
|
+
|
|
116
|
+
```bash
|
|
117
|
+
pip install arapreplab
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
From a copy of this repository:
|
|
121
|
+
|
|
122
|
+
```bash
|
|
123
|
+
pip install -e ".[dev]"
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
With conda:
|
|
127
|
+
|
|
128
|
+
```bash
|
|
129
|
+
conda env create -f environment.yml
|
|
130
|
+
conda activate arapreplab
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
For the optional BERT check (adds torch and transformers, about 1 GB):
|
|
134
|
+
|
|
135
|
+
```bash
|
|
136
|
+
pip install "arapreplab[bert]"
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
## Quick start
|
|
140
|
+
|
|
141
|
+
Start the app:
|
|
142
|
+
|
|
143
|
+
```bash
|
|
144
|
+
python -m arapreplab
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
1. **Data:** click *Open file…* and pick a CSV or Excel file (or *Load sample data*). Check the text and label
|
|
148
|
+
columns, then click *Use columns & audit*.
|
|
149
|
+
2. **Cleaning:** tick steps and click *Preview* to see the text before and after.
|
|
150
|
+
3. **Experiment:** click *Run experiment*. The window stays usable while it runs.
|
|
151
|
+
4. **Results:** see which steps help, hurt or make no clear difference, then *Use best configuration*.
|
|
152
|
+
5. **Topics**, **Predict & Export** and the optional **BERT check** do the rest. *Save session* keeps all your
|
|
153
|
+
settings for next time.
|
|
154
|
+
|
|
155
|
+
Or load your file and press **⚡ Auto analysis** (top bar). It does the work of tabs 1 to 6 in order, recommends a cleaning
|
|
156
|
+
setup with a fixed rule (only steps that clearly help; raw text if nothing does), tests it on texts the model
|
|
157
|
+
has not seen, trains the final model, finds topics, and explains the result in plain words. Every tab is filled
|
|
158
|
+
in afterwards, so you can look closer.
|
|
159
|
+
|
|
160
|
+
The same analysis from Python, without the GUI:
|
|
161
|
+
|
|
162
|
+
```python
|
|
163
|
+
from arapreplab.core import ExperimentSettings, run_experiment
|
|
164
|
+
from arapreplab.io import load_table
|
|
165
|
+
|
|
166
|
+
df = load_table("examples/data/oclar.csv")
|
|
167
|
+
result = run_experiment(df["review"], df["sentiment"], ExperimentSettings(n_splits=5, n_repeats=5, seed=42))
|
|
168
|
+
|
|
169
|
+
for e in result.effects:
|
|
170
|
+
print(e.factor, e.level, round(e.mean_diff, 4), round(e.p_holm, 3), e.verdict)
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
More examples are in `examples/`. To see the whole workflow with its tables and charts in one place, open
|
|
174
|
+
`examples/walkthrough.ipynb` (`pip install -e ".[notebook]"`, then `jupyter notebook`).
|
|
175
|
+
|
|
176
|
+
## Methods and sources
|
|
177
|
+
|
|
178
|
+
`docs/methods.md` lists where every cleaning step and statistical method comes from (light10, ISRI, the
|
|
179
|
+
Nadeau and Bengio test, Holm's correction and others) and how each one was checked.
|
|
180
|
+
|
|
181
|
+
## Data
|
|
182
|
+
|
|
183
|
+
`examples/data/` holds three public datasets, already cleaned. `SOURCES.md` lists the exact changes made to each.
|
|
184
|
+
|
|
185
|
+
| File | Rows | Text | License | Source |
|
|
186
|
+
|---|---|---|---|---|
|
|
187
|
+
| `oclar.csv` | 3,916 | Lebanese reviews of hotels, restaurants and shops | CC BY 4.0 | Omari et al. 2019, doi:10.24432/C5SP66 |
|
|
188
|
+
| `arabic_twitter.csv` | 1,995 | Tweets in MSA and Jordanian Arabic | CC BY 4.0 | Abdulla 2013, doi:10.24432/C5F31B |
|
|
189
|
+
| `arsarcasm.csv` | 10,547 | Tweets labelled for sentiment, sarcasm and dialect | MIT | Abu Farha and Magdy 2020 |
|
|
190
|
+
|
|
191
|
+
`sample_reviews.csv` is made-up data for demos and tests only.
|
|
192
|
+
|
|
193
|
+
## Reproducing the paper
|
|
194
|
+
|
|
195
|
+
```bash
|
|
196
|
+
python examples/reproduce_paper.py
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
This runs every case study in the paper with the same seed and writes the results and a summary table to
|
|
200
|
+
`results/`. It takes 1 to 2 hours on a laptop. The numbers came out identical, to four decimals, on Windows 11
|
|
201
|
+
and Ubuntu Linux. To rebuild the data files from the original downloads, see `examples/prepare_datasets.py`.
|
|
202
|
+
|
|
203
|
+
To check the numbers independently, run:
|
|
204
|
+
|
|
205
|
+
```bash
|
|
206
|
+
python examples/check_results.py
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
It confirms the dataset counts against the published ones and recomputes the raw-text scores with plain
|
|
210
|
+
scikit-learn. It also runs the experiment on shuffled labels, where no step should help, and redoes the t-test by
|
|
211
|
+
hand.
|
|
212
|
+
|
|
213
|
+
`python examples/negation_check.py` compares negation marking on and off for ten short sentences.
|
|
214
|
+
|
|
215
|
+
`python examples/balancing_check.py` compares class weights with SMOTE and random over- and undersampling
|
|
216
|
+
(`pip install imbalanced-learn`); class weights did as well or better on all three datasets.
|
|
217
|
+
|
|
218
|
+
`python examples/bert_compare.py` compares the best TF-IDF setup of each run with CAMeLBERT-Mix (or other models
|
|
219
|
+
with `--models`) and writes `paper/bert_results.csv`. It needs `pip install -e ".[bert]"` and an internet
|
|
220
|
+
connection the first time.
|
|
221
|
+
|
|
222
|
+
`python examples/camel_check.py` compares the normalization steps with CAMeL Tools (`pip install camel-tools`). On
|
|
223
|
+
the three datasets the output is the same for all but 4 of 16,458 texts, and in those 4 AraPrepLab also removes
|
|
224
|
+
rare Quranic marks that CAMeL Tools keeps. CAMeL Tools is not a dependency because it installs torch and
|
|
225
|
+
transformers, which makes the tool much heavier to install offline.
|
|
226
|
+
|
|
227
|
+
## Stand-alone app
|
|
228
|
+
|
|
229
|
+
For people without Python, build a folder that runs on its own:
|
|
230
|
+
|
|
231
|
+
```bash
|
|
232
|
+
pip install -e ".[app]"
|
|
233
|
+
python packaging/build_exe.py
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
The app is in `dist/AraPrepLab/` (`AraPrepLab.exe` on Windows). GitHub Actions builds the Windows version for
|
|
237
|
+
every release tag and attaches it to the run.
|
|
238
|
+
|
|
239
|
+
## Development
|
|
240
|
+
|
|
241
|
+
```bash
|
|
242
|
+
pip install -e ".[dev]"
|
|
243
|
+
pytest --cov=arapreplab.core --cov=arapreplab.io
|
|
244
|
+
python tools/check_app.py --quick
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
`tools/check_app.py` opens the app and presses every button by itself: each tab, cleaning step, model, feature
|
|
248
|
+
type, metric, design, export and error message. It reports PASS or FAIL for each. `docs/testing.md` lists what it
|
|
249
|
+
covers and the few things to check by hand.
|
|
250
|
+
|
|
251
|
+
GitHub Actions runs the tests on Windows and Linux, with pip (Python 3.10 and 3.12) and with conda, on every push.
|
|
252
|
+
|
|
253
|
+
## Limitations
|
|
254
|
+
|
|
255
|
+
- Arabizi (Arabic written in Latin letters) is detected by the audit but not converted.
|
|
256
|
+
- The dialect steps are rule based, with short word lists. They do not identify which dialect a text is in.
|
|
257
|
+
- The experiment uses classical TF-IDF models. They only know the words in their training data. A model trained on the
|
|
258
|
+
UCI tweets, for example, has never seen "ما بنصح" and labels "ما بنصح فيه أبداً" as positive, while the same
|
|
259
|
+
pipeline trained on the Lebanese reviews labels it negative. Train on data from the same domain and dialect as the
|
|
260
|
+
texts you want to label.
|
|
261
|
+
- The BERT check uses the model frozen, with a logistic regression on top. Fine-tuning the whole model usually
|
|
262
|
+
scores higher, but needs a GPU and much more time, so it is not included.
|
|
263
|
+
- It is a single-user desktop app.
|
|
264
|
+
- On Linux, Arabic typed into the prediction box shows as separate letters, because Tk on Linux does not join
|
|
265
|
+
Arabic letters. The prediction itself is not affected, and Windows displays it correctly.
|
|
266
|
+
|
|
267
|
+
## License and citation
|
|
268
|
+
|
|
269
|
+
MIT License. See `CITATION.cff` for how to cite AraPrepLab. The released versions are archived on Zenodo: https://doi.org/10.5281/zenodo.24765356
|
|
270
|
+
|
|
271
|
+
Fatima Zeidan and Leen El Sakka, Lebanese American University.
|
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
# AraPrepLab
|
|
2
|
+
|
|
3
|
+
[](https://doi.org/10.5281/zenodo.24765356)
|
|
4
|
+
|
|
5
|
+
AraPrepLab is a desktop tool for Arabic text classification that answers one practical question: which cleaning
|
|
6
|
+
steps actually improve results on my data?
|
|
7
|
+
|
|
8
|
+
Arabic text is written in many ways. The same word can appear with or without diacritics, with different alef or
|
|
9
|
+
hamza forms, with stretched letters, or in a dialect spelling. Studies disagree on which of these to normalize, and
|
|
10
|
+
whether to stem, because the answer changes from one dataset to another. AraPrepLab lets you load your own
|
|
11
|
+
spreadsheet, test the cleaning choices on it, and see which ones make a real difference. You don't need to write
|
|
12
|
+
any code, and nothing leaves your computer.
|
|
13
|
+
|
|
14
|
+

|
|
15
|
+
|
|
16
|
+
More screenshots: [data and audit](https://raw.githubusercontent.com/fatima-zeidan/arapreplab/main/docs/screenshots/data.png), [cleaning preview](https://raw.githubusercontent.com/fatima-zeidan/arapreplab/main/docs/screenshots/cleaning.png),
|
|
17
|
+
[model check](https://raw.githubusercontent.com/fatima-zeidan/arapreplab/main/docs/screenshots/check.png), [BERT check](https://raw.githubusercontent.com/fatima-zeidan/arapreplab/main/docs/screenshots/bert.png),
|
|
18
|
+
[Auto analysis](https://raw.githubusercontent.com/fatima-zeidan/arapreplab/main/docs/screenshots/auto.png),
|
|
19
|
+
[experiment running](https://raw.githubusercontent.com/fatima-zeidan/arapreplab/main/docs/screenshots/experiment.png), [topics](https://raw.githubusercontent.com/fatima-zeidan/arapreplab/main/docs/screenshots/topics.png),
|
|
20
|
+
[prediction and export](https://raw.githubusercontent.com/fatima-zeidan/arapreplab/main/docs/screenshots/export.png).
|
|
21
|
+
|
|
22
|
+
## What it does
|
|
23
|
+
|
|
24
|
+
- **Data audit:** class balance, the score you would get by always guessing the largest class, exact and near
|
|
25
|
+
duplicates, duplicates with different labels, Arabizi rows, empty rows.
|
|
26
|
+
- **Cleaning steps you can switch on and off:**
|
|
27
|
+
- 12 normalization steps, two of them dialect aware;
|
|
28
|
+
- an MSA stopword list;
|
|
29
|
+
- two stemmers (light10 and ISRI);
|
|
30
|
+
- negation marking, which tags the two words after ما، مش، لا، لم and similar words so that "مش طيب" is not
|
|
31
|
+
read as "طيب".
|
|
32
|
+
|
|
33
|
+
Negation words are never removed or stemmed.
|
|
34
|
+
- **The experiment:**
|
|
35
|
+
- trains a classifier on many cleaning combinations with the same repeated cross-validation folds;
|
|
36
|
+
- measures the effect of each step from pairs of setups that differ only in that step;
|
|
37
|
+
- tests each effect with the corrected resampled t-test (Nadeau and Bengio, 2003) and Holm's correction, so a
|
|
38
|
+
lucky difference isn't reported as a real one;
|
|
39
|
+
- runs one planned test of "all steps vs raw text", and shows the best setup with a note that picking it from
|
|
40
|
+
many setups makes its gap look larger than it is.
|
|
41
|
+
- **Models:** linear SVM, logistic regression and complement naive Bayes, on word or character TF-IDF features.
|
|
42
|
+
The vectorizer is fitted on the training folds only. You can register any scikit-learn classifier from Python.
|
|
43
|
+
- **Topics** with NMF or LDA, a final model you can try on new sentences, and model save/load.
|
|
44
|
+
- **Model check:** a confusion matrix and the list of texts the model gets wrong, each predicted by a model that
|
|
45
|
+
never saw it.
|
|
46
|
+
- **BERT check (optional):** compares your chosen TF-IDF setup (usually the best one from the experiment) with a pretrained Arabic BERT model (CAMeLBERT,
|
|
47
|
+
AraBERT or MARBERT) on the same folds, with the same corrected t-test. The model is downloaded once and then
|
|
48
|
+
runs offline.
|
|
49
|
+
- **Auto analysis:** the whole workflow with one click, ending in a short plain-language summary that can be
|
|
50
|
+
saved as text or as a full JSON report.
|
|
51
|
+
- **Help as you go:** a bar at the bottom shows which steps are done and what to do next, every setting has a
|
|
52
|
+
tooltip, and the results open with a short summary in plain words.
|
|
53
|
+
- **Reproducibility:**
|
|
54
|
+
- one random seed for everything;
|
|
55
|
+
- saved sessions;
|
|
56
|
+
- a JSON report of every run;
|
|
57
|
+
- every action in the app (loading, cleaning, experiment, topics, training, predictions, exports) is logged, and
|
|
58
|
+
the log can be saved as a Python script or a Jupyter notebook that repeats the whole session without the app;
|
|
59
|
+
- an environment capsule with package versions and `pip freeze`.
|
|
60
|
+
|
|
61
|
+
## Install
|
|
62
|
+
|
|
63
|
+
You need Python 3.10 or newer, on Windows or Linux.
|
|
64
|
+
|
|
65
|
+
```bash
|
|
66
|
+
pip install arapreplab
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
From a copy of this repository:
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
pip install -e ".[dev]"
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
With conda:
|
|
76
|
+
|
|
77
|
+
```bash
|
|
78
|
+
conda env create -f environment.yml
|
|
79
|
+
conda activate arapreplab
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
For the optional BERT check (adds torch and transformers, about 1 GB):
|
|
83
|
+
|
|
84
|
+
```bash
|
|
85
|
+
pip install "arapreplab[bert]"
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
## Quick start
|
|
89
|
+
|
|
90
|
+
Start the app:
|
|
91
|
+
|
|
92
|
+
```bash
|
|
93
|
+
python -m arapreplab
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
1. **Data:** click *Open file…* and pick a CSV or Excel file (or *Load sample data*). Check the text and label
|
|
97
|
+
columns, then click *Use columns & audit*.
|
|
98
|
+
2. **Cleaning:** tick steps and click *Preview* to see the text before and after.
|
|
99
|
+
3. **Experiment:** click *Run experiment*. The window stays usable while it runs.
|
|
100
|
+
4. **Results:** see which steps help, hurt or make no clear difference, then *Use best configuration*.
|
|
101
|
+
5. **Topics**, **Predict & Export** and the optional **BERT check** do the rest. *Save session* keeps all your
|
|
102
|
+
settings for next time.
|
|
103
|
+
|
|
104
|
+
Or load your file and press **⚡ Auto analysis** (top bar). It does the work of tabs 1 to 6 in order, recommends a cleaning
|
|
105
|
+
setup with a fixed rule (only steps that clearly help; raw text if nothing does), tests it on texts the model
|
|
106
|
+
has not seen, trains the final model, finds topics, and explains the result in plain words. Every tab is filled
|
|
107
|
+
in afterwards, so you can look closer.
|
|
108
|
+
|
|
109
|
+
The same analysis from Python, without the GUI:
|
|
110
|
+
|
|
111
|
+
```python
|
|
112
|
+
from arapreplab.core import ExperimentSettings, run_experiment
|
|
113
|
+
from arapreplab.io import load_table
|
|
114
|
+
|
|
115
|
+
df = load_table("examples/data/oclar.csv")
|
|
116
|
+
result = run_experiment(df["review"], df["sentiment"], ExperimentSettings(n_splits=5, n_repeats=5, seed=42))
|
|
117
|
+
|
|
118
|
+
for e in result.effects:
|
|
119
|
+
print(e.factor, e.level, round(e.mean_diff, 4), round(e.p_holm, 3), e.verdict)
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
More examples are in `examples/`. To see the whole workflow with its tables and charts in one place, open
|
|
123
|
+
`examples/walkthrough.ipynb` (`pip install -e ".[notebook]"`, then `jupyter notebook`).
|
|
124
|
+
|
|
125
|
+
## Methods and sources
|
|
126
|
+
|
|
127
|
+
`docs/methods.md` lists where every cleaning step and statistical method comes from (light10, ISRI, the
|
|
128
|
+
Nadeau and Bengio test, Holm's correction and others) and how each one was checked.
|
|
129
|
+
|
|
130
|
+
## Data
|
|
131
|
+
|
|
132
|
+
`examples/data/` holds three public datasets, already cleaned. `SOURCES.md` lists the exact changes made to each.
|
|
133
|
+
|
|
134
|
+
| File | Rows | Text | License | Source |
|
|
135
|
+
|---|---|---|---|---|
|
|
136
|
+
| `oclar.csv` | 3,916 | Lebanese reviews of hotels, restaurants and shops | CC BY 4.0 | Omari et al. 2019, doi:10.24432/C5SP66 |
|
|
137
|
+
| `arabic_twitter.csv` | 1,995 | Tweets in MSA and Jordanian Arabic | CC BY 4.0 | Abdulla 2013, doi:10.24432/C5F31B |
|
|
138
|
+
| `arsarcasm.csv` | 10,547 | Tweets labelled for sentiment, sarcasm and dialect | MIT | Abu Farha and Magdy 2020 |
|
|
139
|
+
|
|
140
|
+
`sample_reviews.csv` is made-up data for demos and tests only.
|
|
141
|
+
|
|
142
|
+
## Reproducing the paper
|
|
143
|
+
|
|
144
|
+
```bash
|
|
145
|
+
python examples/reproduce_paper.py
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
This runs every case study in the paper with the same seed and writes the results and a summary table to
|
|
149
|
+
`results/`. It takes 1 to 2 hours on a laptop. The numbers came out identical, to four decimals, on Windows 11
|
|
150
|
+
and Ubuntu Linux. To rebuild the data files from the original downloads, see `examples/prepare_datasets.py`.
|
|
151
|
+
|
|
152
|
+
To check the numbers independently, run:
|
|
153
|
+
|
|
154
|
+
```bash
|
|
155
|
+
python examples/check_results.py
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
It confirms the dataset counts against the published ones and recomputes the raw-text scores with plain
|
|
159
|
+
scikit-learn. It also runs the experiment on shuffled labels, where no step should help, and redoes the t-test by
|
|
160
|
+
hand.
|
|
161
|
+
|
|
162
|
+
`python examples/negation_check.py` compares negation marking on and off for ten short sentences.
|
|
163
|
+
|
|
164
|
+
`python examples/balancing_check.py` compares class weights with SMOTE and random over- and undersampling
|
|
165
|
+
(`pip install imbalanced-learn`); class weights did as well or better on all three datasets.
|
|
166
|
+
|
|
167
|
+
`python examples/bert_compare.py` compares the best TF-IDF setup of each run with CAMeLBERT-Mix (or other models
|
|
168
|
+
with `--models`) and writes `paper/bert_results.csv`. It needs `pip install -e ".[bert]"` and an internet
|
|
169
|
+
connection the first time.
|
|
170
|
+
|
|
171
|
+
`python examples/camel_check.py` compares the normalization steps with CAMeL Tools (`pip install camel-tools`). On
|
|
172
|
+
the three datasets the output is the same for all but 4 of 16,458 texts, and in those 4 AraPrepLab also removes
|
|
173
|
+
rare Quranic marks that CAMeL Tools keeps. CAMeL Tools is not a dependency because it installs torch and
|
|
174
|
+
transformers, which makes the tool much heavier to install offline.
|
|
175
|
+
|
|
176
|
+
## Stand-alone app
|
|
177
|
+
|
|
178
|
+
For people without Python, build a folder that runs on its own:
|
|
179
|
+
|
|
180
|
+
```bash
|
|
181
|
+
pip install -e ".[app]"
|
|
182
|
+
python packaging/build_exe.py
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
The app is in `dist/AraPrepLab/` (`AraPrepLab.exe` on Windows). GitHub Actions builds the Windows version for
|
|
186
|
+
every release tag and attaches it to the run.
|
|
187
|
+
|
|
188
|
+
## Development
|
|
189
|
+
|
|
190
|
+
```bash
|
|
191
|
+
pip install -e ".[dev]"
|
|
192
|
+
pytest --cov=arapreplab.core --cov=arapreplab.io
|
|
193
|
+
python tools/check_app.py --quick
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
`tools/check_app.py` opens the app and presses every button by itself: each tab, cleaning step, model, feature
|
|
197
|
+
type, metric, design, export and error message. It reports PASS or FAIL for each. `docs/testing.md` lists what it
|
|
198
|
+
covers and the few things to check by hand.
|
|
199
|
+
|
|
200
|
+
GitHub Actions runs the tests on Windows and Linux, with pip (Python 3.10 and 3.12) and with conda, on every push.
|
|
201
|
+
|
|
202
|
+
## Limitations
|
|
203
|
+
|
|
204
|
+
- Arabizi (Arabic written in Latin letters) is detected by the audit but not converted.
|
|
205
|
+
- The dialect steps are rule based, with short word lists. They do not identify which dialect a text is in.
|
|
206
|
+
- The experiment uses classical TF-IDF models. They only know the words in their training data. A model trained on the
|
|
207
|
+
UCI tweets, for example, has never seen "ما بنصح" and labels "ما بنصح فيه أبداً" as positive, while the same
|
|
208
|
+
pipeline trained on the Lebanese reviews labels it negative. Train on data from the same domain and dialect as the
|
|
209
|
+
texts you want to label.
|
|
210
|
+
- The BERT check uses the model frozen, with a logistic regression on top. Fine-tuning the whole model usually
|
|
211
|
+
scores higher, but needs a GPU and much more time, so it is not included.
|
|
212
|
+
- It is a single-user desktop app.
|
|
213
|
+
- On Linux, Arabic typed into the prediction box shows as separate letters, because Tk on Linux does not join
|
|
214
|
+
Arabic letters. The prediction itself is not affected, and Windows displays it correctly.
|
|
215
|
+
|
|
216
|
+
## License and citation
|
|
217
|
+
|
|
218
|
+
MIT License. See `CITATION.cff` for how to cite AraPrepLab. The released versions are archived on Zenodo: https://doi.org/10.5281/zenodo.24765356
|
|
219
|
+
|
|
220
|
+
Fatima Zeidan and Leen El Sakka, Lebanese American University.
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=77", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "arapreplab"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Offline, no-code workbench that shows which Arabic text preprocessing choices help on your data"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.10"
|
|
11
|
+
license = "MIT"
|
|
12
|
+
license-files = ["LICENSE"]
|
|
13
|
+
authors = [
|
|
14
|
+
{ name = "Fatima Zeidan" },
|
|
15
|
+
{ name = "Leen El Sakka" },
|
|
16
|
+
]
|
|
17
|
+
keywords = ["Arabic NLP", "text preprocessing", "text classification", "topic modeling", "GUI", "reproducibility"]
|
|
18
|
+
classifiers = [
|
|
19
|
+
"Programming Language :: Python :: 3",
|
|
20
|
+
"Programming Language :: Python :: 3.10",
|
|
21
|
+
"Programming Language :: Python :: 3.11",
|
|
22
|
+
"Programming Language :: Python :: 3.12",
|
|
23
|
+
"Programming Language :: Python :: 3.13",
|
|
24
|
+
"Operating System :: Microsoft :: Windows",
|
|
25
|
+
"Operating System :: POSIX :: Linux",
|
|
26
|
+
"Natural Language :: Arabic",
|
|
27
|
+
"Intended Audience :: Science/Research",
|
|
28
|
+
"Topic :: Text Processing :: Linguistic",
|
|
29
|
+
"Topic :: Scientific/Engineering :: Artificial Intelligence",
|
|
30
|
+
]
|
|
31
|
+
dependencies = [
|
|
32
|
+
"numpy>=1.23",
|
|
33
|
+
"pandas>=1.5",
|
|
34
|
+
"scipy>=1.9",
|
|
35
|
+
"scikit-learn>=1.2",
|
|
36
|
+
"nltk>=3.8",
|
|
37
|
+
"joblib>=1.2",
|
|
38
|
+
"openpyxl>=3.1",
|
|
39
|
+
"matplotlib>=3.6",
|
|
40
|
+
"customtkinter>=5.2",
|
|
41
|
+
"arabic-reshaper>=3.0",
|
|
42
|
+
"python-bidi>=0.4",
|
|
43
|
+
]
|
|
44
|
+
|
|
45
|
+
[project.optional-dependencies]
|
|
46
|
+
dev = ["pytest>=7", "pytest-cov>=4", "build", "twine"]
|
|
47
|
+
notebook = ["notebook", "ipykernel"]
|
|
48
|
+
camel = ["camel-tools"]
|
|
49
|
+
bert = ["torch>=2.1", "transformers>=4.40"]
|
|
50
|
+
app = ["pyinstaller"]
|
|
51
|
+
|
|
52
|
+
[project.scripts]
|
|
53
|
+
arapreplab = "arapreplab.__main__:main"
|
|
54
|
+
|
|
55
|
+
[project.urls]
|
|
56
|
+
Homepage = "https://github.com/fatima-zeidan/arapreplab"
|
|
57
|
+
Issues = "https://github.com/fatima-zeidan/arapreplab/issues"
|
|
58
|
+
|
|
59
|
+
[tool.setuptools.packages.find]
|
|
60
|
+
where = ["src"]
|
|
61
|
+
|
|
62
|
+
[tool.setuptools.package-data]
|
|
63
|
+
arapreplab = ["data/*.csv"]
|
|
64
|
+
|
|
65
|
+
[tool.pytest.ini_options]
|
|
66
|
+
testpaths = ["tests"]
|
|
67
|
+
addopts = "-q"
|
|
68
|
+
|
|
69
|
+
[tool.coverage.run]
|
|
70
|
+
source = ["arapreplab"]
|
|
71
|
+
omit = ["*/arapreplab/gui/*", "*/arapreplab/__main__.py"]
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"""AraPrepLab core: analysis logic with no GUI imports."""
|
|
2
|
+
from .audit import AuditReport, audit_dataset
|
|
3
|
+
from .auto import AutoReport, auto_analysis
|
|
4
|
+
from .experiment import (ExperimentCancelled, ExperimentResult, ExperimentSettings, generate_configs,
|
|
5
|
+
run_experiment)
|
|
6
|
+
from .labels import check_classes, clean_labels
|
|
7
|
+
from .final_model import FinalModel, ModelCheck, check_model, train_final
|
|
8
|
+
from .models import FEATURES, MODELS, build_pipeline, register_model
|
|
9
|
+
from .normalize import STEP_ORDER, STEPS, apply_steps
|
|
10
|
+
from .negation import mark_negation
|
|
11
|
+
from .pipeline import NEGATION_KEY, STOPWORDS_KEY, PreprocessConfig
|
|
12
|
+
from .seed import set_global_seed
|
|
13
|
+
from .stemming import STEMMERS, stem_text
|
|
14
|
+
from .topics import TopicResult, fit_topics
|
|
15
|
+
|
|
16
|
+
__all__ = [
|
|
17
|
+
"AuditReport", "audit_dataset", "AutoReport", "auto_analysis", "ExperimentCancelled", "ExperimentResult", "ExperimentSettings",
|
|
18
|
+
"generate_configs", "run_experiment", "check_classes", "clean_labels", "FinalModel", "ModelCheck", "check_model", "train_final", "FEATURES", "MODELS",
|
|
19
|
+
"build_pipeline", "register_model", "STEP_ORDER", "STEPS", "apply_steps", "STOPWORDS_KEY", "NEGATION_KEY", "mark_negation",
|
|
20
|
+
"PreprocessConfig", "set_global_seed", "STEMMERS", "stem_text", "TopicResult", "fit_topics",
|
|
21
|
+
]
|