--- base_model: deepseek-ai/deepseek-coder-6.7b-instruct tags: - SOLAR - instruct - finetune model-index: - name: NaturalQuery-Solar-6.7B-v0.1 results: [] license: apache-2.0 language: - en datasets: - wikisql --- # **NaturalQuery-Solar-6.7B-v0.1** **NaturalQuery** is a LLM that can translate natural language queries to SQL based on your schema. NaturalQuery-v0.1 is finetuned on 8k text to PostgreSQL Natural Language <> SQL pairs. **Future Improvements**: - Much larger training set - More complex schemas, questions, and queries - Reward modeling via DPO - Benchmarking # **Usage** Make sure you have the correct version of the transformers library installed: ```sh pip install transformers==4.35.2 ``` ### **Loading the Model** Use the following Python code to load the model: ```python import torch from transformers import AutoModelForCausalLM, AutoTokenizer tokenizer = AutoTokenizer.from_pretrained("cfahlgren1/NaturalSQL-6.7B-v0") model = AutoModelForCausalLM.from_pretrained( "cfahlgren1/NaturalSQL-6.7B-v0", device_map="auto", torch_dtype=torch.float16, ) ``` ### **Generating Text** To generate text, use the following Python code: ```python text = "Hi, my name is " inputs = tokenizer(text, return_tensors="pt") outputs = model.generate(**inputs, max_new_tokens=64) print(tokenizer.decode(outputs[0], skip_special_tokens=True)) ``` # **SQL Generation Template** ``` ### Task Generate a SQL query to answer the following question: `{natural language question}` ### Database Schema The query will run on a database with the following schema: ''' ''' ### Answer Here is the SQL query that answers the question: `{natural language question}` '''sql ``` # **Example SQL Output** ### **Example Schemas** ```sql CREATE TABLE table_1_11545282_6 ( "No." numeric, Nationality text, "Years for Jazz" text ); CREATE TABLE table_2_17383560_1 ( Pick numeric, Round numeric, Player text, "School/Club Team" text, Position text ); CREATE TABLE table_1_10581768_2 ( Institution text, Enrollment numeric, Nickname text, Founded numeric ); ``` **Question**: **What is the round of pick 63?** ```sql SELECT "Round" FROM table_2_17383560_1 WHERE Pick=63; ``` **Question**: **What is the most popular position among players?** ```sql SELECT COUNT("Position") FROM "table_2_17383560_1" GROUP BY "Position" ORDER BY COUNT("Position") DESC LIMIT 1; ``` **Question**: **What is the most recent year an institution was founded?** ```sql SELECT MAX("Founded") FROM table_1_10581768_2; ```