How massebaa35/document_classifier works
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.
Components 11
Data prep
In-memory corpus, labels, and dataset split.
- Corpus · Hard-coded documents for three balanced classes.
- Labels · Programmatically generated targets for Billing, Technology, and Sports.
- Train/Test · Partitions the corpus with class balance preserved.
Modeling
Feature extraction, classifier, training, and evaluation.
- TF-IDF · Lowercases, removes English stop words, and builds unigram/bigram TF-IDF features.
- Pipeline · Connects vectorization and classification into one sequential workflow.
- Naive Bayes · MultinomialNB with alpha=0.1 for sparse text features.
- Train · Fits the pipeline on the training subset.
- Predict · Generates labels for the held-out test documents.
- Accuracy · Single-score evaluation of test predictions.
- Report · Precision, recall, and F1 by class with zero-division handling.
- Console · Prints the accuracy value and formatted classification report.
Connections 13
- 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.