Spaces:
Sleeping
Sleeping
File size: 8,662 Bytes
ada7257 2f74c56 | 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 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 | ---
title: Retail Food Freshness Classifier
emoji: 🥗
colorFrom: green
colorTo: blue
sdk: streamlit
sdk_version: 1.47.0
app_file: src/campus_triage/app.py
pinned: false
---
# Campus Support Message Triage Assistant
Campus Support Message Triage Assistant is a complete NLP module project that classifies synthetic student support messages by support category and urgency. The system is designed to help a university support office route messages faster while keeping human review in the loop.
## Novelty Statement
This repository uses a new synthetic dataset created specifically for this project. It does not reuse prior coursework, public student support datasets, or real student records.
## Data Source
The dataset is generated by `src/campus_triage/data.py`. It creates at least 1,500 realistic but synthetic messages with `message_id`, `message_text`, `category`, `urgency`, `channel`, `student_type`, and `created_hour`. The generator intentionally includes typos, informal language, short requests, longer emails, urgent wording, and ambiguous messages.
Saved files:
- `data/raw/campus_support_messages.csv`
- `data/processed/train.csv`
- `data/processed/val.csv`
- `data/processed/test.csv`
## Categories and Urgency Labels
Categories: `financial_aid`, `registration`, `housing`, `academic_advising`, `technical_support`, `health_wellness`, `general`
Urgency: `low`, `medium`, `high`
## Setup
```bash
python -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
pip install -e .
```
The Makefile also sets `PYTHONPATH=src`, so the main workflow works without editable install.
## Generate Data
```bash
make data
```
Optional custom size:
```bash
PYTHONPATH=src python scripts/make_dataset.py --rows 1800
```
## Modeling Strategies
All three required modeling strategies are implemented in the repository.
| Strategy | What it does | Where it is implemented | Training artifact | Command |
| --- | --- | --- | --- | --- |
| A. Naive baseline | Majority-class classifier for category and urgency | `build_baseline_model()` in `src/campus_triage/models.py`; trained by `train_baseline()` in `src/campus_triage/train.py` | `models/majority_baseline.joblib` | `make train` |
| B. Classical ML | TF-IDF vectorizer plus Logistic Regression, with separate category and urgency classifiers | `build_text_pipeline()` and `build_classical_model()` in `src/campus_triage/models.py`; trained by `train_classical()` in `src/campus_triage/train.py` | `models/tfidf_logistic_regression.joblib` | `make train` |
| C. Deep learning | DistilBERT sequence classification, with separate category and urgency transformer models | `src/campus_triage/transformer_training.py`; loaded for evaluation by `TransformerTextClassifier` and `load_transformer_dual_classifier()` in `src/campus_triage/models.py` | `models/transformer/category/` and `models/transformer/urgency/` | `make train-transformer` |
The deployed app uses the TF-IDF Logistic Regression model by default because it is fast, small, free-deployment friendly, and appropriate for a student-laptop proof of concept. The deep learning implementation is included and can be trained when hardware/time allow.
## Train Models
Train the baseline and classical models:
```bash
make train
```
Train the optional DistilBERT deep learning model:
```bash
make train-transformer
```
Equivalent direct command:
```bash
PYTHONPATH=src python scripts/train_all_models.py --include-transformer
```
`make train-transformer` downloads `distilbert-base-uncased` from Hugging Face if it is not already cached, so it requires internet access the first time.
## Run Evaluation
```bash
make evaluate
```
Evaluation always includes the baseline and classical models. If trained transformer checkpoints exist in `models/transformer/category/` and `models/transformer/urgency/`, evaluation automatically includes the deep learning model as `distilbert_transformer`.
Outputs:
- `data/outputs/model_comparison.csv`
- `data/outputs/category_confusion_matrix.png`
- `data/outputs/urgency_confusion_matrix.png`
- `data/outputs/classification_reports.txt`
- `data/outputs/error_analysis.csv`
Macro F1 is important because routing classes may be imbalanced. Accuracy can look strong while hiding poor performance on smaller but important classes such as `health_wellness` or `high` urgency. Macro F1 gives each class equal weight, which makes minority urgent cases visible.
## Robustness Experiment
```bash
make experiment
```
The experiment creates a noisy test condition with random character deletion, random typos, lowercasing, extra punctuation, and missing punctuation. It compares clean versus noisy performance for the classical model. If transformer checkpoints exist, it also compares the deep learning model on clean versus noisy test data.
Outputs:
- `data/outputs/robustness_experiment.csv`
- `data/outputs/robustness_plot.png`
Interpretation guidance: transformer models often have better semantic robustness than sparse TF-IDF models, but the project conclusion should be based on the saved clean/noisy macro F1 values after `make train-transformer` is run.
## Launch the App
```bash
make app
```
Equivalent:
```bash
streamlit run main.py
```
The app runs inference only. It lets a user paste a student message, returns category and urgency predictions, shows confidence scores, recommends a routing action, provides a keyword or confidence explanation, includes example messages, and displays proof-of-concept limitations.
## Repository Structure
```text
README.md
requirements.txt
Makefile
setup.py
main.py
.gitignore
src/campus_triage/
__init__.py
config.py
data.py
features.py
models.py
train.py
evaluate.py
experiment.py
predict.py
app.py
transformer_training.py
scripts/
make_dataset.py
train_all_models.py
run_experiment.py
models/
data/
raw/
processed/
outputs/
notebooks/
```
## Metrics
Category and urgency are evaluated with accuracy, macro F1, weighted F1, per-class precision, recall, F1, and confusion matrices.
## Hyperparameter Tuning
Classical model hyperparameters are in `build_text_pipeline()` in `src/campus_triage/models.py`. Tune `ngram_range`, `min_df`, `max_features`, `sublinear_tf`, `max_iter`, `class_weight`, and `C`.
Transformer hyperparameters are in `src/campus_triage/transformer_training.py`. Tune `num_train_epochs`, `per_device_train_batch_size`, `per_device_eval_batch_size`, `learning_rate`, and tokenizer `max_length`.
After tuning, rerun:
```bash
make train
make evaluate
make experiment
```
## Error Analysis
`make evaluate` creates `data/outputs/error_analysis.csv` with five mispredictions from the best evaluated model, including message text, true labels, predicted labels, likely root cause, and a concrete mitigation strategy.
## Ethical Considerations
This system should assist, not replace, student support staff. Synthetic data cannot represent all student populations, dialects, disability contexts, crisis language, or institutional policies. High-urgency and health/wellness messages require conservative escalation and human review. Real deployment would require privacy review, bias testing, accessibility review, incident response procedures, and staff training.
## Limitations
- Synthetic training data may overstate real-world performance.
- Confidence scores are model probabilities, not guarantees.
- The app does not integrate with official student systems.
- Transformer training is optional and may need hardware beyond a small laptop.
- The model should not be used for disciplinary, medical, or emergency decisions without human review.
## Future Work
- Add institution-specific labeled examples after privacy review.
- Add calibrated confidence thresholds and manual review queues.
- Evaluate fairness across student type, channel, and language variety.
- Add multilingual message handling.
- Deploy with authentication and audit logging.
- Compare trained transformer checkpoints against the classical model on noisy data.
# External Code Attribution
This project includes code written by the author as well as AI-assisted code generation and publicly available libraries.
### AI Assistance
Portions of this project were developed with assistance from OpenAI ChatGPT (GPT-5.5).
OpenAI ChatGPT:
https://chatgpt.com/
AI assistance included (but was not limited to):
- project architecture suggestions
- code generation
- code refactoring
- debugging
- documentation
- README generation
- evaluation report drafting
- comments and explanations
All AI-generated code was reviewed, tested, and modified by the project author before submission.
|