File size: 2,612 Bytes
c8f1989
46658d5
 
 
c8f1989
 
46658d5
 
 
 
 
 
d983985
 
 
 
 
c8f1989
 
d983985
c8f1989
46658d5
d983985
 
 
 
 
c8f1989
d983985
c8f1989
d983985
c8f1989
d983985
 
 
 
c8f1989
d983985
c8f1989
d983985
 
 
 
 
 
c8f1989
d983985
 
 
 
 
c8f1989
d983985
c8f1989
46658d5
d983985
46658d5
c8f1989
46658d5
c8f1989
46658d5
d983985
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
---
language:
  - en
license: apache-2.0
library_name: peft
tags:
  - text-generation
  - sql
  - chat
  - peft
  - lora
  - transformers
  - phi-3
  - instruction-tuning
base_model: unsloth/Phi-3-mini-4k-instruct-bnb-4bit
pipeline_tag: text-generation
inference: false
---

# 🧠 SQL Chat – Phi-3-mini SQL Assistant

**Model ID:** `saadkhi/SQL_Chat_finetuned_model`  
**Base model:** `unsloth/Phi-3-mini-4k-instruct-bnb-4bit`  
**Model type:** LoRA (merged)  
**Task:** Natural Language → SQL query generation + conversational SQL assistance  
**Language:** English  
**License:** Apache 2.0

This model is a fine-tuned version of **Phi-3-mini-4k-instruct** (4-bit quantized) specialized in understanding natural language questions about databases and generating correct, clean SQL queries.

## ✨ Key Features

- Very good balance between size, speed and SQL generation quality  
- Works well with common database dialects (PostgreSQL, MySQL, SQLite, SQL Server, etc.)  
- Can explain queries, suggest improvements and handle follow-up questions  
- Fast inference even on consumer hardware (especially with 4-bit quantization)

## 🎯 Intended Use & Capabilities

**Best for:**
- Converting natural language questions → SQL queries  
- Helping beginners learn SQL through explanations  
- Quick prototyping of SQL queries in development  
- Building SQL chat interfaces / tools / assistants  
- Educational purposes

**Limitations / Not recommended for:**
- Extremely complex analytical/business intelligence queries  
- Real-time query optimization advice  
- Very database-specific or proprietary SQL extensions  
- Production systems without human review (always validate generated SQL!)

## 🛠️ Quick Start (merged LoRA version)

```python
from transformers import AutoTokenizer, AutoModelForCausalLM
import torch

model_id = "saadkhi/SQL_Chat_finetuned_model"

tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForCausalLM.from_pretrained(
    model_id,
    torch_dtype=torch.bfloat16,
    device_map="auto",
    trust_remote_code=True
)

# Simple prompt style (chat template is recommended)
prompt = """Show all customers who placed more than 5 orders in 2024"""

messages = [{"role": "user", "content": prompt}]

inputs = tokenizer.apply_chat_template(
    messages,
    tokenize=True,
    add_generation_prompt=True,
    return_tensors="pt"
).to(model.device)

outputs = model.generate(
    inputs,
    max_new_tokens=180,
    do_sample=False,
    temperature=0.0,
    pad_token_id=tokenizer.eos_token_id
)

print(tokenizer.decode(outputs[0], skip_special_tokens=True))