Downloads · 30 days
39
0% of all-time downloads
suriya7/Gemma2B-Finetuned-Sql-Generator
Gemma2B-Finetuned-Sql-Generator is a text generation model from suriya7. 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.
The Gemma 2B SQL Generator is a specialized version of the Gemma 2B model, fine-tuned to generate SQL queries based on a given SQL context. This model has been tailored to assist developers and analysts in generating…
Downloads · 30 days
39
0% of all-time downloads
All-time downloads
8K
Public
Parameters
2.5B
5 GB on disk
Likes
14
Public
Click a slice to open those files.
.safetensors5 GB · 100%
From the Hugging Face model README
The Gemma 2B SQL Generator is a specialized version of the Gemma 2B model, fine-tuned to generate SQL queries based on a given SQL context. This model has been tailored to assist developers and analysts in generating accurate SQL queries automatically, enhancing productivity and reducing the scope for errors.
To set up the necessary environment for using the SQL Generator, run the following commands:
pip install torch torch
pip install transformers
here is the github link click here
# Load model directly
from transformers import AutoTokenizer, AutoModelForCausalLM
tokenizer = AutoTokenizer.from_pretrained("suriya7/Gemma2B-Finetuned-Sql-Generator")
model = AutoModelForCausalLM.from_pretrained("suriya7/Gemma2B-Finetuned-Sql-Generator")
prompt_template = """
<start_of_turn>user
You are an intelligent AI specialized in generating SQL queries.
Your task is to assist users in formulating SQL queries to retrieve specific information from a database.
Please provide the SQL query corresponding to the given prompt and context:
Prompt:
find the price of laptop
Context:
CREATE TABLE products (
product_id INT,
product_name VARCHAR(100),
category VARCHAR(50),
price DECIMAL(10, 2),
stock_quantity INT
);
INSERT INTO products (product_id, product_name, category, price, stock_quantity)
VALUES
(1, 'Smartphone', 'Electronics', 599.99, 100),
(2, 'Laptop', 'Electronics', 999.99, 50),
(3, 'Headphones', 'Electronics', 99.99, 200),
(4, 'T-shirt', 'Apparel', 19.99, 300),
(5, 'Jeans', 'Apparel', 49.99, 150);<end_of_turn>
<start_of_turn>model
"""
prompt = prompt_template
encodeds = tokenizer(prompt, return_tensors="pt", add_special_tokens=True).input_ids
device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
model.to(device)
inputs = encodeds.to(device)
# Increase max_new_tokens if needed
generated_ids = model.generate(inputs, max_new_tokens=1000, do_sample=True, temperature = 0.7,pad_token_id=tokenizer.eos_token_id)
ans = ''
for i in tokenizer.decode(generated_ids[0], skip_special_tokens=True).split('<end_of_turn>')[:2]:
ans += i
# Extract only the model's answer
model_answer = ans.split("model")[1].strip()
print(model_answer)