Text Classification
fastText
English
transaction-classification
banking
finance
subword-embeddings
Eval Results (legacy)
Instructions to use maaz-zaidi/transaction-classifier-fasttext with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- fastText
How to use maaz-zaidi/transaction-classifier-fasttext with fastText:
from huggingface_hub import hf_hub_download import fasttext model = fasttext.load_model(hf_hub_download("maaz-zaidi/transaction-classifier-fasttext", "model.bin")) - Notebooks
- Google Colab
- Kaggle
fasttext upload
Browse files- README.md +135 -3
- fasttext_model.bin +3 -0
- metadata.json +13 -0
README.md
CHANGED
|
@@ -1,3 +1,135 @@
|
|
| 1 |
-
---
|
| 2 |
-
|
| 3 |
-
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
language: en
|
| 3 |
+
license: apache-2.0
|
| 4 |
+
tags:
|
| 5 |
+
- text-classification
|
| 6 |
+
- transaction-classification
|
| 7 |
+
- banking
|
| 8 |
+
- finance
|
| 9 |
+
- fasttext
|
| 10 |
+
- subword-embeddings
|
| 11 |
+
datasets:
|
| 12 |
+
- mitulshah/transaction-categorization
|
| 13 |
+
pipeline_tag: text-classification
|
| 14 |
+
model-index:
|
| 15 |
+
- name: transaction-classifier-fasttext
|
| 16 |
+
results:
|
| 17 |
+
- task:
|
| 18 |
+
type: text-classification
|
| 19 |
+
name: Transaction Classification
|
| 20 |
+
metrics:
|
| 21 |
+
- name: Real-World Accuracy (Weighted)
|
| 22 |
+
type: accuracy
|
| 23 |
+
value: 0.557
|
| 24 |
+
- name: FastText-Only Accuracy
|
| 25 |
+
type: accuracy
|
| 26 |
+
value: 0.148
|
| 27 |
+
- name: Validation Accuracy
|
| 28 |
+
type: accuracy
|
| 29 |
+
value: 0.99
|
| 30 |
+
---
|
| 31 |
+
|
| 32 |
+
# Transaction Classifier — FastText (v2)
|
| 33 |
+
|
| 34 |
+
A [FastText](https://fasttext.cc/) supervised model that classifies bank transaction strings into 10 budget categories using subword embeddings.
|
| 35 |
+
|
| 36 |
+
This is **version 2** (Phase 2) in a progressive model development series. It introduced direction detection (credit vs debit) and a rules engine, but the FastText ML component itself suffered from severe Income category bias.
|
| 37 |
+
|
| 38 |
+
## Model Details
|
| 39 |
+
|
| 40 |
+
| Property | Value |
|
| 41 |
+
|---|---|
|
| 42 |
+
| Architecture | FastText supervised (subword n-grams) |
|
| 43 |
+
| Task | Multi-class text classification (10 categories) |
|
| 44 |
+
| Training samples | 3,597,859 |
|
| 45 |
+
| Epochs | 10 |
|
| 46 |
+
| Learning rate | 0.5 |
|
| 47 |
+
| Word n-grams | 2 |
|
| 48 |
+
| Embedding dim | 100 |
|
| 49 |
+
| Subword range | 3-6 characters |
|
| 50 |
+
| Loss | Softmax |
|
| 51 |
+
| Format | `.bin` (FastText binary) |
|
| 52 |
+
| Trained | 2026-03-28 |
|
| 53 |
+
|
| 54 |
+
## Categories
|
| 55 |
+
|
| 56 |
+
| ID | Category |
|
| 57 |
+
|---|---|
|
| 58 |
+
| 0 | Food & Dining |
|
| 59 |
+
| 1 | Transportation |
|
| 60 |
+
| 2 | Shopping & Retail |
|
| 61 |
+
| 3 | Entertainment & Recreation |
|
| 62 |
+
| 4 | Healthcare & Medical |
|
| 63 |
+
| 5 | Utilities & Services |
|
| 64 |
+
| 6 | Financial Services |
|
| 65 |
+
| 7 | Income |
|
| 66 |
+
| 8 | Government & Legal |
|
| 67 |
+
| 9 | Charity & Donations |
|
| 68 |
+
|
| 69 |
+
## Performance
|
| 70 |
+
|
| 71 |
+
Evaluated on 505 unique real-world RBC transactions (3,113 weighted, 2019-2026).
|
| 72 |
+
|
| 73 |
+
| Metric | Score |
|
| 74 |
+
|---|---|
|
| 75 |
+
| Real-world accuracy (weighted) | **55.7%** |
|
| 76 |
+
| FastText-only accuracy | **14.8%** |
|
| 77 |
+
| Direction detection accuracy | 100.0% |
|
| 78 |
+
| Rules accuracy | 91.3% |
|
| 79 |
+
| Validation accuracy | 99.0% |
|
| 80 |
+
|
| 81 |
+
> **Key finding**: FastText achieves only 14.8% on unknown merchants due to subword n-gram overlap between the Income category in the training data and real merchant names. The model defaults to predicting Income for most inputs.
|
| 82 |
+
|
| 83 |
+
## Usage
|
| 84 |
+
|
| 85 |
+
```python
|
| 86 |
+
import fasttext
|
| 87 |
+
|
| 88 |
+
model = fasttext.load_model("fasttext_model.bin")
|
| 89 |
+
|
| 90 |
+
result = model.predict("MCDONALD'S #12345 TORONTO ON")
|
| 91 |
+
label = result[0][0].replace("__label__", "")
|
| 92 |
+
confidence = result[1][0]
|
| 93 |
+
|
| 94 |
+
print(f"Category: {label}, Confidence: {confidence:.3f}")
|
| 95 |
+
```
|
| 96 |
+
|
| 97 |
+
### Dependencies
|
| 98 |
+
|
| 99 |
+
```
|
| 100 |
+
fasttext
|
| 101 |
+
```
|
| 102 |
+
|
| 103 |
+
## Training Data
|
| 104 |
+
|
| 105 |
+
- **Primary**: [mitulshah/transaction-categorization](https://huggingface.co/datasets/mitulshah/transaction-categorization) - full 3.6M records (gated dataset)
|
| 106 |
+
- **Evaluation**: 505 real-world RBC bank transactions (2019-2026)
|
| 107 |
+
|
| 108 |
+
## Key Contributions
|
| 109 |
+
|
| 110 |
+
Despite the weak ML component, Phase 2 introduced two critical pipeline stages:
|
| 111 |
+
1. **Direction Detection**: Rule-based credit/debit detection achieving 100% accuracy
|
| 112 |
+
2. **Rules Engine**: YAML-based pattern matching for structural transaction patterns (91.3% accuracy on matched transactions)
|
| 113 |
+
|
| 114 |
+
These pipeline stages carried forward into all subsequent versions.
|
| 115 |
+
|
| 116 |
+
## Part of a Series
|
| 117 |
+
|
| 118 |
+
See the [Transaction Classifier collection](https://huggingface.co/collections/maaz-zaidi/transaction-classifier) for all 7 model versions.
|
| 119 |
+
|
| 120 |
+
## Limitations
|
| 121 |
+
|
| 122 |
+
- Severe Income category bias (14.8% ML-only accuracy)
|
| 123 |
+
- Subword n-gram features from Income training examples overlap with real merchant names
|
| 124 |
+
- Superseded by SetFit (v3) which achieved 66.7% ML-only accuracy using pre-trained embeddings
|
| 125 |
+
|
| 126 |
+
## Citation
|
| 127 |
+
|
| 128 |
+
```bibtex
|
| 129 |
+
@misc{zaidi2026txnclassifier,
|
| 130 |
+
title={Transaction Classifier: Multi-Stage Bank Transaction Categorization},
|
| 131 |
+
author={Maaz Zaidi},
|
| 132 |
+
year={2026},
|
| 133 |
+
url={https://huggingface.co/maaz-zaidi/transaction-classifier-fasttext}
|
| 134 |
+
}
|
| 135 |
+
```
|
fasttext_model.bin
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:37a4f623d92dbb89ec9bd52c66090839ee1460e028588a46766a957c361b29fe
|
| 3 |
+
size 168572253
|
metadata.json
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"epoch": 10,
|
| 3 |
+
"lr": 0.5,
|
| 4 |
+
"word_ngrams": 2,
|
| 5 |
+
"min_count": 1,
|
| 6 |
+
"dim": 100,
|
| 7 |
+
"minn": 3,
|
| 8 |
+
"maxn": 6,
|
| 9 |
+
"loss": "softmax",
|
| 10 |
+
"bucket": 200000,
|
| 11 |
+
"train_samples": 3597859,
|
| 12 |
+
"trained_at": "2026-03-28T19:04:32.539634+00:00"
|
| 13 |
+
}
|