File size: 2,072 Bytes
52b0ede
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# System architecture

## Components

```mermaid
flowchart TB
  subgraph data [Data layer]
    CSV[data/raw/youtoxic_english_1000.csv]
    CFG[configs/*.yaml]
  end

  subgraph training [Training]
    PIPE[run_pipeline.py]
    PRE[TextPreprocessor]
    BL[build_model LR RF XGB]
    EV[Evaluator]
    CSV --> PIPE
    CFG --> PIPE
    PIPE --> PRE --> BL --> EV
    EV --> SUM[reports/summary.csv]
    BL --> JOB[models/experiments/]
  end

  subgraph inference [Inference]
    MS[ModelService]
    JOB2[models/final_model.joblib]
    JOB2 --> MS
    API[FastAPI src/api/main.py]
    UI[Streamlit src/app/app.py]
    MS --> API
    MS --> UI
  end
```

## Module map

| Module | Responsibility |
|--------|----------------|
| `src/data/loader.py` | Load raw CSV, optional processed paths |
| `src/features/text_preprocessor.py` | Clean and lemmatize text |
| `src/features/vectorizer.py` | Standalone TF-IDF (notebooks); baselines embed TF-IDF in sklearn `Pipeline` |
| `src/models/baseline.py` | `LRModel`, `RFModel`, `XGBModel`, `build_model()` |
| `src/evaluation/evaluator.py` | Metrics, ROC, confusion matrix, error analysis, `summary.csv` |
| `src/pipeline/run_pipeline.py` | Orchestrates training + evaluation |
| `src/service/model_service.py` | Loads joblib or Hugging Face models; `predict(text)` |
| `src/api/main.py` | REST endpoints, lifespan model load |
| `src/app/app.py` | Streamlit UI; calls `ModelService` directly |

## Label strategy

- **Binary default:** column `IsToxic` → Safe `0`, Toxic `1`
- User-facing strings: **Safe** / **Toxic** (not “hate” or “harmful” in the UI copy)
- API returns `is_toxic` and `probability` (P(toxic))

## Docker

[`docker-compose.yml`](../docker-compose.yml) runs two containers from one image:

- `youtube_hate_detector-api` — uvicorn port 8000
- `youtube_hate_detector-streamlit` — port 8501

Both include `final_model.joblib`, configs, spaCy, and NLTK data baked into the image.

## Tests

[`tests/`](../tests/) — preprocessor, vectorizer, model binary outputs, `/predict` schema (mocked service).