Instructions to use juierror/flan-t5-text2sql-with-schema-v2 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use juierror/flan-t5-text2sql-with-schema-v2 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="juierror/flan-t5-text2sql-with-schema-v2")# Load model directly from transformers import AutoTokenizer, AutoModelForSeq2SeqLM tokenizer = AutoTokenizer.from_pretrained("juierror/flan-t5-text2sql-with-schema-v2") model = AutoModelForSeq2SeqLM.from_pretrained("juierror/flan-t5-text2sql-with-schema-v2") - Notebooks
- Google Colab
- Kaggle
- Local Apps
- vLLM
How to use juierror/flan-t5-text2sql-with-schema-v2 with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "juierror/flan-t5-text2sql-with-schema-v2" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "juierror/flan-t5-text2sql-with-schema-v2", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/juierror/flan-t5-text2sql-with-schema-v2
- SGLang
How to use juierror/flan-t5-text2sql-with-schema-v2 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 "juierror/flan-t5-text2sql-with-schema-v2" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "juierror/flan-t5-text2sql-with-schema-v2", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'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 "juierror/flan-t5-text2sql-with-schema-v2" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "juierror/flan-t5-text2sql-with-schema-v2", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use juierror/flan-t5-text2sql-with-schema-v2 with Docker Model Runner:
docker model run hf.co/juierror/flan-t5-text2sql-with-schema-v2
The results are a little off.
I tried it with this input "convert question and table into SQL query. tables: student_name(id,name), student_age(student_id,age). question: how many students with name jui and age less than 25"
I get "SELECT count(*) FROM student_name WHERE name = 'jui' AND age < 25". I just renamed the input parameters, didn't change the overall structure of the tables.
@moon-cake22 Thank you very much for the testing.
I notice this point as well. The current result is not good for some type of table. I will try to improve it further.
Sorry for late reply, here is the code
https://github.com/juierror/flan-t5-text-to-sql/blob/main/flan_t5_text2sql_multi_table.ipynb
Thank you!
Thanks for letting us play around with the model. Here is another prompt that came out wrong, if you want more training material:
print(inference(
"Among the artists having concerts in year 2020, which artist has a song whose title equals the name of the stadium on which the concert takes place?",
{
"stadium": ["stadium_id", "location", "name", "capacity", "highest", "lowest", "average"],
"singer": ["singer_id", "name", "country", "song_name"],
"concert": ["concert_id", "stadium_id", "year"],
"singer_in_concert": ["concert_id", "singer_id"]
}))
Returned (which would not work):
SELECT T1.song_name
FROM singer AS T1
JOIN concert AS T2 ON T1.singer_id = T2.singer_id
WHERE T2.year = 2020
AND T1.stadium_id = (
SELECT stadium_id FROM concert WHERE YEAR = 2020
)
To be frank, I still did not have a time to retrain the model. The current model is still not updated.