NSQL is a family of autoregressive open-source large foundation models (FMs) designed specifically for SQL generation tasks.
In this repository we are introducing a new member of NSQL, SambaCoder-nsql-llama-2-70b. It's based on Meta's original
Llama-2 70B model and further pre-trained on a dataset of general SQL queries and then fine-tuned on a dataset composed of text-to-SQL pairs.
Use of this model is governed by the Meta’s Llama 2 Community License Agreement. Please review and accept the license before downloading the model weights and tokenizer
The general SQL queries are the SQL subset from
The Stack, containing 1M training samples. The labeled text-to-SQL pairs come from the NSText2SQL dataset (
https://huggingface.co/datasets/NumbersStation/NSText2SQL).
We evaluate our models on three text-to-SQL benchmarks: Spider, Bird, and text2sql.
SambaCoder-nsql-llama-2-70b was trained using cross-entropy loss to maximize the likelihood of sequential inputs. For finetuning on text-to-SQL pairs, we only compute the loss over the SQL portion of the pair. The model is trained using SambaNova's in-house Reconfigurable Dataflow Unit (RDU), leveraging data and model parallelism. We pre-trained for 2 epochs and fine-tuned for 10 epochs.
The model was designed for text-to-SQL generation tasks from given table schema and natural language prompts. The model works best with the prompt format defined below and outputting SELECT queries.
1import torch
2from transformers import AutoTokenizer, AutoModelForCausalLM
3tokenizer = AutoTokenizer.from_pretrained("sambanovasystems/SambaCoder-nsql-llama-2-70b")
4model = AutoModelForCausalLM.from_pretrained("sambanovasystems/SambaCoder-nsql-llama-2-70b", torch_dtype=torch.bfloat16)
5text = "CREATE TABLE stadium (
6 stadium_id number,
7 location text,
8 name text,
9 capacity number,
10 highest number,
11 lowest number,
12 average number
13)
14
15CREATE TABLE singer (
16 singer_id number,
17 name text,
18 country text,
19 song_name text,
20 song_release_year text,
21 age number,
22 is_male others
23)
24
25CREATE TABLE concert (
26 concert_id number,
27 concert_name text,
28 theme text,
29 stadium_id text,
30 year text
31)
32
33CREATE TABLE singer_in_concert (
34 concert_id number,
35 singer_id text
36)
37
38
39-- Using valid SQLite, answer the following questions for the tables provided above.
40
41-- What is the average, minimum, and maximum age of all singers from France?
42SELECT"
43input_ids = tokenizer(text, return_tensors="pt").input_ids
44
45generated_ids = model.generate(input_ids, max_length=500)
46print(tokenizer.decode(generated_ids[0], skip_special_tokens=True))