Views
No views yet
Base Model |████████████████████ | 50.0%
Fine-Tuned |█████████████████████████ | 63.3% (+26.7%)Base Model |██████████████████████ | 56.7%
Fine-Tuned |█████████████████████████████████ | 83.3% (+47.1%)Base Model |████████████████████████████████████████| 101.9s
Fine-Tuned |████████████████████████ | 62.4s (38.8% faster)| Metric | Base Model | Fine-Tuned | Improvement |
|---|---|---|---|
| Content Coverage | 50.0% | 63.3% | +26.7% |
| Structure Quality | 56.7% | 83.3% | +47.1% |
| Avg Inference Time | 101.9s | 62.4s | 38.8% faster |
Epoch 1: ████████████████████████████████████████ Loss: 1.605 → 0.115
Epoch 2: ████████████ Loss: 0.115 → 0.020
Epoch 3: ████ Loss: 0.020 → 0.019| Parameter | Value |
|---|---|
| Base Model | microsoft/Phi-3-mini-4k-instruct |
| Method | LoRA (Low-Rank Adaptation) |
| LoRA Rank | 64 |
| LoRA Alpha | 128 |
| Target Modules | q_proj, k_proj, v_proj, o_proj, gate_proj, up_proj, down_proj |
| Training Examples | 900 |
| Validation Examples | 100 |
| Epochs | 3 |
| Batch Size | 16 |
| Learning Rate | 2e-4 |
| Precision | BF16 |
| Training Time | ~51 minutes |
| Final Eval Loss | 0.0186 |
| Token Accuracy | 99.3% |
1from transformers import AutoTokenizer, AutoModelForCausalLM
2from peft import PeftModel
3import torch
4
5# Load model
6model_name = "microsoft/Phi-3-mini-4k-instruct"
7tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)
8
9base_model = AutoModelForCausalLM.from_pretrained(
10 model_name,
11 torch_dtype=torch.bfloat16,
12 device_map="auto",
13 trust_remote_code=True
14)
15model = PeftModel.from_pretrained(base_model, "sarathi-balakrishnan/phi3-agricultural-analyst")
16
17# Create prompt
18prompt = """You are an expert agricultural analyst. Analyze the following query using the provided data context.
19
20### Query
21What are the key investment opportunities in Fresno County agriculture?
22
23### Data Context
24County: Fresno, CA
25Operators: 5,847
26Average Farm Size: 423 acres
27Irrigation Coverage: 89%
28Revenue per Acre: $2,340
29
30### Analysis"""
31
32# Generate
33inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
34outputs = model.generate(
35 inputs["input_ids"],
36 max_new_tokens=500,
37 temperature=0.7,
38 do_sample=True
39)
40print(tokenizer.decode(outputs[0], skip_special_tokens=True))model.merge_and_unload()