NaturalSQL-6.7B-v0 / README.md
cfahlgren1's picture
cfahlgren1 HF staff
Update README.md
20ece27
|
raw
history blame
No virus
2.94 kB
metadata
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:

pip install transformers==4.35.2

Loading the Model

Use the following Python code to load the model:

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:

messages=[
    { 'role': 'user', 'content': prompt}
]

inputs = tokenizer.apply_chat_template(messages, add_generation_prompt=True, return_tensors="pt").to(model.device)

# 32021 is the id of <|EOT|> token
outputs = model.generate(inputs, max_new_tokens=512, do_sample=False, top_k=50, top_p=0.95, num_return_sequences=1, eos_token_id=32021)

print(tokenizer.decode(outputs[0][len(inputs[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: 

'''
<SQL Table DDL Statements>
'''

### Answer 
Here is the SQL query that answers the question: `{natural language question}` 
'''sql

Example SQL Output

Example Schemas

 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?

SELECT "Round" FROM table_2_17383560_1 WHERE Pick=63;

Question: What is the most popular position among players?

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?

SELECT MAX("Founded") FROM table_1_10581768_2;