munish0838 commited on
Commit
c901f37
1 Parent(s): 5af29ea

Upload README.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +159 -0
README.md ADDED
@@ -0,0 +1,159 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ ---
3
+
4
+ license: llama2
5
+ inference:
6
+ parameters:
7
+ do_sample: false
8
+ max_length: 200
9
+ base_model: meta-llama/Llama-2-7b
10
+ widget:
11
+ - text: "### Instruction:\nYour task is to generate valid duckdb SQL to answer the following question.\n\n### Input:\n\n### Question:\ncreate a new table called tmp from test.csv\n\n### Response (use duckdb shorthand if possible):"
12
+ example_title: "read test.csv"
13
+ - text: "### Instruction:\nYour task is to generate valid duckdb SQL to answer the following question.\n\n### Input:\n\n### Question:\ncreate a new table called tmp from test.csv\n\n### Response (use duckdb shorthand if possible):"
14
+ example_title: "get _amount columns"
15
+ - text: "### Instruction:\nYour task is to generate valid duckdb SQL to answer the following question, given a duckdb database schema.\n\n### Input:\nHere is the database schema that the SQL query will run on:\nCREATE TABLE rideshare (\n hvfhs_license_num varchar,\n dispatching_base_num varchar,\n originating_base_num varchar,\n request_datetime timestamp,\n on_scene_datetime timestamp,\n pickup_datetime timestamp,\n dropoff_datetime timestamp,\n trip_miles double,\n trip_time bigint,\n\n);\n\n### Question:\nget longest trip in december 2022\n\n### Response (use duckdb shorthand if possible):"
16
+ example_title: "taxi trips"
17
+
18
+ ---
19
+
20
+ [![QuantFactory Banner](https://lh7-rt.googleusercontent.com/docsz/AD_4nXeiuCm7c8lEwEJuRey9kiVZsRn2W-b4pWlu3-X534V3YmVuVc2ZL-NXg2RkzSOOS2JXGHutDuyyNAUtdJI65jGTo8jT9Y99tMi4H4MqL44Uc5QKG77B0d6-JfIkZHFaUA71-RtjyYZWVIhqsNZcx8-OMaA?key=xt3VSDoCbmTY7o-cwwOFwQ)](https://hf.co/QuantFactory)
21
+
22
+
23
+ # QuantFactory/DuckDB-NSQL-7B-v0.1-GGUF
24
+ This is quantized version of [motherduckdb/DuckDB-NSQL-7B-v0.1](https://huggingface.co/motherduckdb/DuckDB-NSQL-7B-v0.1) created using llama.cpp
25
+
26
+ # Original Model Card
27
+
28
+
29
+ # DuckDB-NSQL-7B
30
+
31
+ ## Model Description
32
+
33
+ NSQL is a family of autoregressive open-source large foundation models (FMs) designed specifically for SQL generation tasks.
34
+
35
+ In this repository we are introducing a new member of NSQL, DuckDB-NSQL. It's based on Meta's original [Llama-2 7B model](https://huggingface.co/meta-llama/Llama-2-7b) and further pre-trained on a dataset of general SQL queries and then fine-tuned on a dataset composed of DuckDB text-to-SQL pairs.
36
+
37
+ ## Training Data
38
+
39
+ 200k DuckDB text-to-SQL pairs, synthetically generated using [Mixtral-8x7B-Instruct-v0.1](https://huggingface.co/mistralai/Mixtral-8x7B-Instruct-v0.1), guided by the DuckDB v0.9.2 documentation. And text-to-SQL pairs from [NSText2SQL](https://huggingface.co/datasets/NumbersStation/NSText2SQL) that were transpiled to DuckDB SQL using [sqlglot](https://github.com/tobymao/sqlglot).
40
+
41
+ ## Evaluation Data
42
+
43
+ We evaluate our models on a DuckDB-specific benchmark that contains 75 text-to-SQL pairs. The benchmark is available [here](https://github.com/NumbersStationAI/DuckDB-NSQL/).
44
+
45
+ ## Training Procedure
46
+
47
+ DuckDB-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 model is trained using 80GB A100s, leveraging data and model parallelism. We fine-tuned for 10 epochs.
48
+
49
+ ## Intended Use and Limitations
50
+
51
+ 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 outputs.
52
+ In contrast to existing text-to-SQL models, the SQL generation is not contrained to `SELECT` statements, but can generate any valid DuckDB SQL statement, including statements for official DuckDB extensions.
53
+
54
+ ## How to Use
55
+
56
+ Example 1:
57
+
58
+ ```python
59
+ import torch
60
+ from transformers import AutoTokenizer, AutoModelForCausalLM
61
+ tokenizer = AutoTokenizer.from_pretrained("motherduckdb/DuckDB-NSQL-7B-v0.1")
62
+ model = AutoModelForCausalLM.from_pretrained("motherduckdb/DuckDB-NSQL-7B-v0.1", torch_dtype=torch.bfloat16)
63
+
64
+ text = """### Instruction:
65
+ Your task is to generate valid duckdb SQL to answer the following question.
66
+
67
+ ### Input:
68
+
69
+ ### Question:
70
+ create a new table called tmp from test.csv
71
+
72
+ ### Response (use duckdb shorthand if possible):
73
+ """
74
+
75
+ input_ids = tokenizer(text, return_tensors="pt").input_ids
76
+
77
+ generated_ids = model.generate(input_ids, max_length=500)
78
+ print(tokenizer.decode(generated_ids[0], skip_special_tokens=True))
79
+ ```
80
+
81
+ Example 2:
82
+
83
+ ```python
84
+ import torch
85
+ from transformers import AutoTokenizer, AutoModelForCausalLM
86
+ tokenizer = AutoTokenizer.from_pretrained("motherduckdb/DuckDB-NSQL-7B-v0.1")
87
+ model = AutoModelForCausalLM.from_pretrained("motherduckdb/DuckDB-NSQL-7B-v0.1", torch_dtype=torch.bfloat16)
88
+
89
+ text = """### Instruction:
90
+ Your task is to generate valid duckdb SQL to answer the following question, given a duckdb database schema.
91
+
92
+ ### Input:
93
+ Here is the database schema that the SQL query will run on:
94
+ CREATE TABLE taxi (
95
+ VendorID bigint,
96
+ tpep_pickup_datetime timestamp,
97
+ tpep_dropoff_datetime timestamp,
98
+ passenger_count double,
99
+ trip_distance double,
100
+ fare_amount double,
101
+ extra double,
102
+ tip_amount double,
103
+ tolls_amount double,
104
+ improvement_surcharge double,
105
+ total_amount double,
106
+ );
107
+
108
+ ### Question:
109
+ get all columns ending with _amount from taxi table
110
+
111
+ ### Response (use duckdb shorthand if possible):"""
112
+
113
+ input_ids = tokenizer(text, return_tensors="pt").input_ids
114
+
115
+ generated_ids = model.generate(input_ids, max_length=500)
116
+ print(tokenizer.decode(generated_ids[0], skip_special_tokens=True))
117
+ ```
118
+
119
+ Example 3:
120
+
121
+ ```python
122
+ import torch
123
+ from transformers import AutoTokenizer, AutoModelForCausalLM
124
+ tokenizer = AutoTokenizer.from_pretrained("motherduckdb/DuckDB-NSQL-7B-v0.1")
125
+ model = AutoModelForCausalLM.from_pretrained("motherduckdb/DuckDB-NSQL-7B-v0.1", torch_dtype=torch.bfloat16)
126
+
127
+ text = """### Instruction:
128
+ Your task is to generate valid duckdb SQL to answer the following question, given a duckdb database schema.
129
+
130
+ ### Input:
131
+ Here is the database schema that the SQL query will run on:
132
+ CREATE TABLE rideshare (
133
+ hvfhs_license_num varchar,
134
+ dispatching_base_num varchar,
135
+ originating_base_num varchar,
136
+ request_datetime timestamp,
137
+ on_scene_datetime timestamp,
138
+ pickup_datetime timestamp,
139
+ dropoff_datetime timestamp,
140
+ trip_miles double,
141
+ trip_time bigint,
142
+
143
+ );
144
+
145
+ ### Question:
146
+ get longest trip in december 2022
147
+
148
+ ### Response (use duckdb shorthand if possible):
149
+ """
150
+
151
+ input_ids = tokenizer(text, return_tensors="pt").input_ids
152
+
153
+ generated_ids = model.generate(input_ids, max_length=500)
154
+ print(tokenizer.decode(generated_ids[0], skip_special_tokens=True))
155
+ ```
156
+
157
+
158
+
159
+ For more information (e.g., run with your local database), please find examples in [this repository](https://github.com/NumbersStationAI/DuckDB-NSQL).