Commit ·
7db8fbe
1
Parent(s): 6e716e3
Cleanup pass 3: Delete debug_verdict.py, rewrite tasks/todo.md and src/README.md for v2.0
Browse files- src/README.md +52 -49
- tasks/todo.md +45 -34
- tests/v2/debug_verdict.py +0 -10
src/README.md
CHANGED
|
@@ -1,55 +1,58 @@
|
|
| 1 |
-
# src/ —
|
| 2 |
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
All core project code should live in `src/`: data loaders, preprocessing, training scripts, model definitions, and inference API.
|
| 6 |
-
|
| 7 |
-
Suggested layout
|
| 8 |
-
|
| 9 |
-
- `src/app.py` — lightweight Flask/FastAPI app for inference and testing
|
| 10 |
-
- `src/train.py` — training orchestration (argument parsing, checkpointing)
|
| 11 |
-
- `src/evaluate.py` — evaluation scripts and metrics
|
| 12 |
-
- `src/data_loader.py` — dataset loaders and helpers
|
| 13 |
-
- `src/preprocessing.py` — normalization, tokenization, and text cleaning
|
| 14 |
-
- `src/models/` — model classes or adapters
|
| 15 |
-
- `src/utils/` — utility functions (logging, metrics, etc.)
|
| 16 |
-
- `src/tests/` — unit and integration tests for core modules
|
| 17 |
-
|
| 18 |
-
File responsibilities and guidelines
|
| 19 |
-
|
| 20 |
-
- Keep functions small and well-documented.
|
| 21 |
-
- Expose a stable API for inference (e.g., `predict(text: str) -> dict`). Document the input/output shapes.
|
| 22 |
-
- Add type hints where practical.
|
| 23 |
-
|
| 24 |
-
Coding conventions
|
| 25 |
-
|
| 26 |
-
- Use the project style (PEP8). Add a linter config if needed (e.g., `pyproject.toml` or `.flake8`).
|
| 27 |
-
- Write tests for data loaders and small utilities. Place tests under `src/tests/` and use pytest.
|
| 28 |
-
|
| 29 |
-
What to add when working in `src/`
|
| 30 |
-
|
| 31 |
-
- Small, focused commits that update a single feature or test.
|
| 32 |
-
- If adding a new script, update top-level `README.md` with a one-line summary and usage example.
|
| 33 |
-
- If you modify input/output shapes for the inference API, update the API docs and communicate in the PR description.
|
| 34 |
-
|
| 35 |
-
Quick example: inference contract
|
| 36 |
-
|
| 37 |
-
- Input: Arabic text string (utf-8)
|
| 38 |
-
- Output: JSON object with fields such as `text`, `suggestions` (list), `confidence` (0-1), and optional `edits` with positions
|
| 39 |
-
|
| 40 |
-
Example output shape
|
| 41 |
|
| 42 |
```
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
```
|
| 51 |
|
| 52 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
|
| 54 |
-
|
| 55 |
-
|
|
|
|
|
|
| 1 |
+
# src/ — Source Code
|
| 2 |
|
| 3 |
+
## Structure
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
|
| 5 |
```
|
| 6 |
+
src/
|
| 7 |
+
├── app.py # Flask application — routes + pipeline orchestration
|
| 8 |
+
├── model_loader.py # Model loading (Spelling, Grammar, Summarization, Autocomplete)
|
| 9 |
+
├── hf_inference.py # HuggingFace API inference wrappers
|
| 10 |
+
├── index.html # Main web UI (single-page app)
|
| 11 |
+
├── favicon.svg # Site icon
|
| 12 |
+
├── css/ # Stylesheets
|
| 13 |
+
│ ├── tokens.css # Design tokens (colors, spacing)
|
| 14 |
+
│ ├── base.css # Base styles
|
| 15 |
+
│ └── components.css # Component styles
|
| 16 |
+
├── js/ # Frontend JavaScript modules
|
| 17 |
+
│ ├── editor.js # Editor logic, events, debouncing
|
| 18 |
+
│ ├── renderer.js # Offset-based highlight rendering
|
| 19 |
+
│ ├── selection.js # Cursor/selection save & restore
|
| 20 |
+
│ ├── ui.js # Tooltips, suggestion lists, scores
|
| 21 |
+
│ ├── api.js # Backend API fetch wrappers
|
| 22 |
+
│ ├── format.js # Text formatting
|
| 23 |
+
│ ├── theme.js # Theme switching
|
| 24 |
+
│ ├── autocomplete.js # Autocomplete UI
|
| 25 |
+
│ ├── auth/ # Authentication (Supabase)
|
| 26 |
+
│ ├── documents/ # Local document management
|
| 27 |
+
│ ├── documents-cloud/ # Cloud document sync
|
| 28 |
+
│ ├── summaries/ # Text summarization UI
|
| 29 |
+
│ ├── settings-sync/ # Settings sync
|
| 30 |
+
│ ├── sync/ # Real-time sync engine
|
| 31 |
+
│ └── vendor/ # Third-party libraries
|
| 32 |
+
└── nlp/ # NLP pipeline modules
|
| 33 |
+
├── spelling/ # AraSpell spelling correction
|
| 34 |
+
│ ├── araspell_rules.py
|
| 35 |
+
│ └── araspell_service.py
|
| 36 |
+
├── grammar/ # Grammar correction
|
| 37 |
+
│ ├── grammar_rules.py
|
| 38 |
+
│ └── grammar_service.py
|
| 39 |
+
├── punctuation/ # Punctuation restoration
|
| 40 |
+
│ ├── punctuation_rules.py
|
| 41 |
+
│ └── punctuation_service.py
|
| 42 |
+
├── autocomplete/ # Text autocomplete
|
| 43 |
+
├── dialect/ # Dialect detection
|
| 44 |
+
├── pipeline_context.py # Shared pipeline state
|
| 45 |
+
├── stage_locker.py # Cross-stage text locking
|
| 46 |
+
└── correction_patch.py # Correction patch utilities
|
| 47 |
```
|
| 48 |
|
| 49 |
+
## API Contract
|
| 50 |
+
|
| 51 |
+
- **Input**: Arabic text string (UTF-8)
|
| 52 |
+
- **Output**: JSON with `corrected`, `suggestions[]` (each with `start`, `end`, `replacement`, `explanation`), and `timing_ms`
|
| 53 |
+
|
| 54 |
+
## Running
|
| 55 |
|
| 56 |
+
```bash
|
| 57 |
+
cd src && gunicorn app:app --bind 0.0.0.0:7860 --timeout 120 --workers 1
|
| 58 |
+
```
|
tasks/todo.md
CHANGED
|
@@ -1,41 +1,52 @@
|
|
| 1 |
-
#
|
| 2 |
|
| 3 |
-
##
|
| 4 |
-
- [
|
| 5 |
-
- [
|
| 6 |
-
- [
|
| 7 |
-
- [
|
| 8 |
-
- [
|
| 9 |
-
- [
|
| 10 |
-
- [ ]
|
| 11 |
-
- [ ] Verify that the frontend loads correctly and contains no console errors
|
| 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 |
-
- [ ] Wire
|
|
|
|
|
|
|
| 37 |
|
| 38 |
-
##
|
| 39 |
-
- [ ]
|
| 40 |
-
- [ ]
|
| 41 |
-
- [ ]
|
|
|
|
|
|
|
|
|
| 1 |
+
# BAYAN v2.0 — Task List
|
| 2 |
|
| 3 |
+
## Phase A: Test Infrastructure ✅
|
| 4 |
+
- [x] Create `tests/v2/test_level1_raw.py` — Raw model tests with TP/FP/FN/TN verdicts
|
| 5 |
+
- [x] Create `tests/v2/test_level2_solo.py` — Solo API endpoint tests
|
| 6 |
+
- [x] Create `tests/v2/test_level3_integrated.py` — Full pipeline tests
|
| 7 |
+
- [x] Create `tests/v2/benchmark_matrix.py` — Master comparison runner
|
| 8 |
+
- [x] Fix verdict logic (strip terminal punctuation before comparison)
|
| 9 |
+
- [x] Run baseline on entities + spelling datasets
|
| 10 |
+
- [ ] Run full 320-test baseline across all 3 levels
|
|
|
|
| 11 |
|
| 12 |
+
## Phase A.1: Project Cleanup ✅
|
| 13 |
+
- [x] Archive legacy scripts (AraSpell.py, Grammer_Rules.py, PuncAra.py)
|
| 14 |
+
- [x] Archive 36 old phase/verification reports
|
| 15 |
+
- [x] Archive 23 old test files + 8 phase10 helpers
|
| 16 |
+
- [x] Delete 35 orphaned debug/temp files
|
| 17 |
+
- [x] Fix .gitignore corruption (binary null bytes)
|
| 18 |
+
- [x] Fix PROJECT_DESCRIPTION.md stale reference
|
| 19 |
+
- [x] Archive docs/audit + docs/audits
|
| 20 |
|
| 21 |
+
## Phase B: Extract Stages (NOT STARTED)
|
| 22 |
+
- [ ] Create `src/nlp/stages/spelling_stage.py`
|
| 23 |
+
- [ ] Create `src/nlp/stages/grammar_stage.py`
|
| 24 |
+
- [ ] Create `src/nlp/stages/punctuation_stage.py`
|
| 25 |
+
- [ ] Each stage wraps: model call → filter → verdict
|
| 26 |
+
- [ ] Hash (comment out) old inline stage code in `app.py`
|
| 27 |
+
- [ ] Re-run v2 benchmark → must match Phase A baseline
|
| 28 |
|
| 29 |
+
## Phase C: Extract Filters (NOT STARTED)
|
| 30 |
+
- [ ] Create `src/nlp/filters/` module
|
| 31 |
+
- [ ] Extract overlap resolution, religious guard, entity guard
|
| 32 |
+
- [ ] Hash old filter code in `app.py`
|
| 33 |
+
- [ ] Re-run v2 benchmark → must match baseline
|
| 34 |
|
| 35 |
+
## Phase D: Extract Preprocessors (NOT STARTED)
|
| 36 |
+
- [ ] Create `src/nlp/preprocessors/` module
|
| 37 |
+
- [ ] Extract text normalization, diacritic handling, chunk splitting
|
| 38 |
+
- [ ] Hash old preprocessor code in `app.py`
|
| 39 |
+
- [ ] Re-run v2 benchmark → must match baseline
|
| 40 |
|
| 41 |
+
## Phase E: Create Pipeline Orchestrator (NOT STARTED)
|
| 42 |
+
- [ ] Create `src/nlp/pipeline.py` — orchestrates stages via PipelineContext
|
| 43 |
+
- [ ] Wire `app.py` /api/analyze to use `pipeline.run(text)`
|
| 44 |
+
- [ ] Hash old monolithic analyze code in `app.py`
|
| 45 |
+
- [ ] Re-run v2 benchmark → must match baseline
|
| 46 |
|
| 47 |
+
## Phase F: Clean app.py (NOT STARTED)
|
| 48 |
+
- [ ] Move helpers (get_word_positions, OffsetMapper, etc.) to utility modules
|
| 49 |
+
- [ ] Remove all hashed (commented) code blocks
|
| 50 |
+
- [ ] app.py should only contain: Flask routes + pipeline.run() calls
|
| 51 |
+
- [ ] Final v2 benchmark → must match baseline
|
| 52 |
+
- [ ] Target: app.py < 500 lines
|
tests/v2/debug_verdict.py
DELETED
|
@@ -1,10 +0,0 @@
|
|
| 1 |
-
import json
|
| 2 |
-
|
| 3 |
-
d = json.load(open('tests/v2/reports/level3_integrated_results.json', 'r', encoding='utf-8'))
|
| 4 |
-
for r in d['results'][:5]:
|
| 5 |
-
print(f"ID: {r['id']}")
|
| 6 |
-
print(f" IN: {r['input_text']}")
|
| 7 |
-
print(f" EXP: {r['expected']}")
|
| 8 |
-
print(f" OUT: {r['pipeline_corrected']}")
|
| 9 |
-
print(f" V: {r['verdict']} | {r['detail']}")
|
| 10 |
-
print()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|