Downloads · 30 days
5
0% of all-time downloads
Arogyasami/Llama-2-7b-text2sql-finetune
Llama-2-7b-text2sql-finetune is a text generation model from Arogyasami. Use it when you need the model to write or continue text. It is set up for transformers. The card lists the license as mit.
python import torch from transformers import AutoModelForCausalLM, AutoTokenizer from peft import PeftModel
Downloads · 30 days
5
0% of all-time downloads
All-time downloads
5.1K
Public
Repo size
40.4 GB
Likes
1
Public
Click a slice to open those files.
.bin13.5 GB · 100%
From the Hugging Face model README
# Llama-2 7B Text-to-SQL (Fine-Tuned with LoRA)
## 📌 Model Overview
This 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.
- **Developer:** DanielMartin Arogyasami
- **Base Model:** Meta-Llama-3-8B
- **Task:** Text-to-SQL (Code Generation)
- **Fine-Tuning Methodology:** Low-Rank Adaptation (LoRA) / PEFT
- **Language:** English, SQL
- **License:** Meta Llama 3 Community License / MIT (for fine-tuned weights)
## 🎯 Intended Use Cases
This model is highly specialized for deployment in regulated enterprise environments (e.g., healthcare, finance), where data sovereignty is paramount.
- **Enterprise Data Retrieval:** Empowering business users to query databases using natural language, significantly reducing reliance on specialized SQL programmers.
- **Agentic AI Workflows:** Serving as the SQL-generation agent within larger Retrieval-Augmented Generation (RAG) and enterprise AI architectures.
- **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.
## ⚙️ Technical Details & Training
This 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.
* **Adapter:** LoRA
* **Target Modules:** Attention weights (`q_proj`, `v_proj`)
* **Precision:** FP16 / 4-bit Quantization (QLoRA) supported for edge-deployment.
* **Architecture:** Auto-Regressive Transformer.
## 🚀 How to Use (Inference)
You can load this model and run inference using the `transformers` and `peft` libraries from Hugging Face.
```python
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer
from peft import PeftModel
# Load base model and tokenizer
base_model_id = "meta-llama/Meta-Llama-3-8B"
adapter_id = "Arogyasami/Llama-3-8b-text2sql-finetune"
tokenizer = AutoTokenizer.from_pretrained(base_model_id)
base_model = AutoModelForCausalLM.from_pretrained(base_model_id, torch_dtype=torch.float16, device_map="auto")
# Load LoRA adapter
model = PeftModel.from_pretrained(base_model, adapter_id)
# Define your schema and question
schema = "CREATE TABLE Employees (ID int, Name varchar(255), Department varchar(255), Salary int);"
question = "What is the average salary of employees in the Sales department?"
prompt = f"Given the following database schema:\n{schema}\n\nWrite a SQL query to answer this question: {question}\n\nSQL:"
inputs = tokenizer(prompt, return_tensors="pt").to("cuda")
# Generate SQL
outputs = model.generate(**inputs, max_new_tokens=100)
print(tokenizer.decode(outputs[0], skip_special_tokens=True))
By utilizing LoRA instead of full-parameter fine-tuning, the computational cost and carbon footprint required to train this model were drastically reduced. Its 8B parameter size allows it to be served efficiently on consumer-grade hardware (e.g., NVIDIA RTX 4090 or A10G), democratizing advanced AI access.