21 yesterday

A highly optimized, fine-tuned Qwen2.5-Coder-1.5B model specifically trained to accurately translate natural language into raw SQL queries.

ollama run mohamedelawakey/sql_coder

Details

1 week ago

5e96207867dd · 986MB

qwen2
·
1.54B
·
Q4_K_M
Below is an instruction that describes a task, paired with an input that provides further context. W
You Are a Smart SQL Assistant & Staff DB Engineer. Generate a SQL Query
{ "num_ctx": 4096, "stop": [ "### Instruction:", "### Input:", "###

Readme

SQL Coder - Fine-Tuned Text-to-SQL Assistant

A highly optimized, fine-tuned series of Qwen2.5-Coder models, specifically trained to act as a Senior Staff Database Engineer. These models translate natural language questions into accurate, production-ready, raw SQL queries.

🚀 Available Versions

This repository contains multiple versions of the model. You can specify the version you want to use via tags:

1. sql_coder_v3:latest (Recommended & Most Powerful) 🔥

  • Base Model: Qwen2.5-Coder-3B-Instruct
  • Status: Active & Highly Capable
  • Overview: The ultimate version! Trained on a massive 100,000+ example dataset with advanced Noise-Injection techniques to handle incredibly noisy production database schemas. It features Zero-Chat Formatting (100% adherence), meaning it outputs only raw SQL without any conversational filler, making it immediately production-ready for automated backend pipelines.
  • Command: ollama run sql_coder_v3:latest

2. sql_coder:v2 (Legacy)

  • Base Model: Qwen2.5-Coder-1.5B
  • Status: Deprecated
  • Overview: Fine-tuned on a combined dataset of WikiSQL and Spider. While it understands database schemas, it suffers from “Chatty Format” issues (outputting conversational text alongside SQL) which can crash automated execution engines.
  • Command: ollama run mohamedelawakey/sql_coder:v2

3. sql_coder:latest (V1 - Prototype)

  • Base Model: Qwen2.5-Coder-1.5B
  • Status: Deprecated / Weak
  • Overview: The initial experimental version. It struggles with complex schemas, advanced joins, and frequently hallucinates non-existent columns. Kept only for historical comparison.
  • Command: ollama run mohamedelawakey/sql_coder:latest

⚡ How to Use

You can run any of the versions locally using Ollama by specifying the correct tag:

For V3 (Recommended):

ollama run sql_coder_v3:latest

For V2:

ollama run mohamedelawakey/sql_coder:v2

For V1:

ollama run mohamedelawakey/sql_coder:latest

💡 Example Usage

🎯 Example Usage (For V3)

Because V3 was highly optimized using a very specific simulated Database Schema format, you MUST format your prompts exactly as shown below to get accurate results. The model has been stripped of unnecessary conversational abilities to output raw, syntactically correct SQL queries.

Always provide your schema and question in this exact format:

>>> Tables: CREATE TABLE items (
...   [notes] VARCHAR,
...   [Year] VARCHAR
... )
... Question: How much is the purse worth after 2012?
... 
SELECT SUM(Purse) FROM items WHERE Year > 2012

🎯 Example Usage (For V1 & V2)

In the older versions, providing a schema was optional but recommended. You could ask direct questions like this:

>>> what is the nationality of the player messi?
SELECT Nationality FROM table WHERE Player = 'messi'
>>> count the number of red cars ordered in 2023
SELECT COUNT(Car) FROM table WHERE Color = 'Red' AND Year = 2023

📊 Performance & Evaluation

Evaluated locally across graded test batches (200 queries) ranging from simple aggregations to complex intersections (Level 1 to Level 5).

V3 Benchmarks

  • Absolute Logic Accuracy (~75%): Rivals much larger models (7B+) in handling deep relational logic, multi-table joins, and complex subqueries.
  • Format Adherence (100%): Achieved perfect “Zero-Chat” output across all tests, making it fully crash-proof for automated APIs.
  • Fast Inference: Averages ~0.5s per query generation on standard local hardware.
  • Context Handling: Optimized with a 4096 context window to process complex, multi-table database schemas without losing focus.

V2 Benchmarks

  • Usable Accuracy (~30%): While the model understands database schemas and basic SQL, its actual usability drops significantly due to “Chatty Format” issues (wrapping outputs in markdown or conversational text).
  • Fast Inference: ~0.4s per query generation on average hardware.
  • Context Handling: Processes complex schemas but occasionally struggles with deep relational logic.

V1 Benchmarks

  • Accuracy (Low): Heavily biased towards simple queries and frequently hallucinates non-existent columns.
  • Fast Inference: ~0.4s per query generation.
  • Context Handling: Struggles to maintain focus on complex schemas.

Model Details

  • Base Models: Qwen2.5-Coder-3B-Instruct (V3) / Qwen2.5-Coder-1.5B (V1, V2)
  • Quantization: Q4_K_M (GGUF) for extreme memory efficiency and fast local inference.
  • Fine-Tuning Framework: Unsloth & LoRA