Update README.md
Browse files
README.md
CHANGED
|
@@ -16,6 +16,14 @@ base_model:
|
|
| 16 |
|
| 17 |
## Model Details
|
| 18 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
Prompt:
|
| 20 |
```
|
| 21 |
### Task
|
|
@@ -30,6 +38,32 @@ Given the database schema, here is the SQL query that [QUESTION]{user_question}[
|
|
| 30 |
[SQL]
|
| 31 |
```
|
| 32 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
|
| 34 |
### Model Description
|
| 35 |
|
|
|
|
| 16 |
|
| 17 |
## Model Details
|
| 18 |
|
| 19 |
+
To load the model:
|
| 20 |
+
```
|
| 21 |
+
# Load model directly
|
| 22 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 23 |
+
|
| 24 |
+
tokenizer = AutoTokenizer.from_pretrained("kristiannordby/llama3-sqlcoder-ft")
|
| 25 |
+
model = AutoModelForCausalLM.from_pretrained("kristiannordby/llama3-sqlcoder-ft")
|
| 26 |
+
```
|
| 27 |
Prompt:
|
| 28 |
```
|
| 29 |
### Task
|
|
|
|
| 38 |
[SQL]
|
| 39 |
```
|
| 40 |
|
| 41 |
+
To prompt the model for generation:
|
| 42 |
+
```
|
| 43 |
+
def build_prompt(user_question, create_table_statements):
|
| 44 |
+
return (
|
| 45 |
+
"### Task\n"
|
| 46 |
+
f"Generate a SQL query to answer [QUESTION]{user_question}[/QUESTION]\n\n"
|
| 47 |
+
"### Database Schema\n"
|
| 48 |
+
"The query will run on a database with the following schema:\n"
|
| 49 |
+
f"{create_table_statements}\n\n"
|
| 50 |
+
"### Answer\n"
|
| 51 |
+
f"Given the database schema, here is the SQL query that [QUESTION]{user_question}[/QUESTION]\n"
|
| 52 |
+
"[SQL]\n"
|
| 53 |
+
)
|
| 54 |
+
|
| 55 |
+
def build_output(sql):
|
| 56 |
+
# Add a newline at end; if the data has a closing "[/SQL]", add it here!
|
| 57 |
+
return f"{sql.strip()}\n"
|
| 58 |
+
|
| 59 |
+
create_table_statements = "YOUR TABLE SCHEMA HERE"
|
| 60 |
+
inputs = build_prompt("YOUR PROMPT HERE", create_table_statements)
|
| 61 |
+
input_ids = tokenizer(inputs, return_tensors="pt", padding = True, truncation = True, max_length = 512).input_ids.to(model.device)
|
| 62 |
+
outputs = model.generate(input_ids, max_new_tokens=100)
|
| 63 |
+
output = tokenizer.decode(outputs[0])
|
| 64 |
+
```
|
| 65 |
+
|
| 66 |
+
|
| 67 |
|
| 68 |
### Model Description
|
| 69 |
|