This model is a fine-tuned version of
Qwen/Qwen3-14B with thinking disabled on the
BIRD dataset.
It has been trained using
TRL.
The best model performance is given with its System and User prompts.
The model is intended to be used with three inputs: question, evidence, and the database schema.
1import transformers
2import torch
3model_id = "anonymous-2321/Think2SQL-14B"
4pipeline = transformers.pipeline(
5 "text-generation",
6 model=model_id,
7 model_kwargs={"torch_dtype": torch.bfloat16},
8 device_map="auto",
9)
10
11system_message ="""
12You are a data science expert that provides well-reasoned and detailed responses. Your task is to understand the schema and generate a valid SQL query to answer the question.
13You first think about the reasoning process as an internal monologue and then provide the user with the answer.
14Respond in the following format:
15<reasoning>
16 ...
17</reasoning>
18<answer>
19 ...
20</answer>
21""".strip()
22
23user_message = """
24Answer the following question with the SQL code. Use the piece of evidence and base your answer on the database schema.
25Given the question, the evidence and the database schema, return in the <answer> tags only the SQL script that addresses the question.
26
27Database Engine:
28SQLite
29
30Question:
31Return the product name, sorted alphabetically and by price in descending order.
32
33
34Evidence:
35
36
37Database Schema:
38CREATE TABLE products (
39 id INTEGER PRIMARY KEY,
40 name TEXT NOT NULL,
41 price REAL NOT NULL
42);
43
44CREATE TABLE customers (
45 id INTEGER PRIMARY KEY,
46 name TEXT NOT NULL,
47 email TEXT NOT NULL
48);
49"""
50
51
52messages = [
53 {"role": "system", "content": system_message},
54 {"role": "user", "content": user_message},
55]
56
57outputs = pipeline(
58 messages,
59 max_new_tokens=4096,
60 temperature=0.6,
61 top_p=0.95,
62 top_k=20
63)
64print(outputs[0]["generated_text"][-1])
Think2SQL is a systematic study on injecting reasoning capabilities into Text-to-SQL through Reinforcement Learning with Verifiable Rewards (RLVR). We uncover the critical interplay between reward density, advantage scaling, and model capacity, proposing novel execution-guided dense rewards and optimal scaling strategies. Our 4B-parameter model achieves reasoning capabilities competitive with state-of-the-art models, while providing a comprehensive analysis for optimizing Text-to-SQL reasoning under computational constraints.