TicketLens
Ticket classifier benchmarked across three model families
ITIL ticket classifier comparing TF-IDF + Logistic Regression, a Keras CNN and DistilBERT + LoRA on one held-out set; serves the TF-IDF model via FastAPI with PII scrubbing and confidence-gated routing.

The problem
Routing IT tickets by ITIL category from free text is ambiguous, the classes are imbalanced, and tickets can contain personal data.
The approach
Trains TF-IDF + Logistic Regression, a Keras CNN and DistilBERT + LoRA on the same data and scores them on one held-out set, then serves the winning TF-IDF model through FastAPI with PII scrubbing and confidence-gated human review.
Architecture
- 01
Ingestion and governance
Downloads the Tobi-Bueck/customer-support-tickets dataset from Hugging Face, keeps English tickets, regex-redacts emails, phone numbers and IPs, de-duplicates on text and makes one stratified 70/15/15 split with a fixed seed.
- 02
Three model families
TF-IDF + Logistic Regression (scikit-learn), a Keras CNN (TextVectorization, Embedding, Conv1D) and DistilBERT fine-tuned with LoRA via PEFT, all trained on the same training subset.
- 03
Shared evaluation and audit
Every model is scored on the same held-out test tickets for macro-F1, per-class precision and recall and confusion matrices, plus error analysis, SHAP LinearExplainer attributions and a bias check by class balance and ticket length.
- 04
Inference service
A FastAPI /predict endpoint applies PII scrubbing, optional ITIL keyword cues, non-English detection and a 0.80 confidence gate, then attaches a resolver queue from configs/routing.yaml.
- 05
Packaging
A lightweight TF-IDF image matches the Render free-plan deployment; a separate DistilBERT + LoRA image downloads the adapter from the GitHub release produced by the benchmark workflow.
Key decisions
- Trains the three architectures on the same 7,000-ticket subset and scores them on the identical test split; the subset size is set by the CPU budget for fine-tuning DistilBERT, which limits how far the transformer result can be read.
- Serves TF-IDF + Logistic Regression rather than the transformer: it had the highest macro-F1 of the three on the shared test set and fits Render's 512 MB free plan, while the DistilBERT container needs about 430 MB at idle and ships as a separate image.
- Adds an ITIL keyword-cue layer on the served model that lowers macro-F1 slightly on the in-distribution test split but raises accuracy on a small hand-written holdout; it can be turned off with inference.itil_cue_weight: 0.
- Gates auto-routing at 0.80 confidence and forces Needs Review for low-confidence or non-English tickets, trading auto-routing coverage for precision on the tickets that are routed automatically.
- Uses a LoRA adapter on the attention q/v projections only (r=8) after an all-linear-layer variant with a class-balanced loss overfit after the first epoch.
- Runs the Render build's download, corpus preparation and training as separate processes to keep peak memory low, and fails the build if the dataset cannot be downloaded instead of training on the test fixture.
Results
- TF-IDF + Logistic Regression beat both the Keras CNN and DistilBERT + LoRA on macro-F1 on the shared test set; the transformer ranked last there.
- On the small hand-written holdout the ranking reverses and DistilBERT transfers best, which the README labels as indicative only.
- Incident versus Problem confusion accounts for most errors for every model, and SHAP shows the two classes share top terms such as 'problem' and 'issue'.
- At the confidence threshold, auto-accepted tickets are more precise than overall accuracy, so ambiguous tickets go to human review.
| Metric | Value | Source |
|---|---|---|
| TF-IDF + LR macro-F1 | 0.8352 | reports/model_comparison.json |
| DistilBERT + LoRA macro-F1 | 0.7790 | reports/model_comparison.json |
| Keras CNN macro-F1 | 0.8095 | reports/model_comparison.json |
| Served TF-IDF macro-F1 (full train split) | 0.8782 | reports/model_comparison.json |
How it is tested
- 50 pytest test functions (the README reports 66 tests) covering text cleaning, PII redaction, schema and leakage checks, API health, auth, validation and prediction, ITIL cues, language detection and the fixed benchmark split.
- CI replays the Render build on Python 3.11 with serving-only dependencies, asserts the heavy ML stack is not installed, fails if any build step exceeds 512 MB, then runs the tests, boots the server, smoke-tests /health and /predict and fails if its RSS reaches 400 MB.
- CI also builds both Docker images and checks that the transformer image serves the fine-tuned model.
- A manually triggered benchmark workflow trains all models on CPU, evaluates them on the shared test set, runs SHAP and the bias audit and the full test suite, and publishes the models as a GitHub release.
Limits, stated plainly
- The dataset is CC BY-NC 4.0 (non-commercial), its tickets have a long-form synthetic style, and the README notes its Incident and Problem labels are applied inconsistently.
- The three-way comparison uses a 7,000-ticket CPU-budget subset; the hand-written evaluation sets are small.
- The served model's higher macro-F1 comes from training on the full training split with augmentation, so it is not a like-for-like comparison with the three-way benchmark.
- Latency figures were measured on a shared GitHub runner and are only relative, and the PII scrubbing covers emails, phone numbers and IP addresses only.
- The bias check covers class balance and ticket length, not other attributes.