This repository contains the codebase for the Document Categorization and Tagging project. The goal is to build an automated pipeline that can ingest documents, clean and preprocess them across multiple languages, extract meaningful features, and tag/categorize them into target categories (e.g., Technology, Finance, Sports).
document-categorization/
├── .gitignore # Excludes environments, IDE configs, and caching noise
├── README.md # Project overview, installation, and run guide
├── requirements.txt # Project requirements and packages
├── run_pipeline.py # Phase 2 pipeline runner (Cleaning & NER Tagging)
├── audit.md # populated self-audit checklists showing demonstration checks
├── app/
│ ├── __init__.py # Web App package constructor
│ └── real_time_dashboard.py # Streamlit visualization & telemetry dashboard (Phase 5)
├── models/
│ ├── __init__.py # Models package constructor
│ ├── tagger.py # Context-aware tagger (NER + rule-based)
│ ├── text_classifier.py # Fine-tunable DistilBERT classifier (Phase 3)
│ └── baseline_classifier.py # Traditional TF-IDF + LogisticRegression baseline (Phase 1 Expansion)
├── notebooks/
│ └── EDA_and_Training.ipynb # Jupyter Notebook detailing data loader EDA and training steps
├── reports/
│ └── performance_metrics.json # Production KPIs (classification accuracy, latency, and speed)
└── utils/
├── __init__.py # Utils package constructor
├── data_loader.py # Multi-language thematic news dataset loader (Phase 1 Expansion)
├── pipeline_engine.py # Unified integration & batch processing engine (Phase 4)
├── text_preprocessing.py # Multi-language text cleaning, language detection & tokenization
└── transfer_learning.py # DistilBERT tokenization & label encoding helpers
Lists dependencies required for processing, feature engineering, and modeling, including:
pandas&numpyfor data manipulation.scikit-learn&tensorflowfor modeling.langdetectfor automatic language identification.spacyfor language-appropriate tokenization and NLP preprocessing.beautifulsoup4for HTML stripping.transformers(pinned to<5.0.0for TensorFlow modeling compatibility) &tf-keras(backward compatibility helper for Keras 3).streamlitfor the visualization dashboard UI.datasets(pinned to<4.0.0to preserve Hugging Face loading script capabilities).
Provides two core data loading routines:
load_mock_data(): Generates a simulated dataset with documents across English and Spanish containing raw noise such as HTML markup, excess whitespace, symbols, and mixed casing.load_production_dataset(sample_size): Loads the English and Spanish splits of Hugging Face'sburuzaemon/amazon_reviews_multiand dynamically maps their product categories to the 5 target thematic domains (Finance, General, Noise, Sports, and Technology), while generating synthetic balanced noise samples to avoid model memorization.
Features a modular TextPreprocessor class that executes HTML cleaning, hashtag removal, emoji/symbol filtering, punctuation normalization, language detection, and dynamic SpaCy loading.
Provides a traditional ML baseline pipeline:
- Loads 10,000 balanced, multi-lingual thematic news documents across 5 target categories (Finance, General, Noise, Sports, Technology).
- Cleans review text using the preprocessor.
- Splits the clean data into an 80/20 train/test split.
- Generates features using scikit-learn's
TfidfVectorizer(unigrams and bigrams, up to 10,000 features). - Trains a multi-class
LogisticRegressionmodel. - Prints testing evaluation metrics (Accuracy, Macro F1-score, and full classification report) and benchmarks documents processing speed.
Implements a hybrid context-aware tagger (DocumentTagger class) combining ML-based NER and rule-based keyword matching.
Provides the Phase 3 deep learning sequence classification model fine-tuning TFDistilBertForSequenceClassification mapping categories to the 5 target business domains.
Provides the Phase 4 unified integration and batch-processing optimization engine.
Provides the Phase 5 interactive Streamlit dashboard.
reports/performance_metrics.json: Piles model accuracy, macro F1, and throughput benchmarks.audit.md: Self-contained audit answer checks detailing operational demonstration steps.notebooks/EDA_and_Training.ipynb: Jupyter Notebook documenting exploratory analyses, preprocessing splits, and transfer learning fine-tuning.
- Python 3.8 or higher is recommended (verified on Python 3.11).
-
Clone or navigate to the project directory:
cd /Users/inka.saavuori/document-categorization -
Create a virtual environment:
python3 -m venv venv
-
Activate the virtual environment:
- On macOS/Linux:
source venv/bin/activate - On Windows:
venv\Scripts\activate
- On macOS/Linux:
-
Install dependencies:
pip install -r requirements.txt
python run_pipeline.pyPYTHONPATH=. python models/baseline_classifier.pyPYTHONPATH=. python models/text_classifier.py --sample_size 10000 --epochs 10 --batch_size 32This runs compiled graph execution with tf.data.Dataset pipelines, integrates EarlyStopping callbacks, and automatically exports training curves to reports/learning_curves.png.
PYTHONPATH=. python utils/pipeline_engine.pystreamlit run app/real_time_dashboard.py --server.port 8505Open your browser and navigate to http://localhost:8505 to view the dashboard interface.