Downloads · 30 days
19
23% of all-time downloads
adamwhite625/gemma-2-2b-finetuned-text2sql
gemma-2-2b-finetuned-text2sql is a text generation model from adamwhite625. Use it when you need the model to write or continue text. It is set up for transformers. The card lists the license as apache-2.0.
Downloads · 30 days
19
23% of all-time downloads
All-time downloads
84
Public
Parameters
2.6B
5.3 GB on disk
Likes
0
Public
Click a slice to open those files.
.safetensors5.2 GB · 99%
From the Hugging Face model README

A specialized SQL generation model fine-tuned on 78k+ samples. Built with Unsloth for efficiency and speed.
</div>This model is a fine-tuned version of Gemma-2-2B-Instruct, specialized in translating natural language questions into SQL queries. It has been trained to understand database schemas and generate precise SQL commands without conversational filler.
pip install "unsloth[colab-new] @ git+[https://github.com/unslothai/unsloth.git](https://github.com/unslothai/unsloth.git)"
pip install --no-deps xformers "trl<0.9.0" peft accelerate bitsandbytes
from unsloth import FastLanguageModel
import torch
# 1. Load Model & Tokenizer
model_name = "adamwhite625/gemma-2-2b-finetuned-text2sql"
model, tokenizer = FastLanguageModel.from_pretrained(
model_name = model_name,
max_seq_length = 2048,
dtype = None,
load_in_4bit = True,
)
FastLanguageModel.for_inference(model)
# 2. Define Schema & Question
question = "Find the name and address of the employee who is the oldest."
schema = "CREATE TABLE employee (name VARCHAR, address VARCHAR, age INTEGER)"
# 3. Format Prompt (Strict Format)
prompt = f"""Write a SQL query to answer the following question given the database schema:
{question}
Schema:
{schema}"""
# 4. Generate SQL
inputs = tokenizer.apply_chat_template(
[{"role": "user", "content": prompt}],
add_generation_prompt = True,
return_tensors = "pt",
).to("cuda")
outputs = model.generate(input_ids=inputs, max_new_tokens=128, use_cache=True)
result = tokenizer.batch_decode(outputs)
# Print only the generated SQL (extracting from the response)
print(result[0].split("<start_of_turn>model")[-1].replace("<end_of_turn>", "").strip())
Find the name and address of the employee who is the oldest. Schema: CREATE TABLE employee (name VARCHAR, address VARCHAR, age INTEGER)
SELECT name, address FROM employee ORDER BY age DESC LIMIT 1