Instructions to use Omaratef3221/Qwen2-0.5B-Instruct-SQL-query-generator with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use Omaratef3221/Qwen2-0.5B-Instruct-SQL-query-generator with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="Omaratef3221/Qwen2-0.5B-Instruct-SQL-query-generator") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("Omaratef3221/Qwen2-0.5B-Instruct-SQL-query-generator") model = AutoModelForCausalLM.from_pretrained("Omaratef3221/Qwen2-0.5B-Instruct-SQL-query-generator") 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]:])) - Inference
- Notebooks
- Google Colab
- Kaggle
- Local Apps
- vLLM
How to use Omaratef3221/Qwen2-0.5B-Instruct-SQL-query-generator with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "Omaratef3221/Qwen2-0.5B-Instruct-SQL-query-generator" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Omaratef3221/Qwen2-0.5B-Instruct-SQL-query-generator", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/Omaratef3221/Qwen2-0.5B-Instruct-SQL-query-generator
- SGLang
How to use Omaratef3221/Qwen2-0.5B-Instruct-SQL-query-generator 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 "Omaratef3221/Qwen2-0.5B-Instruct-SQL-query-generator" \ --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": "Omaratef3221/Qwen2-0.5B-Instruct-SQL-query-generator", "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 "Omaratef3221/Qwen2-0.5B-Instruct-SQL-query-generator" \ --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": "Omaratef3221/Qwen2-0.5B-Instruct-SQL-query-generator", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use Omaratef3221/Qwen2-0.5B-Instruct-SQL-query-generator with Docker Model Runner:
docker model run hf.co/Omaratef3221/Qwen2-0.5B-Instruct-SQL-query-generator
Qwen2-0.5B-Instruct-SQL-query-generator
This model is a fine-tuned version of Qwen/Qwen2-0.5B-Instruct on the motherduckdb/duckdb-text2sql-25k dataset (first 10k rows).
Model Description
The Qwen2-0.5B-Instruct-SQL-query-generator is a specialized model fine-tuned to generate SQL queries from natural language text prompts. This fine-tuning allows the model to better understand and convert text inputs into corresponding SQL queries, facilitating tasks such as data retrieval and database querying through natural language interfaces.
Intended Uses & Limitations
Intended Uses
- Convert natural language questions to SQL queries.
- Facilitate data retrieval from databases using natural language.
- Assist in building natural language interfaces for databases.
Limitations
- The model is fine-tuned on a specific subset of data and may not generalize well to all SQL query formats or databases.
- It is recommended to review the generated SQL queries for accuracy and security, especially before executing them on live databases.
Training and Evaluation Data
Training Data
The model was fine-tuned on the motherduckdb/duckdb-text2sql-25k dataset, specifically using the first 10,000 rows. This dataset includes natural language questions and their corresponding SQL queries, providing a robust foundation for training a text-to-SQL model.
Evaluation Data
The evaluation data used for fine-tuning was a subset of the same dataset, ensuring consistency in training and evaluation metrics.
Training Procedure
Github Code: https://github.com/omaratef3221/SQL_Query_Generator_llm/
Training Hyperparameters
The following hyperparameters were used during training:
learning_rate: 1e-4train_batch_size: 8save_steps: 1logging_steps: 500num_epochs: 5
Training Frameworks
- Transformers: 4.39.0
- PyTorch: 2.2.0
- Datasets: 2.20.0
- Tokenizers: 0.15.2
Training Results
During the training process, the model was periodically evaluated to ensure it was learning effectively. The specific training metrics and results were logged for further analysis.
Model Performance
Evaluation Metrics
- Evaluation metrics such as accuracy, precision, recall, and F1-score were used to assess the model's performance. (Specific values can be added here if available.)
Usage
To use this model, simply load it from the Hugging Face Model Hub and provide natural language text prompts. The model will generate the corresponding SQL queries.
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
tokenizer = AutoTokenizer.from_pretrained("omaratef3221/Qwen2-0.5B-Instruct-SQL-query-generator")
model = AutoModelForSeq2SeqLM.from_pretrained("omaratef3221/Qwen2-0.5B-Instruct-SQL-query-generator")
inputs = tokenizer("Show me all employees with a salary greater than $100,000", return_tensors="pt")
outputs = model.generate(**inputs)
print(tokenizer.decode(outputs[0], skip_special_tokens=True))
- Downloads last month
- 32