Transaction Classifier — Enriched MiniLM (v7)

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.

Model Details

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

Categories

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

Performance

Evaluated on 505 unique real-world RBC (Royal Bank of Canada) transactions (3,113 weighted by occurrence frequency, spanning 2019-2026).

Overall

Metric Score
Real-world accuracy (weighted) 83.6%
Real-world accuracy (unique) 73.9%
ML-only accuracy 77.1%
Validation accuracy 93.0%

Per-Category Accuracy

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%

Usage

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

Training Data

Full Pipeline Context

This model is designed as the ML component of a multi-stage classification pipeline:

  1. Direction Detection (rules) - identifies credits vs debits (100% accuracy)
  2. Rules Engine - YAML-based pattern matching for structural patterns (92.3%)
  3. Merchant Knowledge Base - dense retrieval + cross-encoder reranking against 1.8M Canadian merchants (94.3%)
  4. ML Ensemble - this model (77.1% standalone, 83.6% with KB metadata enrichment)

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.

Full Report

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

What is Metadata Enrichment?

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.

Model Evolution

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.

Limitations

  • Charity & Donations: 0% accuracy - insufficient training examples
  • Government & Legal: 54.5% - often confused with Financial Services
  • Domain specificity: Trained on Canadian banking transaction formats; may not generalize to other regions
  • Standalone vs pipeline: Best results require the full pipeline (knowledge base + rules); the model alone achieves 77.1%
  • Training data gap: Trained on synthetic data, evaluated on real bank statements - domain shift is the primary challenge

Source Code

The full pipeline source code (rules engine, merchant knowledge base, retrieval, API) is available at: github.com/maaz-zaidi/transaction-classifier

Citation

@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}
}
Downloads last month
59
Safetensors
Model size
22.7M params
Tensor type
F32
·
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support

Model tree for maaz-zaidi/transaction-classifier-minilm-en-ca

Dataset used to train maaz-zaidi/transaction-classifier-minilm-en-ca

Collection including maaz-zaidi/transaction-classifier-minilm-en-ca

Evaluation results