Text Generation
Transformers
Safetensors
qwen2
Generated from Trainer
open-r1
Text2SQL
Reasoning
conversational
text-generation-inference
Instructions to use simone-papicchio/Think2SQL-7B with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use simone-papicchio/Think2SQL-7B with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="simone-papicchio/Think2SQL-7B") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("simone-papicchio/Think2SQL-7B") model = AutoModelForCausalLM.from_pretrained("simone-papicchio/Think2SQL-7B") messages = [ {"role": "user", "content": "Who are you?"}, ] inputs = tokenizer.apply_chat_template( messages, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors="pt", ).to(model.device) outputs = model.generate(**inputs, max_new_tokens=40) print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps
- vLLM
How to use simone-papicchio/Think2SQL-7B with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "simone-papicchio/Think2SQL-7B" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "simone-papicchio/Think2SQL-7B", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/simone-papicchio/Think2SQL-7B
- SGLang
How to use simone-papicchio/Think2SQL-7B with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "simone-papicchio/Think2SQL-7B" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "simone-papicchio/Think2SQL-7B", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "simone-papicchio/Think2SQL-7B" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "simone-papicchio/Think2SQL-7B", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use simone-papicchio/Think2SQL-7B with Docker Model Runner:
docker model run hf.co/simone-papicchio/Think2SQL-7B
Create README.md
Browse files
README.md
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: apache-2.0
|
| 3 |
+
base_model:
|
| 4 |
+
- Qwen/Qwen2.5-Coder-7B-Instruct
|
| 5 |
+
---
|
| 6 |
+
|
| 7 |
+
## Model Information
|
| 8 |
+
This model is the reasoning model for Text2SQL task introduced in [Think2SQL: Reinforce LLM Reasoning Capabilities for Text2SQL](https://arxiv.org/abs/2504.15077)
|
| 9 |
+
|
| 10 |
+
## Intended use
|
| 11 |
+
The best model performance are given with its System and User prompt.
|
| 12 |
+
The model is intended to use with three input: question, evidence and the database schema.
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
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.
|
| 16 |
+
|
| 17 |
+
Make sure to update your transformers installation via `pip install --upgrade transformers`.
|
| 18 |
+
|
| 19 |
+
```python
|
| 20 |
+
import transformers
|
| 21 |
+
import torch
|
| 22 |
+
model_id = "simone-papicchio/Think2SQL-7B"
|
| 23 |
+
pipeline = transformers.pipeline(
|
| 24 |
+
"text-generation",
|
| 25 |
+
model=model_id,
|
| 26 |
+
model_kwargs={"torch_dtype": torch.bfloat16},
|
| 27 |
+
device_map="auto",
|
| 28 |
+
)
|
| 29 |
+
|
| 30 |
+
system_message = (
|
| 31 |
+
"You are a helpful AI Assistant that provides well-reasoned and detailed responses. "
|
| 32 |
+
"You first think about the reasoning process as an internal monologue and then provide the user with the answer. "
|
| 33 |
+
"Respond in the following format: <think>\n...\n</think>\n<answer>\n...\n</answer>"
|
| 34 |
+
).strip()
|
| 35 |
+
|
| 36 |
+
user_message = (
|
| 37 |
+
"Answer the following question with the SQL code. Use the piece of evidence and base your answer on the database schema. "
|
| 38 |
+
"Given the question, the evidence and the database schema, return in the <answer> tags only the SQL script that addresses the question.\n"
|
| 39 |
+
"Question:\n{question}\n\n"
|
| 40 |
+
"Evidence:\n{evidence}\n\n"
|
| 41 |
+
"Database Schema:\n{schema}\n\n"
|
| 42 |
+
"Return only the SQL script enclosed in <answer> tags."
|
| 43 |
+
).strip()
|
| 44 |
+
|
| 45 |
+
messages = [
|
| 46 |
+
{"role": "system", "content": system_message},
|
| 47 |
+
{"role": "user", "content": user_message},
|
| 48 |
+
]
|
| 49 |
+
|
| 50 |
+
outputs = pipeline(
|
| 51 |
+
messages,
|
| 52 |
+
max_new_tokens=256,
|
| 53 |
+
)
|
| 54 |
+
print(outputs[0]["generated_text"][-1])
|
| 55 |
+
```
|
| 56 |
+
|
| 57 |
+
|
| 58 |
+
## Citation
|
| 59 |
+
```bitex
|
| 60 |
+
@misc{papicchio2025think2sqlreinforcellmreasoning,
|
| 61 |
+
title={Think2SQL: Reinforce LLM Reasoning Capabilities for Text2SQL},
|
| 62 |
+
author={Simone Papicchio and Simone Rossi and Luca Cagliero and Paolo Papotti},
|
| 63 |
+
year={2025},
|
| 64 |
+
eprint={2504.15077},
|
| 65 |
+
archivePrefix={arXiv},
|
| 66 |
+
primaryClass={cs.LG},
|
| 67 |
+
url={https://arxiv.org/abs/2504.15077},
|
| 68 |
+
}
|
| 69 |
+
```
|
| 70 |
+
|