File size: 2,367 Bytes
1aa7668
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
---
license: apache-2.0
base_model:
- Qwen/Qwen2.5-Coder-7B-Instruct
---

## Model Information
This model is the reasoning model for Text2SQL task introduced in [Think2SQL: Reinforce LLM Reasoning Capabilities for Text2SQL](https://arxiv.org/abs/2504.15077)

## Intended use
The best model performance are given with its System and User prompt.
The model is intended to use with three input: question, evidence and the database schema. 


Starting with `transformers >= 4.43.0` onward, you can run conversational inference using the Transformers `pipeline` abstraction or by leveraging the Auto classes with the `generate()` function.

Make sure to update your transformers installation via `pip install --upgrade transformers`.

```python
import transformers
import torch
model_id = "simone-papicchio/Think2SQL-7B"
pipeline = transformers.pipeline(
    "text-generation",
    model=model_id,
    model_kwargs={"torch_dtype": torch.bfloat16},
    device_map="auto",
)

system_message = (
    "You are a helpful AI Assistant that provides well-reasoned and detailed responses. "
    "You first think about the reasoning process as an internal monologue and then provide the user with the answer. "
    "Respond in the following format: <think>\n...\n</think>\n<answer>\n...\n</answer>"
).strip()

user_message = (
    "Answer the following question with the SQL code. Use the piece of evidence and base your answer on the database schema. "
    "Given the question, the evidence and the database schema, return in the <answer> tags only the SQL script that addresses the question.\n"
    "Question:\n{question}\n\n"
    "Evidence:\n{evidence}\n\n"
    "Database Schema:\n{schema}\n\n"
    "Return only the SQL script enclosed in <answer> tags."
).strip()

messages = [
    {"role": "system", "content": system_message},
    {"role": "user", "content": user_message},
]

outputs = pipeline(
    messages,
    max_new_tokens=256,
)
print(outputs[0]["generated_text"][-1])
```


## Citation
```bitex
@misc{papicchio2025think2sqlreinforcellmreasoning,
      title={Think2SQL: Reinforce LLM Reasoning Capabilities for Text2SQL}, 
      author={Simone Papicchio and Simone Rossi and Luca Cagliero and Paolo Papotti},
      year={2025},
      eprint={2504.15077},
      archivePrefix={arXiv},
      primaryClass={cs.LG},
      url={https://arxiv.org/abs/2504.15077}, 
}
```