somrajmondal/phi3-mini-finance-lora-fp16
150
๐น Phi-3-mini Finance LoRA (fp16)
A domain-specialized version of Microsoft's Phi-3-mini-4k-instruct, fine-tuned on financial Q&A data using LoRA + 4-bit NF4 quantization โ trained entirely on a free Google Colab T4 GPU.
๐ Model Details
๐ฏ 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
๐ How to Use
Quick Start (Transformers)
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, # set False for full fp16
)
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)๐ฌ Prompt Format
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
# For factual / accurate answers (recommended)
do_sample = False
repetition_penalty = 1.3
max_new_tokens = 300
# For more creative / detailed answers
do_sample = True
temperature = 0.3
top_p = 0.9๐ฆ Training Framework
- Unsloth โ 2x faster training, 60% less VRAM
- HuggingFace TRL โ SFTTrainer
- PEFT โ LoRA adapters
- BitsAndBytes โ 4-bit NF4 quantization
๐ 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}
}