# massebaa35/document_classifier architecture

> Architecture diagram of the GitHub repository massebaa35/document_classifier, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-06-02). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/massebaa35/document_classifier
- Repository: https://github.com/massebaa35/document_classifier

## Overview

1. **Repository shape**
   - This repo is a single, self-contained Python text-classification prototype.
   - There are no packages, services, APIs, databases, or deployment artifacts; the entire architecture lives in one training script shown in the README.

2. **Primary purpose**
   - The system trains a document classifier that assigns one of three classes: **Billing**, **Technology**, or **Sports**.
   - It is designed as a small supervised learning workflow rather than a production application.

3. **Input layer: in-memory corpus**
   - The training data is hard-coded as a list of short documents.
   - Each class has 15 documents, giving a balanced 45-sample dataset.
   - This is the only data source, so the architecture has no external ingestion boundary.

4. **Labeling and class schema**
   - Labels are generated programmatically to match the three document groups.
   - The classifier’s output space is fixed and closed: exactly those three categories.
   - The label distribution is intentionally balanced to support fair model evaluation.

5. **Dataset partitioning**
   - The data is split into training and test subsets using `train_test_split`.
   - `stratify=labels` preserves class proportions across splits, which is important because the dataset is small.
   - With `test_size=0.33`, the test set contains 5 samples per class, making evaluation class-complete but still lightweight.

6. **Feature extraction boundary**
   - Text is converted into numeric features by `TfidfVectorizer`.
   - Important configuration choices:
     - English stop-word removal
     - Lowercasing normalization
     - Unigram and bigram features (`ngram_range=(1, 2)`)
   - This is the main transformation boundary: raw text in, sparse TF-IDF matrix out.

7. **Modeling layer**
   - The classifier is `MultinomialNB` with `alpha=0.1`.
   - This is a classic bag-of-words style model that pairs naturally with TF-IDF features.
   - The lower smoothing value indicates the model is tuned to emphasize discriminative rare terms.

8. **Pipeline composition**
   - `make_pipeline` connects vectorization and classification into one sequential ML pipeline.
   - The pipeline ensures training and prediction use the exact same preprocessing steps.
   - This creates a clean boundary between text normalization/feature engineering and probabilistic classification.

9. **Training and inference flow**
   - Training happens on `X_train` and `y_train` through `fit`.
   - Prediction runs on `X_test` through `predict`.
   - The flow is strictly linear: documents → TF-IDF features → Naive Bayes model → predicted labels.

10. **Evaluation subsystem**
   - Model quality is measured with `accuracy_score` and `classification_report`.
   - The report provides precision, recall, and F1-score per class.
   - `zero_division=0` prevents metric failures if a class is never predicted.

11. **Output and diagnostics**
   - The script prints a single accuracy value and a formatted classification report.
   - Warnings for undefined metrics are suppressed to keep output clean.
   - There is no logging, visualization, or artifact export.

12. **Architectural constraints**
   - The repository does not include persistence of the trained model, hyperparameter search, cross-validation, or a prediction endpoint.
   - It is best understood as a minimal, reproducible ML experiment: a small labeled corpus, one preprocessing pipeline, one classifier, and local evaluation.

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_data["Data prep"]
  node_corpus["Corpus<br/>in-memory text set"]
  node_labels(("Labels<br/>class targets"))
  node_split["Train/Test<br/>stratified split"]
end

subgraph group_ml["Modeling"]
  node_vectorizer["TF-IDF<br/>feature extraction"]
  node_pipeline["Pipeline"]
  node_nb{{"Naive Bayes<br/>classifier"}}
  node_fit(("Train<br/>fitting step"))
  node_predict(("Predict<br/>inference step"))
  node_accuracy(("Accuracy<br/>metric"))
  node_report["Report<br/>classification metrics"]
  node_output["Console<br/>stdout output"]
end

node_corpus -->|"documents"| node_split
node_labels -->|"targets"| node_split
node_split -->|"train text"| node_vectorizer
node_vectorizer -->|"features"| node_pipeline
node_pipeline -->|"contains"| node_nb
node_split -->|"X_train/y_train"| node_fit
node_fit -->|"train model"| node_pipeline
node_split -->|"X_test"| node_predict
node_pipeline -->|"inference"| node_predict
node_predict -->|"predictions"| node_accuracy
node_predict -->|"predictions"| node_report
node_accuracy -->|"print"| node_output
node_report -->|"print"| node_output

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_corpus,node_labels,node_split toneBlue
class node_vectorizer,node_pipeline,node_nb,node_fit,node_predict,node_accuracy,node_report,node_output toneAmber
```

## Components

### Data prep

In-memory corpus, labels, and dataset split.

- **Corpus**: in-memory text set · Hard-coded documents for three balanced classes.
- **Labels**: class targets · Programmatically generated targets for Billing, Technology, and Sports.
- **Train/Test**: stratified split · Partitions the corpus with class balance preserved.

### Modeling

Feature extraction, classifier, training, and evaluation.

- **TF-IDF**: feature extraction · Lowercases, removes English stop words, and builds unigram/bigram TF-IDF features.
- **Pipeline**: ml pipeline · Connects vectorization and classification into one sequential workflow.
- **Naive Bayes**: classifier · MultinomialNB with alpha=0.1 for sparse text features.
- **Train**: fitting step · Fits the pipeline on the training subset.
- **Predict**: inference step · Generates labels for the held-out test documents.
- **Accuracy**: metric · Single-score evaluation of test predictions.
- **Report**: classification metrics · Precision, recall, and F1 by class with zero-division handling.
- **Console**: stdout output · Prints the accuracy value and formatted classification report.

## Connections

- Corpus → Train/Test: documents · Hard-coded text samples are partitioned for evaluation.
- Labels → Train/Test: targets · Class labels are split alongside the documents.
- Train/Test → TF-IDF: train text · Training documents are transformed into numeric features.
- TF-IDF → Pipeline: features · TF-IDF representation feeds the sequential pipeline.
- Pipeline → Naive Bayes: contains · The pipeline wraps the classifier after preprocessing.
- Train/Test → Train: X_train/y_train · Training subset is used to fit the model.
- Train → Pipeline: train model · Pipeline training applies the same preprocessing and classifier fitting.
- Train/Test → Predict: X_test · Held-out documents are passed to prediction.
- Pipeline → Predict: inference · Trained pipeline produces predicted labels.
- Predict → Accuracy: predictions · Predicted labels are scored against ground truth.
- Predict → Report: predictions · Predictions are summarized per class.
- Accuracy → Console: print · Accuracy is emitted to the console.
- Report → Console: print · Classification report is emitted to the console.
