Downloads · 30 days
86
6% of all-time downloads
hassan7272/urdu-finance-embeddings
urdu-finance-embeddings is a sentence similarity model from hassan7272. Use it when you need a score for how close two texts are. It is set up for sentence-transformers. The card lists the license as apache-2.0.
Downloads · 30 days
86
6% of all-time downloads
All-time downloads
1.4K
Public
Parameters
278M
1.1 GB on disk
Likes
0
Public
Click a slice to open those files.
.safetensors1.1 GB · 99%
From the Hugging Face model README
Pakistan has 220 million people, millions of active fintech users (Easypaisa, JazzCash, Raast), and a growing Islamic finance sector — yet almost no NLP infrastructure exists for Pakistani financial queries.
The challenge is threefold:
This model was built from the ground up to fix that.
| Feature | Generic Multilingual Models | This Model |
|---|---|---|
| Roman Urdu queries | ❌ Poor | ✅ Trained on it |
| Islamic finance terms | ❌ No context | ✅ Domain fine-tuned |
| Pakistani banking context | ❌ None | ✅ HBL, Meezan, NBP, UBL |
| Mixed-language queries | ❌ Struggles | ✅ Handles naturally |
| RAG retrieval accuracy | ~60–70% | 93.9% @ Top-1 |
Evaluated using InformationRetrievalEvaluator on a held-out validation set of 147 financial queries across all 8 categories.
| Metric | Score | What It Means |
|---|---|---|
| Accuracy@1 | 93.9% | Correct answer ranked #1 out of corpus |
| Accuracy@3 | 99.3% | Correct answer in top 3 |
| Accuracy@10 | 100.0% | Never misses — perfect recall at 10 |
| MRR@10 | 0.966 | Near-perfect mean reciprocal rank |
| NDCG@10 | 0.975 | Excellent ranking quality |
| MAP@100 | 0.966 | Consistent precision across the board |
Baseline (zero fine-tuning): Accuracy@1 ≈ 72.8% → +21 points gained from domain training
from sentence_transformers import SentenceTransformer, util
model = SentenceTransformer("hassan7272/urdu-finance-embeddings")
# Works in all three forms — no preprocessing needed
queries = [
"zakat ka hisab kaise karein", # Roman Urdu
"زکوٰۃ کا حساب کیسے کریں", # Urdu script
"how to calculate zakat in Pakistan", # English
]
# Your answer corpus
answers = [
"Zakat 2.5% hoti hai jo nisab se zyada savings par lagti hai...",
"Meezan Bank Islamic saving account mein profit milta hai...",
]
query_embeddings = model.encode(queries, convert_to_tensor=True)
answer_embeddings = model.encode(answers, convert_to_tensor=True)
scores = util.cos_sim(query_embeddings, answer_embeddings)
print(scores)
from sentence_transformers import SentenceTransformer
import faiss, numpy as np
model = SentenceTransformer("hassan7272/urdu-finance-embeddings")
# Build index over your answer corpus
answers = ["answer 1 ...", "answer 2 ...", ...]
embeddings = model.encode(answers, normalize_embeddings=True)
index = faiss.IndexFlatIP(embeddings.shape[1]) # inner product = cosine on normalized
index.add(embeddings.astype(np.float32))
# Retrieve
query = "Easypaisa se ghar ka kiraya kaise bharein"
q_emb = model.encode([query], normalize_embeddings=True).astype(np.float32)
scores, indices = index.search(q_emb, k=10) # top-10 retrieval
This model was produced through a full ML engineering pipeline built from scratch — not just a fine-tuning script.
The training data comes from hassan7272/urdu-finance-qa, a custom 1,510-record Q&A dataset across 8 Pakistani financial categories.
Text normalization handled:
kyaaaa → kyaa)ur / roman_ur / en)Instead of random negatives, a category-aware hard negative miner was built:
Query: "zakat ka hisab kaise karein" (Islamic Finance)
Random negative: "online bill payment kaise karein" ← too easy, model ignores
Hard negative: "loan ka interest kaise calculate hota hai" ← looks relevant, is WRONG
The confusable category map forces the model to discriminate on intent, not just topic. For example, islamic_finance negatives are drawn from loans_credit and personal_finance — the most semantically similar but semantically incorrect categories. Keyword overlap filtering ensures negatives are hard but not trivially different.
2,752 training examples were built from three sources:
(question_ur, answer_ur) pairs — native Urdu / Roman Urdu(question_ur, hard_negative, answer_ur) triplets — explicit confusion signal(question_en, answer_en) pairs — free cross-lingual alignmentLoss: MultipleNegativesRankingLoss (scale=20, cosine similarity)
Training config:
Base model : paraphrase-multilingual-mpnet-base-v2
Epochs : 4
Batch size : 16
Learning rate : 5e-5
FP16 : True (mixed precision)
Platform : Kaggle GPU (CUDA)
Train time : 7 minutes
InformationRetrievalEvaluator was used at every 86 steps during training, treating the entire validation answer set as a retrieval corpus. This is the same evaluation setup used in real RAG systems — not a toy cosine similarity test.
Training progression:
| Epoch | Step | NDCG@10 |
|---|---|---|
| 1.0 | 86 | 0.9547 |
| 1.16 | 100 | 0.9546 |
| 2.0 | 172 | 0.9746 ← best |
Model converged at epoch 2 with train loss of 0.063 — a very low value indicating clean convergence without overfitting on the 1.5k dataset.
| Category | Records | Description |
|---|---|---|
| Personal Finance | 251 | Budgeting, savings, emergency funds |
| Islamic Finance | 240 | Zakat, Riba, Murabaha, Sukuk |
| Financial Education | 237 | Concepts, terminology, literacy |
| Banking | 222 | HBL, MCB, NBP, Meezan, UBL |
| Investment | 183 | Mutual funds, stocks, real estate |
| Loans & Credit | 159 | Home loans, car financing, credit cards |
| Digital Finance | 141 | Easypaisa, JazzCash, Raast, SadaPay |
| Bills & Payments | 77 | Utility bills, tax payments, DISCO |
This model is Phase 1 of the FinGuard RAG system — a full retrieval-augmented generation pipeline for Pakistani financial advisory:
User Query (Urdu / Roman Urdu / English)
↓
Query Normalization
↓
Hybrid Search (this model + BM25)
↓
Top-10 Retrieval
↓
MMR (diversity filtering)
↓
Cross-Encoder Reranker → Top-3
↓
LLM Answer Generation
The embedding model (this model) handles the vector search component with 93.9% accuracy at Top-1.
If you use this model in your research or application, please cite:
@misc{hassan2025finguard,
title = {FinGuard Urdu Finance Embeddings: Domain-Specific Multilingual Embeddings for Pakistani Financial RAG},
author = {Hassan},
year = {2025},
publisher = {HuggingFace},
url = {https://huggingface.co/hassan7272/urdu-finance-embeddings},
note = {Fine-tuned on urdu-finance-qa dataset with hard negative mining and MultipleNegativesRankingLoss}
}
@inproceedings{reimers-2019-sentence-bert,
title = "Sentence-BERT: Sentence Embeddings using Siamese BERT-Networks",
author = "Reimers, Nils and Gurevych, Iryna",
booktitle = "Proceedings of the 2019 Conference on Empirical Methods in Natural Language Processing",
year = "2019",
url = "https://arxiv.org/abs/1908.10084",
}