CoolFace
Modelpublic

NanG01/bert-txn-classifier

sourceHugging Facemitupdated 5mo agoView on Hugging Face
0likes
Model Card

BERT Transaction Classifier — SecureWealth Twin (M2)

Fine-tuned bert-base-multilingual-cased for automatic transaction categorisation across English, Hindi (Devanagari), and Punjabi (Gurmukhi).

Part of the SecureWealth Twin AI system — a bank-grade fraud detection and financial intelligence platform.


Model Details

Base modelbert-base-multilingual-cased
Task7-class text classification
LanguagesEnglish · Hindi · Punjabi
Max sequence length64
Training epochs5
Learning rate2e-5
Batch size32
Train/val/test split70 / 15 / 15 (stratified)

Categories

LabelID
Food0
Transport1
EMIs2
Entertainment3
Utilities4
Investments5
Other6

Architecture

bert-base-multilingual-cased
  → [CLS] token (768-d)
  → Dropout(0.3)
  → Linear(768 → 7)

Usage

Load and run inference

python
import torch
import torch.nn as nn
from transformers import BertTokenizer, BertModel
from huggingface_hub import hf_hub_download

# Model class (must match training definition)
class BERTTxnClassifier(nn.Module):
    def __init__(self):
        super().__init__()
        self.bert       = BertModel.from_pretrained("bert-base-multilingual-cased")
        self.drop       = nn.Dropout(0.3)
        self.classifier = nn.Linear(768, 7)

    def forward(self, input_ids, attention_mask):
        cls = self.bert(input_ids=input_ids, attention_mask=attention_mask).last_hidden_state[:, 0, :]
        return self.classifier(self.drop(cls))

CATEGORIES = ["Food", "Transport", "EMIs", "Entertainment", "Utilities", "Investments", "Other"]

# Download model + tokenizer
model_path = hf_hub_download(repo_id="NanG01/bert-txn-classifier", filename="bert_classifier.pt")

device    = torch.device("cuda" if torch.cuda.is_available() else "cpu")
tokenizer = BertTokenizer.from_pretrained("NanG01/bert-txn-classifier")
model     = BERTTxnClassifier()
model.load_state_dict(torch.load(model_path, map_location=device))
model.to(device).eval()

# Inference
def predict(text: str) -> dict:
    enc = tokenizer(text, max_length=64, padding="max_length",
                    truncation=True, return_tensors="pt")
    with torch.no_grad():
        probs = torch.softmax(
            model(enc["input_ids"].to(device), enc["attention_mask"].to(device)), dim=-1
        ).squeeze(0)
    pred = probs.argmax().item()
    return {"category": CATEGORIES[pred], "confidence": round(probs[pred].item(), 4)}

Examples

python
predict("SWIGGY ORDER PAYMENT")
# → {"category": "Food", "confidence": 0.9821}

predict("HDFC BANK PERSONAL LOAN EMI")
# → {"category": "EMIs", "confidence": 0.9743}

predict("OLA RIDE PAYMENT")
# → {"category": "Transport", "confidence": 0.9512}

predict("ZERODHA MUTUAL FUND")
# → {"category": "Investments", "confidence": 0.9301}

predict("बिजली बिल भुगतान")
# → {"category": "Utilities", "confidence": 0.9104}

predict("ਖਾਣੇ ਦਾ ਭੁਗਤਾਨ")
# → {"category": "Food", "confidence": 0.8932}

Files

FileDescription
bert_classifier.ptFull model state dict
tokenizer/tokenizer.jsonTokenizer vocab + merges
tokenizer/tokenizer_config.jsonTokenizer config

Training Data

~1,300 transaction descriptions across 3 languages:

  • ~500 English transactions
  • ~400 Hindi transactions
  • ~400 Punjabi transactions

Dataset: SecureWealthTwin_DL_Datasets_v2.xlsx (private)


Part of SecureWealth Twin

This model is M2 in a 6-model AI system:

#ModelTask
M1BehaviorDNABehavioural anomaly detection
M2BERT Txn ClassifierTransaction categorisation
M3NLP Coercion DetectorCoercion language detection
M4Coercion Risk ScorerComposite risk scoring
M5Monte Carlo SimulatorWealth projection
M6Predictive Early WarningFinancial distress prediction

GitHub: BlackBox-Wealth/AI_Models_2