📋 Model Details
Table with columns: Field, Details| Field | Details |
|---|
| Developed by | somrajmondal |
| Base model | unsloth/phi-3-mini-4k-instruct-bnb-4bit |
| Model type | Causal Language Model (Phi-3 architecture) |
| Parameters | 3.8B total / 29.8M trainable (0.78%) |
| Language | English |
| License | Apache 2.0 |
| Fine-tuning method | LoRA (Low-Rank Adaptation) |
| Quantization | 4-bit NF4 during training, merged to fp16 |
🎯 What This Model Does
This model is fine-tuned to answer finance and investment questions clearly and accurately. It was trained on the gbharti/finance-alpaca dataset covering topics like:
- Stock market concepts (P/E ratio, dividends, market cap)
- Investment strategies (ETFs, mutual funds, dollar-cost averaging)
- Fixed income (bonds, yields, interest rates)
- Personal finance (compound interest, savings, budgeting)
- Financial planning and portfolio diversification
🏋️ Training Details
Table with columns: Setting, Value| Setting | Value |
|---|
| Dataset | gbharti/finance-alpaca |
| Training rows | 5,000 |
| Epochs | 2 |
| Total steps | 1,250 |
| Batch size | 2 (effective: 8 with grad accumulation) |
| Learning rate | 2e-4 (cosine scheduler) |
| Optimizer | AdamW 8-bit |
|
🚀 How to Use
from transformers import AutoTokenizer, AutoModelForCausalLM
import torch
model_id = "somrajmondal/phi3-mini-finance-lora-fp16"
tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForCausalLM.from_pretrained(
model_id,
torch_dtype=torch.float16,
device_map="auto",
)
question = "What is compound interest and why is it important?"
prompt = f"""<|user|>
{question}
<|end|>
<|assistant|>
"""
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
outputs = model.generate(
**inputs,
max_new_tokens=300,
do_sample=False,
repetition_penalty=1.3,
eos_token_id=tokenizer.eos_token_id,
pad_token_id=tokenizer.eos_token_id,
)
response = tokenizer.decode(
outputs[0][inputs["input_ids"].shape[1]:],
skip_special_tokens=True
)
print(response)
With Unsloth (Faster Inference)
from unsloth import FastLanguageModel
import torch
model, tokenizer = FastLanguageModel.from_pretrained(
model_name = "somrajmondal/phi3-mini-finance-lora-fp16",
max_seq_length = 1024,
dtype = None,
load_in_4bit = True,
)
FastLanguageModel.for_inference(model)
question = "What is the difference between a stock and a bond?"
prompt = f"""<|user|>
{question}
<|end|>
<|assistant|>
"""
inputs = tokenizer(prompt, return_tensors="pt").to("cuda")
outputs = model.generate(
**inputs,
max_new_tokens=300,
do_sample=False,
repetition_penalty=1.3,
eos_token_id=tokenizer.eos_token_id,
pad_token_id=tokenizer.eos_token_id,
)
response = tokenizer.decode(
outputs[0][inputs["input_ids"].shape[1]:],
skip_special_tokens=True
)
print(response)
This model uses the Phi-3 chat template. Always wrap your input like this:
<|user|>
Your finance question here
<|end|>
<|assistant|>
📊 Example Outputs
Q: What is a P/E ratio?
The price-to-earnings (P/E) ratio measures a company's current share price relative to its earnings per share. A high P/E suggests investors expect future growth, while a low P/E may indicate an undervalued stock or slower expected growth.
Q: What is dollar cost averaging?
Dollar cost averaging is an investment strategy where you invest a fixed amount of money at regular intervals, regardless of market conditions. This reduces the impact of volatility and removes the need to time the market.
⚠️ Limitations
- Trained on only 5,000 rows — may lack depth on niche financial topics
- Not suitable for real financial advice — always consult a professional
- May occasionally produce incomplete answers on complex multi-part questions
- Training loss of 2.18 indicates room for improvement with more epochs/data
🔧 Recommended Inference Settings
do_sample = False
repetition_penalty = 1.3
max_new_tokens = 300
do_sample = True
temperature = 0.3
top_p = 0.9
📦 Training Framework
📄 Citation
If you use this model, please cite the base model and dataset:
@misc{phi3-mini-finance-lora,
author = {somrajmondal},
title = {Phi-3-mini Finance LoRA},
year = {2025},
publisher = {HuggingFace},
url = {https://huggingface.co/somrajmondal/phi3-mini-finance-lora-fp16}
}