gabrielpondc/NL2SQL-StarCoder-15B
Model Card for NL2SQL-StarCoder-15B
Model Inro
NL2SQL-StarCoder-15B is a NLP-SQL model fintuned by QLoRA based on StarCoder 15B Code-LLM。
Requirements
- python>=3.8
- pytorch>=2.0.0
- transformers==4.32.0
- CUDA 11.4
Data Format
The data is in the form of a string spliced by the model in the training data format, which is also how the input PROMPT is spliced during inference:
"""
<|user|>
/* Given the following database schema: */
CREATE TABLE "table_name" (
"col1" int,
...
...
)
/* Write a sql to answer the following question: {Question} */
<|assistant|>{Output SQL}
"""But from test we recomended using the promt what sqlcoder was given:
### Instructions:
Your task is to convert a question into a SQL query, given a Postgres database schema.
Adhere to these rules:
- **Deliberately go through the question and database schema word by word** to appropriately answer the question
- **Use Table Aliases** to prevent ambiguity. For example, `SELECT table1.col1, table2.col1 FROM table1 JOIN table2 ON table1.id = table2.id`.
- When creating a ratio, always cast the numerator as float
### Input:
Generate a SQL query that answers the question `{question}`.
This query will run on a database whose schema is represented in this string:
CREATE TABLE "table_name" (
"col1" int,
...
...
)
### Response:
Based on your instructions, here is the SQL query I have generated to answer the question `{question}`:
## Quick Start
import torch from transformers import AutoModelForCausalLM, AutoTokenizer modeldir = "gabrielpondc/NL2SQL-StarCoder-15B" tokenizer = AutoTokenizer.frompretrained(modeldir, devicemap="auto", trustremotecode=True, torchdtype=torch.float16) tokenizer.paddingside = "left" tokenizer.padtokenid = tokenizer.converttokenstoids("<fimpad>") tokenizer.eostokenid = tokenizer.converttokenstoids("<|endoftext|>") tokenizer.padtoken = "<fimpad>" tokenizer.eostoken = "<|endoftext|>"
model = AutoModelForCausalLM.frompretrained(modeldir, devicemap="auto", trustremotecode=True, torchdtype=torch.float16) model.eval()
text = '<|user|>\n/ Given the following database schema: /\nCREATE TABLE "singer" (\n"SingerID" int,\n"Name" text,\n"Country" text,\n"SongName" text,\n"Songreleaseyear" text,\n"Age" int,\n"Ismale" bool,\nPRIMARY KEY ("SingerID")\n)\n\n/ Write a sql to answer the following question: Show countries where a singer above age 40 and a singer below 30 are from. /<|end|>\n' inputs = tokenizer(text, returntensors='pt', padding=True, addspecialtokens=False).to("cuda") outputs = model.generate( inputs=inputs["inputids"], attentionmask=inputs["attentionmask"], maxnewtokens=512, topp=0.95, temperature=0.1, dosample=False, eostokenid=tokenizer.eostokenid, padtokenid=tokenizer.padtokenid ) gentext = tokenizer.batchdecode(outputs[:, inputs["inputids"].shape[1]:], skipspecialtokens=True) print(gentext)
