Views
No views yet
| Parameter | Value |
|---|---|
| Epochs | 2 |
| Batch size (per device) | 2 |
| Gradient accumulation steps | 8 |
| Effective batch size | 16 |
| Learning rate | 2e-4 |
| LR scheduler | Cosine |
| Warmup ratio | 0.03 |
| Optimizer | paged_adamw_32bit |
| Max sequence length | 512 |
| Quantization | NF4 4-bit (double quant) |
| Compute dtype | float16 |
| Hardware | Kaggle T4 x2 |
| Training time | ~5 hours |
| Epoch | Training Loss | Validation Loss |
|---|---|---|
| 1 | 1.2723 | 1.4589 |
| 2 | 1.0242 | 1.5069 |
1from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig
2from peft import PeftModel
3import torch
4
5base_model_id = "mistralai/Mistral-7B-v0.1"
6adapter_id = "MadhurArora1/mistral-7b-finance-qlora"
7
8bnb_config = BitsAndBytesConfig(
9 load_in_4bit=True,
10 bnb_4bit_use_double_quant=True,
11 bnb_4bit_quant_type="nf4",
12 bnb_4bit_compute_dtype=torch.float16
13)
14
15tokenizer = AutoTokenizer.from_pretrained(adapter_id)
16model = AutoModelForCausalLM.from_pretrained(
17 base_model_id,
18 quantization_config=bnb_config,
19 device_map="auto"
20)
21model = PeftModel.from_pretrained(model, adapter_id)1def ask(question, max_new_tokens=200):
2 prompt = f"Below is a financial question. Answer it accurately and concisely.\n\n### Question:\n{question}\n\n### Answer:\n"
3 inputs = tokenizer(prompt, return_tensors="pt").to("cuda")
4 with torch.no_grad():
5 output = model.generate(
6 **inputs,
7 max_new_tokens=max_new_tokens,
8 temperature=0.1,
9 do_sample=True,
10 pad_token_id=tokenizer.eos_token_id
11 )
12 return tokenizer.decode(output[0][inputs["input_ids"].shape[1]:], skip_special_tokens=True)
13
14print(ask("What is the P/E ratio and how do investors use it?"))
15print(ask("Explain the difference between stocks and bonds."))
16print(ask("What is compound interest?"))The P/E ratio (Price-to-Earnings ratio) measures how much investors are willing to pay for each dollar of a company's earnings. It is calculated by dividing the stock price by earnings per share (EPS). A high P/E may indicate the market expects strong future growth, while a low P/E may suggest undervaluation or slow growth expectations. Investors use it to compare companies within the same industry.
ROE (Return on Equity) measures how efficiently a company generates profit from shareholders' equity, while ROA (Return on Assets) measures profitability relative to total assets. ROE focuses on returns to equity holders and is affected by leverage; ROA is a broader measure of operational efficiency regardless of how assets are financed.
@misc{mistral7b,
title={Mistral 7B},
author={Mistral AI},
year={2023},
url={https://huggingface.co/mistralai/Mistral-7B-v0.1}
}