SmartVest / README.md
shravankotagi's picture
Update README.md
cf11116 verified
|
Raw
History Blame Contribute Delete
8.15 kB
---
base_model: sarvamai/sarvam-1
library_name: peft
pipeline_tag: text-generation
datasets:
- shravankotagi/hinglish-finance-sft-v5-fixed
tags:
- lora
- qlora
- sft
- trl
- peft
- finance
- hinglish
- indian-stock-market
license: apache-2.0
language:
- en
- hi
---
# SmartVest — Sarvam-1 Fine-Tuned for Hinglish Financial Assistance
[![License](https://img.shields.io/badge/License-Apache_2.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
[![Base Model](https://img.shields.io/badge/Base_Model-Sarvam--1-green)](https://huggingface.co/sarvamai/sarvam-1)
[![Dataset](https://img.shields.io/badge/Dataset-Hinglish_Finance_SFT-yellow)](https://huggingface.co/datasets/shravankotagi/hinglish-finance-sft-v5-fixed)
[![PEFT](https://img.shields.io/badge/Adapter-PEFT_LoRA-orange)](https://github.com/huggingface/peft)
A QLoRA fine-tune of **Sarvam-1** underlying **SmartVest**, an interactive web application designed for Indian retail investors. SmartVest allows users to text or speak their financial, tax, and trading queries in conversational **Hinglish** (Hindi in Latin script mixed with English financial terms) and receive real-time, safety-verified responses.
---
## SmartVest Interactive Interface
SmartVest is deployed as a full-stack financial assistant with an integrated safety verification engine:
- **Voice & Text Input:** Users can type or use voice queries (speech-to-text) to ask market questions.
- **Trust Guard Panel:** Features real-time LLM response validation, evaluating outputs against safety checkpoints (e.g., SEBI disclaimers, hallucination checks) to assign a verification score before rendering to the user.
- **Conversational Search History:** Tracks query logs and verification statuses (`PASS`) in real time.
---
## Sample Generation Outputs
### Example 1: Live Market & Entity Query
**User:** `Bajaj Housing Finance ka aaj ka bhav kya hai?`
**SmartVest:** `Bajaj Housing Finance (BAJAJHFL) ka aaj ka live NSE price hai Rs 86.52 (change neeche -1.27% aaj). Invest karne se pehle apne broker app pe confirm karein. Yeh sirf informational data hai. SEBI registered advisor se zaroor milein.`
### Example 2: Portfolio Advice & Risk Query
**User:** `loss ho raha hai portfolio mein kya karein?`
**SmartVest:** `Bear market mein ghabrana zaroori nahi. Historically markets hamesha recover karte hain - long term investors ke liye yeh buying opportunity hoti hai. SIP jaari rakho, quality stocks hold karo, panic mein mat becho. Yeh sirf educational info hai. SEBI registered advisor se zaroor milein.`
### Example 3: Financial Product Comparison
**User:** `FD vs mutual fund konsa better hai long term ke liye?`
**SmartVest:** `FD (Fixed Deposit) mein guaranteed returns milte hain aur risk bahut low hota hai, jabki Mutual Funds market-linked hote hain aur unme high returns ka potential hota hai. Long term wealth creation ke liye Mutual Funds behtar hain, par short term safety ke liye FD secure hai. Apne goal ke hisab se allocate karein. Yeh sirf educational info hai. SEBI registered advisor se zaroor milein.`
---
## Model Details
- **Developed by:** Shravan Kotagi
- **Application Name:** SmartVest
- **Model type:** Causal LM — Sarvam-1 + LoRA adapter (PEFT)
- **Languages:** Hinglish (hi-Latn), English
- **License:** Apache 2.0
- **Base model:** `sarvamai/sarvam-1`
- **Task:** Conversational SFT for Indian finance, tax rules (LTCG/STCG), stock tickers, and general market literacy.
---
## What It Does
SmartVest acts as a friendly, concise AI assistant for Indian stock market queries:
- **Entity Resolution:** Handles Indian tickers (e.g., `BAJAJHFL`, `RELIANCE`, `INFY`) and Hinglish financial slang (`bhav`, `mandi`, `munafa`, `profit book`).
- **Taxation & Market Literacy:** Explains capital gains tax, brokerage charges, and trading losses clearly.
- **Safety Disclaimers & Trust Guard:** Automatically includes SEBI/educational disclaimers and verifies responses for investor safety.
---
## Training Details
| Parameter | Value |
|---|---|
| **Base Model** | `sarvamai/sarvam-1` |
| **Method** | QLoRA (4-bit quantization via `bitsandbytes`) |
| **Dataset** | [`shravankotagi/hinglish-finance-sft-v5-fixed`](https://huggingface.co/datasets/shravankotagi/hinglish-finance-sft-v5-fixed) |
| **Hardware** | Kaggle T4 GPU (15.6 GB VRAM) |
| **LoRA Rank / Alpha** | `r=16` / `alpha=32` (`dropout=0.05`) |
| **Target Modules** | `q_proj`, `k_proj`, `v_proj`, `o_proj`, `gate_proj`, `up_proj`, `down_proj` |
| **Trainable Parameters** | 23,969,792 / 2,549,463,040 (0.94%) |
| **Vocabulary Size** | Expanded to 68,195 tokens |
| **Epochs / Total Steps**| 2 Epochs / 1,174 Steps |
| **Optimizer / LR** | `paged_adamw_8bit` / `1e-4` (Cosine Scheduler) |
### Dataset Overview
The model was fine-tuned on [`shravankotagi/hinglish-finance-sft-v5-fixed`](https://huggingface.co/datasets/shravankotagi/hinglish-finance-sft-v5-fixed), an instruction dataset consisting of 5,521 instruction-response pairs covering:
- **Financial QA & Literacy:** Mutual funds, ETFs, portfolio rebalancing, and risk metrics.
- **Indian Taxation:** Capital gains (LTCG/STCG), ITR forms, and tax loss harvesting.
- **Market Sentiment & News:** Analysis of market trends, corporate actions, and regulatory updates in conversational Hinglish.
---
## Training Loss Curve
| Step | Training Loss | Validation Loss |
|:---:|:---:|:---:|
| 150 | 0.7084 | 0.7169 |
| 300 | 0.6150 | 0.6206 |
| 450 | 0.5472 | 0.5872 |
| 600 | 0.5373 | 0.5665 |
| 750 | 0.4852 | 0.5523 |
| 900 | 0.5248 | 0.5426 |
| 1050 | 0.5042 | 0.5376 |
---
## How to Use
To run inference, load `sarvamai/sarvam-1` in 4-bit mode, resize its embedding layer to match the expanded tokenizer, and apply the PEFT adapter:
```python
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig
from peft import PeftModel
MODEL_ID = "shravankotagi/SmartVest"
# 1. Configure 4-bit quantization
bnb_config = BitsAndBytesConfig(
load_in_4bit=True,
bnb_4bit_quant_type="nf4",
bnb_4bit_compute_dtype=torch.float16,
bnb_4bit_use_double_quant=True,
)
# 2. Load base model
base_model = AutoModelForCausalLM.from_pretrained(
"sarvamai/sarvam-1",
quantization_config=bnb_config,
device_map="auto",
trust_remote_code=True,
)
# 3. Load tokenizer and resize embeddings
tokenizer = AutoTokenizer.from_pretrained(MODEL_ID)
tokenizer.pad_token = tokenizer.eos_token
base_model.resize_token_embeddings(len(tokenizer))
# 4. Load SmartVest LoRA adapter
model = PeftModel.from_pretrained(
base_model,
MODEL_ID,
ignore_mismatched_sizes=True
)
model.eval()
# 5. Generate
SYSTEM = """You are SmartVest, an AI assistant for Indian retail investors.
You understand Hinglish and answer finance questions clearly and factually."""
user_query = "FD vs mutual fund konsa better hai long term ke liye?"
prompt = f"<s>[INST] {SYSTEM}\n\nUser query: {user_query} [/INST]"
inputs = tokenizer(prompt, return_tensors="pt").to("cuda")
with torch.no_grad():
outputs = model.generate(
**inputs,
max_new_tokens=120,
temperature=0.5,
do_sample=True,
repetition_penalty=1.1
)
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
print(response.split("[/INST]")[-1].strip())
```
---
## Interface Preview
![image](https://cdn-uploads.huggingface.co/production/uploads/68970c56644d1a4ced590567/_kFiEzZevJxEgqADIK0LX.png)
---
## Limitations & Disclaimers
* **Educational Purpose Only:** SmartVest is an experimental AI assistant and does not provide certified financial, legal, or tax advice.
* **Dynamic Data:** Stock prices, tax slabs (LTCG/STCG), and exchange fees change frequently. Always verify live rates via official SEBI/NSE/BSE sources or consult a SEBI-registered financial advisor.
* **Scope:** Optimized specifically for Indian retail market contexts and Hinglish terminology; may underperform on non-Indian or purely technical corporate finance queries.
---
## Contact
* **Developer:** Shravan Kotagi
* **Hugging Face:** [@shravankotagi](https://huggingface.co/shravankotagi)