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. Install dependencies:

    pip install transformers torch
    
  2. Load the model:

     from transformers import AutoModelForCausalLM, AutoTokenizer
     import torch
     
     model_name = "iamkushagratomar/Qwen2.5-0.5B-text2sql"
     tokenizer = AutoTokenizer.from_pretrained(model_name)
     model = AutoModelForCausalLM.from_pretrained(model_name).to("cuda")
    
  3. Use the model (with your question + schema)::

    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 and Huggingface's TRL library.

Downloads last month
103
Safetensors
Model size
0.5B params
Tensor type
BF16
ยท
Inference Providers NEW
This model isn't deployed by any Inference Provider. ๐Ÿ™‹ Ask for provider support

Model tree for iamkushagratomar/Qwen2.5-0.5B-text2sql

Finetuned
(47)
this model