Team Ai
Modelpublic

iamkushagratomar/Qwen2.5-0.5B-text2sql

sourceHugging Faceapache-2.0updated 23d agoView on Hugging Face
0likes568downloads
Model Card

Qwen2.5-0.5B Text-to-SQL Model

This model is a fine-tuned version of Qwen2.5-0.5B for the text-to-SQL task on the b-mc2/sql-create-context dataset. It converts natural language questions + database schemas into SQL queries.

🔧 How to Use

  1. 1.Install dependencies:
bash
   pip install transformers torch
   
2. **Load the model**:

from transformers import AutoModelForCausalLM, AutoTokenizer import torch

modelname = "iamkushagratomar/Qwen2.5-0.5B-text2sql" tokenizer = AutoTokenizer.frompretrained(modelname) model = AutoModelForCausalLM.frompretrained(model_name).to("cuda")

  1. 1.Use the model (with your question + schema)::
bash
    def generate_sql(question, schema):
      # Format input as: "System: [message]\n\nUser: [question + schema]"
      system_message = "You are a SQL expert. Convert natural language questions into SQL queries."
      user_message = f"### Question: \n{question}\n\n### Schema: \n{schema}"
      
      full_input = f"System: {system_message}\n\nUser: {user_message}"
      
      inputs = tokenizer(full_input, return_tensors="pt").to(model.device)
      outputs = model.generate(
          input_ids=inputs.input_ids,
          max_new_tokens=100,
          temperature=0.2,
          do_sample=True,
          use_cache=True
      )
      return tokenizer.decode(outputs[0], skip_special_tokens=True)

    # Example usage
    question = "Find the total revenue from orders placed in the last 30 days."
    schema = "CREATE TABLE orders (order_id INT, order_date DATE, order_total DECIMAL, customer_id INT);"
    sql_query = generate_sql(question, schema)
    print(sql_query)

# Uploaded finetuned  model

- **Developed by:** iamkushagratomar
- **License:** apache-2.0
- **Finetuned from model :** unsloth/Qwen2.5-0.5B-Instruct-bnb-4bit

This qwen2 model was trained 2x faster with [Unsloth](https://github.com/unslothai/unsloth) and Huggingface's TRL library.

[<img src="https://raw.githubusercontent.com/unslothai/unsloth/main/images/unsloth%20made%20with%20love.png" width="200"/>](https://github.com/unslothai/unsloth)