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3
|
| 14 |
+
license: llama3
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
---
|
| 19 |
+
license: cc-by-sa-4.0
|
| 20 |
+
metrics:
|
| 21 |
+
- accuracy
|
| 22 |
+
pipeline_tag: text-generation
|
| 23 |
+
tags:
|
| 24 |
+
- code
|
| 25 |
+
---
|
| 26 |
+
|
| 27 |
+
A capable language model for text to SQL generation for Postgres, Redshift and Snowflake that is on-par with the most capable generalist frontier models.
|
| 28 |
+
|
| 29 |
+

|
| 30 |
+
|
| 31 |
+
## Model Description
|
| 32 |
+
|
| 33 |
+
Developed by: Defog, Inc
|
| 34 |
+
Model type: [Text to SQL]
|
| 35 |
+
License: [CC-by-SA-4.0]
|
| 36 |
+
Finetuned from model: [Meta-Llama-3-8B-Instruct]
|
| 37 |
+
|
| 38 |
+
## defog/llama-3-sqlcoder-8b for CTranslate2
|
| 39 |
+
|
| 40 |
+
**The model is quantized version of the [meta-llama/Meta-Llama-3-8B-Instruct](https://huggingface.co/meta-llama/Meta-Llama-3-8B-Instruct) with int8_float16 quantization and can be used in [CTranslate2](https://github.com/OpenNMT/CTranslate2).**
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
## How to use
|
| 45 |
+
|
| 46 |
+
```pip install ctranslate2```
|
| 47 |
+
|
| 48 |
+
This repository for use with [CTranslate2](https://github.com/OpenNMT/CTranslate2).
|
| 49 |
+
|
| 50 |
+
### Use with CTranslate2
|
| 51 |
+
|
| 52 |
+
This example code is obtained from [CTranslate2_transformers](https://opennmt.net/CTranslate2/guides/transformers.html#mpt) and [tokenizer AutoTokenizer](https://huggingface.co/docs/transformers/main_classes/tokenizer).
|
| 53 |
+
More detailed information about the `generate_batch` methon can be found at [CTranslate2_Generator.generate_batch](https://opennmt.net/CTranslate2/python/ctranslate2.Generator.html#ctranslate2.Generator.generate_batch).
|
| 54 |
+
|
| 55 |
+
```python
|
| 56 |
+
import ctranslate2
|
| 57 |
+
import transformers
|
| 58 |
+
|
| 59 |
+
from huggingface_hub import snapshot_download
|
| 60 |
+
model_id = "ByteForge/Defog_llama-3-sqlcoder-8b-ct2-int8_float16"
|
| 61 |
+
model_path = snapshot_download(model_id)
|
| 62 |
+
model = ctranslate2.Generator(model_path)
|
| 63 |
+
tokenizer = transformers.AutoTokenizer.from_pretrained(model_id)
|
| 64 |
+
|
| 65 |
+
prompt="""
|
| 66 |
+
CREATE TABLE stadium (
|
| 67 |
+
stadium_id number,
|
| 68 |
+
location text,
|
| 69 |
+
name text,
|
| 70 |
+
capacity number,
|
| 71 |
+
highest number,
|
| 72 |
+
lowest number,
|
| 73 |
+
average number
|
| 74 |
+
)
|
| 75 |
+
|
| 76 |
+
CREATE TABLE singer (
|
| 77 |
+
singer_id number,
|
| 78 |
+
name text,
|
| 79 |
+
country text,
|
| 80 |
+
song_name text,
|
| 81 |
+
song_release_year text,
|
| 82 |
+
age number,
|
| 83 |
+
is_male others
|
| 84 |
+
)
|
| 85 |
+
|
| 86 |
+
CREATE TABLE concert (
|
| 87 |
+
concert_id number,
|
| 88 |
+
concert_name text,
|
| 89 |
+
theme text,
|
| 90 |
+
stadium_id text,
|
| 91 |
+
year text
|
| 92 |
+
)
|
| 93 |
+
|
| 94 |
+
CREATE TABLE singer_in_concert (
|
| 95 |
+
concert_id number,
|
| 96 |
+
singer_id text
|
| 97 |
+
)
|
| 98 |
+
|
| 99 |
+
-- Using valid SQLite, answer the following questions for the tables provided above.
|
| 100 |
+
|
| 101 |
+
-- What is the maximum, the average, and the minimum capacity of stadiums ? (Generate 1 Sql query. No explaination needed)
|
| 102 |
+
|
| 103 |
+
answer:
|
| 104 |
+
"""
|
| 105 |
+
|
| 106 |
+
messages = [
|
| 107 |
+
{"role": "system", "content": "You are SQL Expert. Given a input question and schema, answer with correct sql query"},
|
| 108 |
+
{"role": "user", "content": prompt},
|
| 109 |
+
]
|
| 110 |
+
|
| 111 |
+
input_ids = tokenizer.apply_chat_template(
|
| 112 |
+
messages,
|
| 113 |
+
tokenize=False,
|
| 114 |
+
add_generation_prompt=True
|
| 115 |
+
)
|
| 116 |
+
|
| 117 |
+
terminators = [
|
| 118 |
+
tokenizer.eos_token_id,
|
| 119 |
+
tokenizer.convert_tokens_to_ids("<|eot_id|>")
|
| 120 |
+
]
|
| 121 |
+
|
| 122 |
+
input_tokens = tokenizer.convert_ids_to_tokens(tokenizer.encode(input_ids))
|
| 123 |
+
|
| 124 |
+
results = model.generate_batch([input_tokens], include_prompt_in_result=False, max_length=256, sampling_temperature=0.6, sampling_topp=0.9, end_token=terminators)
|
| 125 |
+
output = tokenizer.decode(results[0].sequences_ids[0])
|
| 126 |
+
|
| 127 |
+
print(output)
|
| 128 |
+
```
|
| 129 |
+
|
| 130 |
+
## Ideal prompt and inference parameters
|
| 131 |
+
Set temperature to 0, and do not do sampling.
|
| 132 |
+
|