Views
No views yet
1# Llama-3 8B Text-to-SQL (Fine-Tuned with LoRA)
2
3## 📌 Model Overview
4This repository contains a fine-tuned version of Meta's **Llama-3 (8B)**, optimized specifically for the **Natural Language to SQL (Text-to-SQL)** generation task. By converting conversational English into executable SQL queries, this model is designed to bridge the gap between non-technical stakeholders and complex relational databases.
5
6- **Developer:** DanielMartin Arogyasami
7- **Base Model:** Meta-Llama-3-8B
8- **Task:** Text-to-SQL (Code Generation)
9- **Fine-Tuning Methodology:** Low-Rank Adaptation (LoRA) / PEFT
10- **Language:** English, SQL
11- **License:** Meta Llama 3 Community License / MIT (for fine-tuned weights)
12
13## 🎯 Intended Use Cases
14This model is highly specialized for deployment in regulated enterprise environments (e.g., healthcare, finance), where data sovereignty is paramount.
15- **Enterprise Data Retrieval:** Empowering business users to query databases using natural language, significantly reducing reliance on specialized SQL programmers.
16- **Agentic AI Workflows:** Serving as the SQL-generation agent within larger Retrieval-Augmented Generation (RAG) and enterprise AI architectures.
17- **Privacy-Preserving Analytics:** Allowing companies to run text-to-SQL conversions entirely on-premises or within air-gapped Virtual Private Clouds (VPCs). This ensures compliance with HIPAA and FDA CFR Part 11, as no sensitive data is transmitted to external proprietary APIs.
18
19## ⚙️ Technical Details & Training
20This model was trained using **Parameter-Efficient Fine-Tuning (PEFT)**. Specifically, **LoRA (Low-Rank Adaptation)** was applied to the foundational Llama-3 model. This approach adapts the foundational reasoning capabilities of Llama-3 to the strict syntax requirements of SQL generation, while significantly reducing computational overhead.
21
22* **Adapter:** LoRA
23* **Target Modules:** Attention weights (`q_proj`, `v_proj`)
24* **Precision:** FP16 / 4-bit Quantization (QLoRA) supported for edge-deployment.
25* **Architecture:** Auto-Regressive Transformer.
26
27## 🚀 How to Use (Inference)
28You can load this model and run inference using the `transformers` and `peft` libraries from Hugging Face.
29
30```python
31import torch
32from transformers import AutoModelForCausalLM, AutoTokenizer
33from peft import PeftModel
34
35# Load base model and tokenizer
36base_model_id = "meta-llama/Meta-Llama-3-8B"
37adapter_id = "Arogyasami/Llama-3-8b-text2sql-finetune"
38
39tokenizer = AutoTokenizer.from_pretrained(base_model_id)
40base_model = AutoModelForCausalLM.from_pretrained(base_model_id, torch_dtype=torch.float16, device_map="auto")
41
42# Load LoRA adapter
43model = PeftModel.from_pretrained(base_model, adapter_id)
44
45# Define your schema and question
46schema = "CREATE TABLE Employees (ID int, Name varchar(255), Department varchar(255), Salary int);"
47question = "What is the average salary of employees in the Sales department?"
48
49prompt = f"Given the following database schema:\n{schema}\n\nWrite a SQL query to answer this question: {question}\n\nSQL:"
50
51inputs = tokenizer(prompt, return_tensors="pt").to("cuda")
52
53# Generate SQL
54outputs = model.generate(**inputs, max_new_tokens=100)
55print(tokenizer.decode(outputs[0], skip_special_tokens=True))