加载中…
加载中…
A fine-tuned sentence-transformers/all-MiniLM-L6-v2 model that classifies raw bank transaction strings into 10 budget categories. Trained on metadata-enriched transaction descriptions using merchant knowledge from the Foursquare OS Places dataset.
This is the 7th and current best iteration in a progressive model development series for real-world Canadian bank transaction classification.
| Property | Value |
|---|---|
| Base model | sentence-transformers/all-MiniLM-L6-v2 (22M params) |
| Task | Multi-class text classification (10 categories) |
| Training samples | 55,750 (metadata-enriched) |
| Epochs | 2 |
| Batch size | 64 |
| Learning rate | 5e-6 |
| Max sequence length | 96 tokens |
| Format | SafeTensors |
| Trained | 2026-04-06 |
| ID | Category |
|---|---|
| 0 | Food & Dining |
| 1 | Transportation |
| 2 | Shopping & Retail |
| 3 | Entertainment & Recreation |
| 4 | Healthcare & Medical |
| 5 | Utilities & Services |
| 6 | Financial Services |
| 7 | Income |
| 8 | Government & Legal |
| 9 | Charity & Donations |
Evaluated on 505 unique real-world RBC (Royal Bank of Canada) transactions (3,113 weighted by occurrence frequency, spanning 2019-2026).
| Metric | Score |
|---|---|
| Real-world accuracy (weighted) | 83.6% |
| Real-world accuracy (unique) | 73.9% |
| ML-only accuracy | 77.1% |
| Validation accuracy | 93.0% |
| Category | Accuracy |
|---|---|
| Income | 100.0% |
| Healthcare & Medical | 100.0% |
| Financial Services | 94.7% |
| Food & Dining | 89.3% |
| Entertainment & Recreation | 88.6% |
| Transportation | 83.3% |
| Shopping & Retail | 78.9% |
| Utilities & Services | 68.4% |
| Government & Legal | 54.5% |
| Charity & Donations | 0.0% |
from transformers import AutoTokenizer, AutoModelForSequenceClassification
import torch
model_name = "maaz-zaidi/transaction-classifier-minilm-en-ca"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForSequenceClassification.from_pretrained(model_name)
categories = [
"Food & Dining", "Transportation", "Shopping & Retail",
"Entertainment & Recreation", "Healthcare & Medical",
"Utilities & Services", "Financial Services", "Income",
"Government & Legal", "Charity & Donations"
]
text = "MCDONALD'S #12345 TORONTO ON"
inputs = tokenizer(text, return_tensors="pt", truncation=True, max_length=96)
with torch.no_grad():
logits = model(**inputs).logits
predicted = torch.argmax(logits, dim=-1).item()
print(f"Category: {categories[predicted]}")
# Output: Category: Food & Dining
This model is designed as the ML component of a multi-stage classification pipeline:
The model performs best when transaction descriptions are enriched with merchant category metadata from the knowledge base before classification. Without enrichment, standalone accuracy is lower.
A comprehensive PDF report covering the full research journey, architecture decisions, evaluation methodology, and results across all 7 phases is included in this repository: Transaction_Classifier_Report.pdf
This model was trained on transaction strings enriched with merchant place-type metadata. During training, raw transaction text like "MCDONALD'S #12345" was augmented to "MCDONALD'S #12345 [restaurant, fast_food]" using category information from the Foursquare OS Places dataset. This teaches the model to leverage semantic merchant-type signals when available, while still functioning on raw text alone.
This model is part of a 7-version development series. All versions are available in the Transaction Classifier collection.
| Version | Model | Real Accuracy | Key Change |
|---|---|---|---|
| v1 | SGD | 53.7% | TF-IDF baseline |
| v2 | FastText | 55.7% | Subword embeddings |
| v3 | SetFit | 80.5% | Contrastive learning |
| v4 | Fine-tuned MiniLM | 86.5% | Cross-entropy fine-tuning |
| v5 | Augmented MiniLM | - | Data augmentation (experiment) |
| v6 | CANINE | - | Character-level (experiment) |
| v7 | Enriched MiniLM (this model) | 83.6% | Metadata enrichment |
Note: v4 achieved 86.5% after preprocessing fixes specific to the evaluation pipeline (Phase 4b). The enriched model (v7) achieves the best ML-only accuracy at 77.1% and is the production model.
The full pipeline source code (rules engine, merchant knowledge base, retrieval, API) is available at: github.com/maaz-zaidi/transaction-classifier
@misc{zaidi2026txnclassifier,
title={Transaction Classifier: Multi-Stage Bank Transaction Categorization},
author={Maaz Zaidi},
year={2026},
url={https://huggingface.co/maaz-zaidi/transaction-classifier-minilm-en-ca}
}