senwu commited on
Commit
6146518
0 Parent(s):

initial commit

Browse files
.gitattributes ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ *.7z filter=lfs diff=lfs merge=lfs -text
2
+ *.arrow filter=lfs diff=lfs merge=lfs -text
3
+ *.bin filter=lfs diff=lfs merge=lfs -text
4
+ *.bz2 filter=lfs diff=lfs merge=lfs -text
5
+ *.ckpt filter=lfs diff=lfs merge=lfs -text
6
+ *.ftz filter=lfs diff=lfs merge=lfs -text
7
+ *.gz filter=lfs diff=lfs merge=lfs -text
8
+ *.h5 filter=lfs diff=lfs merge=lfs -text
9
+ *.joblib filter=lfs diff=lfs merge=lfs -text
10
+ *.lfs.* filter=lfs diff=lfs merge=lfs -text
11
+ *.mlmodel filter=lfs diff=lfs merge=lfs -text
12
+ *.model filter=lfs diff=lfs merge=lfs -text
13
+ *.msgpack filter=lfs diff=lfs merge=lfs -text
14
+ *.npy filter=lfs diff=lfs merge=lfs -text
15
+ *.npz filter=lfs diff=lfs merge=lfs -text
16
+ *.onnx filter=lfs diff=lfs merge=lfs -text
17
+ *.ot filter=lfs diff=lfs merge=lfs -text
18
+ *.parquet filter=lfs diff=lfs merge=lfs -text
19
+ *.pb filter=lfs diff=lfs merge=lfs -text
20
+ *.pickle filter=lfs diff=lfs merge=lfs -text
21
+ *.pkl filter=lfs diff=lfs merge=lfs -text
22
+ *.pt filter=lfs diff=lfs merge=lfs -text
23
+ *.pth filter=lfs diff=lfs merge=lfs -text
24
+ *.rar filter=lfs diff=lfs merge=lfs -text
25
+ *.safetensors filter=lfs diff=lfs merge=lfs -text
26
+ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
27
+ *.tar.* filter=lfs diff=lfs merge=lfs -text
28
+ *.tar filter=lfs diff=lfs merge=lfs -text
29
+ *.tflite filter=lfs diff=lfs merge=lfs -text
30
+ *.tgz filter=lfs diff=lfs merge=lfs -text
31
+ *.wasm filter=lfs diff=lfs merge=lfs -text
32
+ *.xz filter=lfs diff=lfs merge=lfs -text
33
+ *.zip filter=lfs diff=lfs merge=lfs -text
34
+ *.zst filter=lfs diff=lfs merge=lfs -text
35
+ *tfevents* filter=lfs diff=lfs merge=lfs -text
README.md ADDED
@@ -0,0 +1,150 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: bsd-3-clause
3
+ inference:
4
+ parameters:
5
+ do_sample: false
6
+ max_length: 200
7
+ widget:
8
+ - text: "CREATE TABLE stadium (\n stadium_id number,\n location text,\n name text,\n capacity number,\n)\n\n-- Using valid SQLite, answer the following questions for the tables provided above.\n\n-- how many stadiums in total?\n\nSELECT"
9
+ example_title: "Number stadiums"
10
+ - text: "CREATE TABLE work_orders ( ID NUMBER, CREATED_AT TEXT, COST FLOAT, INVOICE_AMOUNT FLOAT, IS_DUE BOOLEAN, IS_OPEN BOOLEAN, IS_OVERDUE BOOLEAN, COUNTRY_NAME TEXT, )\n\n-- Using valid SQLite, answer the following questions for the tables provided above.\n\n-- how many work orders are open?\n\nSELECT"
11
+ example_title: "Open work orders"
12
+ - text: "CREATE TABLE stadium ( stadium_id number, location text, name text, capacity number, highest number, lowest number, average number )\n\nCREATE TABLE singer ( singer_id number, name text, country text, song_name text, song_release_year text, age number, is_male others )\n\nCREATE TABLE concert ( concert_id number, concert_name text, theme text, stadium_id text, year text )\n\nCREATE TABLE singer_in_concert ( concert_id number, singer_id text )\n\n-- Using valid SQLite, answer the following questions for the tables provided above.\n\n-- What is the maximum, the average, and the minimum capacity of stadiums ?\n\nSELECT"
13
+ example_title: "Stadium capacity"
14
+ ---
15
+
16
+ # NSQL (NSQL-350M)
17
+
18
+ ## Model Description
19
+
20
+ NSQL is a family of autoregressive open-source large foundation models (FMs) designed specifically for SQL generation tasks.
21
+
22
+ The checkpoint included in this repository is based on [CodeGen-Multi 350M](https://huggingface.co/Salesforce/codegen-350M-multi) from Salesforce and further pre-trained on a dataset of general SQL queries and then fine-tuned on a dataset composed of text-to-SQL pairs.
23
+
24
+ ## Training Data
25
+
26
+ The general SQL queries are the SQL subset from [The Stack](https://huggingface.co/datasets/bigcode/the-stack), containing 1M training samples. The labeled text-to-SQL pairs come from more than 20 public sources across the web from standard datasets. We hold out Spider and GeoQuery datasets for use in evaluation.
27
+
28
+ ## Evaluation Data
29
+
30
+ We evaluate our models on two text-to-SQL benchmarks: Spider and GeoQuery.
31
+
32
+ ## Training Procedure
33
+
34
+ NSQL 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 family of models is trained using 80GB A100s, leveraging data and model parallelism. We pre-trained for 3 epochs and fine-tuned for 10 epochs.
35
+
36
+ ## Intended Use and Limitations
37
+
38
+ 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.
39
+
40
+ ## How to Use
41
+
42
+ Example 1:
43
+
44
+ ```python
45
+ from transformers import AutoTokenizer, AutoModelForCausalLM
46
+ tokenizer = AutoTokenizer.from_pretrained("NumbersStation/nsql-350M")
47
+ model = AutoModelForCausalLM.from_pretrained("NumbersStation/nsql-350M")
48
+
49
+ text = """CREATE TABLE stadium (
50
+ stadium_id number,
51
+ location text,
52
+ name text,
53
+ capacity number,
54
+ highest number,
55
+ lowest number,
56
+ average number
57
+ )
58
+
59
+ CREATE TABLE singer (
60
+ singer_id number,
61
+ name text,
62
+ country text,
63
+ song_name text,
64
+ song_release_year text,
65
+ age number,
66
+ is_male others
67
+ )
68
+
69
+ CREATE TABLE concert (
70
+ concert_id number,
71
+ concert_name text,
72
+ theme text,
73
+ stadium_id text,
74
+ year text
75
+ )
76
+
77
+ CREATE TABLE singer_in_concert (
78
+ concert_id number,
79
+ singer_id text
80
+ )
81
+
82
+ -- Using valid SQLite, answer the following questions for the tables provided above.
83
+
84
+ -- What is the maximum, the average, and the minimum capacity of stadiums ?
85
+
86
+ SELECT"""
87
+
88
+ input_ids = tokenizer(text, return_tensors="pt").input_ids
89
+
90
+ generated_ids = model.generate(input_ids, max_length=500)
91
+ print(tokenizer.decode(generated_ids[0], skip_special_tokens=True))
92
+ ```
93
+
94
+ Example 2:
95
+
96
+ ```python
97
+ from transformers import AutoTokenizer, AutoModelForCausalLM
98
+ tokenizer = AutoTokenizer.from_pretrained("NumbersStation/nsql-350M")
99
+ model = AutoModelForCausalLM.from_pretrained("NumbersStation/nsql-350M")
100
+
101
+ text = """CREATE TABLE stadium (
102
+ stadium_id number,
103
+ location text,
104
+ name text,
105
+ capacity number,
106
+ )
107
+
108
+ -- Using valid SQLite, answer the following questions for the tables provided above.
109
+
110
+ -- how many stadiums in total?
111
+
112
+ SELECT"""
113
+
114
+ input_ids = tokenizer(text, return_tensors="pt").input_ids
115
+
116
+ generated_ids = model.generate(input_ids, max_length=500)
117
+ print(tokenizer.decode(generated_ids[0], skip_special_tokens=True))
118
+ ```
119
+
120
+ Example 3:
121
+
122
+ ```python
123
+ from transformers import AutoTokenizer, AutoModelForCausalLM
124
+ tokenizer = AutoTokenizer.from_pretrained("NumbersStation/nsql-350M")
125
+ model = AutoModelForCausalLM.from_pretrained("NumbersStation/nsql-350M")
126
+
127
+ text = """CREATE TABLE work_orders (
128
+ ID NUMBER,
129
+ CREATED_AT TEXT,
130
+ COST FLOAT,
131
+ INVOICE_AMOUNT FLOAT,
132
+ IS_DUE BOOLEAN,
133
+ IS_OPEN BOOLEAN,
134
+ IS_OVERDUE BOOLEAN,
135
+ COUNTRY_NAME TEXT,
136
+ )
137
+
138
+ -- Using valid SQLite, answer the following questions for the tables provided above.
139
+
140
+ -- how many work orders are open?
141
+
142
+ SELECT"""
143
+
144
+ input_ids = tokenizer(text, return_tensors="pt").input_ids
145
+
146
+ generated_ids = model.generate(input_ids, max_length=500)
147
+ print(tokenizer.decode(generated_ids[0], skip_special_tokens=True))
148
+ ```
149
+
150
+ For more information (e.g., run with your local database), please find examples in [this repository](https://github.com/NumbersStationAI/NSQL).
added_tokens.json ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "\t\t": 50294,
3
+ "\t\t\t": 50293,
4
+ "\t\t\t\t": 50292,
5
+ "\t\t\t\t\t": 50291,
6
+ "\t\t\t\t\t\t": 50290,
7
+ "\t\t\t\t\t\t\t": 50289,
8
+ "\t\t\t\t\t\t\t\t": 50288,
9
+ "\t\t\t\t\t\t\t\t\t": 50287,
10
+ " ": 50286,
11
+ " ": 50285,
12
+ " ": 50284,
13
+ " ": 50283,
14
+ " ": 50282,
15
+ " ": 50281,
16
+ " ": 50280,
17
+ " ": 50279,
18
+ " ": 50278,
19
+ " ": 50277,
20
+ " ": 50276,
21
+ " ": 50275,
22
+ " ": 50274,
23
+ " ": 50273,
24
+ " ": 50272,
25
+ " ": 50271,
26
+ " ": 50270,
27
+ " ": 50269,
28
+ " ": 50268,
29
+ " ": 50267,
30
+ " ": 50266,
31
+ " ": 50265,
32
+ " ": 50264,
33
+ " ": 50263,
34
+ " ": 50262,
35
+ " ": 50261,
36
+ " ": 50260,
37
+ " ": 50259,
38
+ " ": 50258,
39
+ " ": 50257
40
+ }
config.json ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_name_or_path": "nsql-350M",
3
+ "activation_function": "gelu_new",
4
+ "architectures": [
5
+ "CodeGenForCausalLM"
6
+ ],
7
+ "attn_pdrop": 0.0,
8
+ "bos_token_id": 1,
9
+ "embd_pdrop": 0.0,
10
+ "eos_token_id": 50256,
11
+ "gradient_checkpointing": false,
12
+ "initializer_range": 0.02,
13
+ "layer_norm_epsilon": 1e-05,
14
+ "model_type": "codegen",
15
+ "n_ctx": 2048,
16
+ "n_embd": 1024,
17
+ "n_head": 16,
18
+ "n_inner": null,
19
+ "n_layer": 20,
20
+ "n_positions": 2048,
21
+ "pad_token_id": 50256,
22
+ "resid_pdrop": 0.0,
23
+ "rotary_dim": 32,
24
+ "scale_attn_weights": true,
25
+ "summary_activation": null,
26
+ "summary_first_dropout": 0.1,
27
+ "summary_proj_to_labels": true,
28
+ "summary_type": "cls_index",
29
+ "summary_use_proj": true,
30
+ "task_specific_params": {
31
+ "text-generation": {
32
+ "do_sample": true,
33
+ "max_length": 50,
34
+ "temperature": 1.0
35
+ }
36
+ },
37
+ "tie_word_embeddings": false,
38
+ "tokenizer_class": "GPT2Tokenizer",
39
+ "torch_dtype": "float32",
40
+ "transformers_version": "4.28.1",
41
+ "use_cache": true,
42
+ "vocab_size": 51200
43
+ }
generation_config.json ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ {
2
+ "_from_model_config": true,
3
+ "bos_token_id": 1,
4
+ "eos_token_id": 50256,
5
+ "transformers_version": "4.28.1"
6
+ }
merges.txt ADDED
The diff for this file is too large to render. See raw diff
 
pytorch_model.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:f333ac3d1d5dcb2e1230f14bd3e2c6bab8ed1259dc6cabe8caf990c30154c620
3
+ size 1510794225
special_tokens_map.json ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ {
2
+ "bos_token": "<|endoftext|>",
3
+ "eos_token": "<|endoftext|>",
4
+ "unk_token": "<|endoftext|>"
5
+ }
tokenizer.json ADDED
The diff for this file is too large to render. See raw diff
 
tokenizer_config.json ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "add_prefix_space": false,
3
+ "bos_token": "<|endoftext|>",
4
+ "clean_up_tokenization_spaces": true,
5
+ "eos_token": "<|endoftext|>",
6
+ "model_max_length": 2048,
7
+ "tokenizer_class": "CodeGenTokenizer",
8
+ "unk_token": "<|endoftext|>"
9
+ }
vocab.json ADDED
The diff for this file is too large to render. See raw diff