AI & XML / LLM test suite / Results / Models / duckdb-nsql:7b
Model description
A text-to-SQL model with 7 billion parameters from MotherDuck and Numbers Station.
Model family | duckdb-nsql |
|---|---|
Context | 16K |
Input | Text |
Size | 38 GB |
Family sizes | 7b |
Readme excerpt
DuckDB-NSQL is a text-to-SQL model with 7 billion parameters, designed specifically for SQL generation tasks.
Based on Meta’s original Llama-2-7B model, it underwent further pretraining on general SQL queries and was then fine-tuned on DuckDB text-to-SQL pairs.
Usage
Example prompt
Gegeben sei dieses Schema: CREATE TABLE taxi ( VendorID bigint, tpep_pickup_datetime timestamp, tpep_dropoff_datetime timestamp, passenger_count double, trip_distance double, fare_amount double, extra double, tip_amount double, tolls_amount double, improvement_surcharge double, total_amount double, ); Gib mir Taxis mit mehr als 2 FahrgästenExample output
SELECT * FROM taxi WHERE passenger_count > 2Set the system prompt
This model expects the schema as input in the system prompt:
/set system """Hier ist das Datenbankschema, auf dem die SQL-Abfrage ausgeführt wird: CREATE TABLE taxi ( VendorID bigint, tpep_pickup_datetime timestamp, tpep_dropoff_datetime timestamp, passenger_count double, trip_distance double, fare_amount double, extra double, tip_amount double, tolls_amount double, improvement_surcharge double, total_amount double, );"""Once the schema is provided in the system prompt, the model uses it in subsequent responses.
For the following prompt:
gib alle Spalten aus der Tabelle taxi zurück, die auf _amount endenThe model outputs something like:
SELECT COLUMNS('.*_amount') FROM taxi;API example
$ curl http://localhost:11434/api/generate -d '{ "model": "duckdb-nsql:7b-q4_0", "system": "Hier ist das Datenbankschema, auf dem die SQL-Abfrage ausgeführt wird: CREATE TABLE taxi (VendorID bigint, tpep_pickup_datetime timestamp, tpep_dropoff_datetime timestamp, passenger_count double, trip_distance double, fare_amount double, extra double, tip_amount double, tolls_amount double, improvement_surcharge double, total_amount double,);", "prompt": "gib alle Spalten aus der Tabelle taxi zurück, die auf _amount enden" }'Python library example
pip install ollamaimport ollama r = ollama.generate( model='duckdb-nsql:7b-q4_0', system='''Hier ist das Datenbankschema, auf dem die SQL-Abfrage ausgeführt wird: CREATE TABLE taxi ( VendorID bigint, tpep_pickup_datetime timestamp, tpep_dropoff_datetime timestamp, passenger_count double, trip_distance double, fare_amount double, extra double, tip_amount double, tolls_amount double, improvement_surcharge double, total_amount double, );''', prompt='gib alle Spalten aus der Tabelle taxi zurück, die auf _amount enden', ) print(r['response'])Training data
200,000 DuckDB text-to-SQL pairs synthetically generated with Mixtral-8x7B-Instruct-v0.1, guided by the DuckDB v0.9.2 documentation, plus NSText2SQL text-to-SQL pairs converted to DuckDB SQL using sqlglot.
Training procedure
DuckDB-NSQL was trained with cross-entropy loss to maximize the probability of sequential inputs. When fine-tuning on text-to-SQL pairs, we compute loss only on the SQL portion of the pair. Training used 80 GB A100 GPUs with data and model parallelism. Fine-tuning comprised 10 epochs.
Intended use and limitations
The model was designed for text-to-SQL generation from supplied table schemas and natural-language prompts. It works best with the prompt format defined below and corresponding outputs. Unlike existing text-to-SQL models, SQL generation is not limited to SELECT statements. It can generate any valid DuckDB SQL statement, including statements for official DuckDB extensions.
References
Hugging Face
760 Runs 801 evaluated 4.9 % Score 0.1 % exactly correct
Help on evaluation, score and exact correctness
Score is a graded quality measure: correct = 100 %, mostly_correct = 80 %, partial = 50 %, wrong/not_answered = 0 %.
Exactly correct is stricter: only correct-labeled runs count. Mostly correct increases score but does not count as exactly correct.
Evaluated counts all runs with a substantive judgment. LLM-judge errors also count as evaluated, with score 0 %.
Test case Category