File size: 2,191 Bytes
b55ed9a
 
 
 
a3f482d
 
 
 
 
b55ed9a
 
 
 
 
 
a3f482d
 
 
 
 
b55ed9a
 
a3f482d
b55ed9a
a3f482d
b55ed9a
 
 
 
 
a3f482d
b55ed9a
a3f482d
 
 
 
 
b55ed9a
a3f482d
b55ed9a
a3f482d
b55ed9a
a3f482d
b55ed9a
a3f482d
 
 
b55ed9a
a3f482d
 
 
b55ed9a
a3f482d
 
 
 
b55ed9a
a3f482d
 
 
b55ed9a
a3f482d
 
 
 
 
 
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
---
base_model: TinyLlama/TinyLlama-1.1B-Chat-v1.0
library_name: peft
pipeline_tag: text-generation
license: mit
language:
- en
datasets:
- spider
tags:
- base_model:adapter:TinyLlama/TinyLlama-1.1B-Chat-v1.0
- lora
- sft
- transformers
- trl
- text-to-sql
- sql
- natural-language-processing
metrics:
- loss
---

# Text-to-SQL TinyLlama LoRA Adapter

A fine-tuned LoRA adapter that converts **natural language questions into SQL queries**. Built on top of [TinyLlama-1.1B-Chat-v1.0](https://huggingface.co/TinyLlama/TinyLlama-1.1B-Chat-v1.0) using Supervised Fine-Tuning (SFT) on the Spider benchmark dataset.

## Model Details

### Model Description

This is a **LoRA (Low-Rank Adaptation) adapter** fine-tuned to generate SQL queries from natural language questions. Only 0.10% of the base model's parameters were trained, making it extremely lightweight (4.5 MB) while still achieving strong results.

- **Developed by:** [Rj18](https://huggingface.co/Rj18)
- **Model type:** Causal Language Model (LoRA Adapter)
- **Language(s):** English
- **License:** MIT
- **Fine-tuned from:** [TinyLlama/TinyLlama-1.1B-Chat-v1.0](https://huggingface.co/TinyLlama/TinyLlama-1.1B-Chat-v1.0)

### Model Sources

- **Repository:** [https://github.com/18-RAJAT/Interactive-Production-text2sql-Pipeline](https://github.com/18-RAJAT/Interactive-Production-text2sql-Pipeline)

## How to Use

import torch
from transformers import AutoModelForCausalLM, AutoTokenizer
from peft import PeftModel

# Load base model and tokenizer
base_model = "TinyLlama/TinyLlama-1.1B-Chat-v1.0"
adapter = "Rj18/text-to-sql-tinyllama-lora"

tokenizer = AutoTokenizer.from_pretrained(adapter)
model = AutoModelForCausalLM.from_pretrained(base_model, torch_dtype=torch.float16)
model = PeftModel.from_pretrained(model, adapter)
model.eval()

# Generate SQL
question = "How many employees are in each department?"
prompt = f"[INST] Generate SQL for the following question.\nQuestion: {question} [/INST]\n"

inputs = tokenizer(prompt, return_tensors="pt")
with torch.no_grad():
    outputs = model.generate(**inputs, max_new_tokens=128, temperature=0.1)
    
sql = tokenizer.decode(outputs[0], skip_special_tokens=True)
print(sql)