Update README.md
Browse files
README.md
CHANGED
|
@@ -3,7 +3,6 @@ language:
|
|
| 3 |
- en
|
| 4 |
license: apache-2.0
|
| 5 |
library_name: peft
|
| 6 |
-
pipeline_tag: text-generation
|
| 7 |
tags:
|
| 8 |
- text-generation
|
| 9 |
- sql
|
|
@@ -11,61 +10,80 @@ tags:
|
|
| 11 |
- peft
|
| 12 |
- lora
|
| 13 |
- transformers
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
|
|
|
|
|
|
| 17 |
---
|
| 18 |
|
| 19 |
-
# 🧠 SQL Chat
|
| 20 |
|
| 21 |
**Model ID:** `saadkhi/SQL_Chat_finetuned_model`
|
| 22 |
-
**
|
| 23 |
-
**
|
|
|
|
|
|
|
|
|
|
| 24 |
|
| 25 |
-
This model is fine-tuned
|
| 26 |
|
| 27 |
-
|
| 28 |
|
| 29 |
-
|
|
|
|
|
|
|
|
|
|
| 30 |
|
| 31 |
-
|
| 32 |
|
| 33 |
-
**
|
| 34 |
-
-
|
| 35 |
-
-
|
|
|
|
|
|
|
|
|
|
| 36 |
|
| 37 |
-
**
|
| 38 |
-
-
|
| 39 |
-
-
|
|
|
|
|
|
|
| 40 |
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
## 🚀 How to Use
|
| 44 |
-
|
| 45 |
-
### Python (Transformers + PEFT)
|
| 46 |
|
| 47 |
```python
|
| 48 |
-
from transformers import
|
| 49 |
import torch
|
| 50 |
|
| 51 |
model_id = "saadkhi/SQL_Chat_finetuned_model"
|
| 52 |
|
| 53 |
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
| 54 |
-
model = AutoModelForCausalLM.from_pretrained(
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
- en
|
| 4 |
license: apache-2.0
|
| 5 |
library_name: peft
|
|
|
|
| 6 |
tags:
|
| 7 |
- text-generation
|
| 8 |
- sql
|
|
|
|
| 10 |
- peft
|
| 11 |
- lora
|
| 12 |
- transformers
|
| 13 |
+
- phi-3
|
| 14 |
+
- instruction-tuning
|
| 15 |
+
base_model: unsloth/Phi-3-mini-4k-instruct-bnb-4bit
|
| 16 |
+
pipeline_tag: text-generation
|
| 17 |
+
inference: false
|
| 18 |
---
|
| 19 |
|
| 20 |
+
# 🧠 SQL Chat – Phi-3-mini SQL Assistant
|
| 21 |
|
| 22 |
**Model ID:** `saadkhi/SQL_Chat_finetuned_model`
|
| 23 |
+
**Base model:** `unsloth/Phi-3-mini-4k-instruct-bnb-4bit`
|
| 24 |
+
**Model type:** LoRA (merged)
|
| 25 |
+
**Task:** Natural Language → SQL query generation + conversational SQL assistance
|
| 26 |
+
**Language:** English
|
| 27 |
+
**License:** Apache 2.0
|
| 28 |
|
| 29 |
+
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.
|
| 30 |
|
| 31 |
+
## ✨ Key Features
|
| 32 |
|
| 33 |
+
- Very good balance between size, speed and SQL generation quality
|
| 34 |
+
- Works well with common database dialects (PostgreSQL, MySQL, SQLite, SQL Server, etc.)
|
| 35 |
+
- Can explain queries, suggest improvements and handle follow-up questions
|
| 36 |
+
- Fast inference even on consumer hardware (especially with 4-bit quantization)
|
| 37 |
|
| 38 |
+
## 🎯 Intended Use & Capabilities
|
| 39 |
|
| 40 |
+
**Best for:**
|
| 41 |
+
- Converting natural language questions → SQL queries
|
| 42 |
+
- Helping beginners learn SQL through explanations
|
| 43 |
+
- Quick prototyping of SQL queries in development
|
| 44 |
+
- Building SQL chat interfaces / tools / assistants
|
| 45 |
+
- Educational purposes
|
| 46 |
|
| 47 |
+
**Limitations / Not recommended for:**
|
| 48 |
+
- Extremely complex analytical/business intelligence queries
|
| 49 |
+
- Real-time query optimization advice
|
| 50 |
+
- Very database-specific or proprietary SQL extensions
|
| 51 |
+
- Production systems without human review (always validate generated SQL!)
|
| 52 |
|
| 53 |
+
## 🛠️ Quick Start (merged LoRA version)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
|
| 55 |
```python
|
| 56 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 57 |
import torch
|
| 58 |
|
| 59 |
model_id = "saadkhi/SQL_Chat_finetuned_model"
|
| 60 |
|
| 61 |
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
| 62 |
+
model = AutoModelForCausalLM.from_pretrained(
|
| 63 |
+
model_id,
|
| 64 |
+
torch_dtype=torch.bfloat16,
|
| 65 |
+
device_map="auto",
|
| 66 |
+
trust_remote_code=True
|
| 67 |
+
)
|
| 68 |
+
|
| 69 |
+
# Simple prompt style (chat template is recommended)
|
| 70 |
+
prompt = """Show all customers who placed more than 5 orders in 2024"""
|
| 71 |
+
|
| 72 |
+
messages = [{"role": "user", "content": prompt}]
|
| 73 |
+
|
| 74 |
+
inputs = tokenizer.apply_chat_template(
|
| 75 |
+
messages,
|
| 76 |
+
tokenize=True,
|
| 77 |
+
add_generation_prompt=True,
|
| 78 |
+
return_tensors="pt"
|
| 79 |
+
).to(model.device)
|
| 80 |
+
|
| 81 |
+
outputs = model.generate(
|
| 82 |
+
inputs,
|
| 83 |
+
max_new_tokens=180,
|
| 84 |
+
do_sample=False,
|
| 85 |
+
temperature=0.0,
|
| 86 |
+
pad_token_id=tokenizer.eos_token_id
|
| 87 |
+
)
|
| 88 |
+
|
| 89 |
+
print(tokenizer.decode(outputs[0], skip_special_tokens=True))
|