tyfeng1997
commited on
Commit
•
ee011f4
1
Parent(s):
c8c04b1
add usage
Browse files
README.md
CHANGED
@@ -58,4 +58,64 @@ The following hyperparameters were used during training:
|
|
58 |
- Transformers 4.40.0
|
59 |
- Pytorch 2.2.0+cu121
|
60 |
- Datasets 2.19.0
|
61 |
-
- Tokenizers 0.19.1
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
58 |
- Transformers 4.40.0
|
59 |
- Pytorch 2.2.0+cu121
|
60 |
- Datasets 2.19.0
|
61 |
+
- Tokenizers 0.19.1
|
62 |
+
|
63 |
+
|
64 |
+
|
65 |
+
### Usage
|
66 |
+
|
67 |
+
```python
|
68 |
+
|
69 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
70 |
+
import torch
|
71 |
+
|
72 |
+
model_id = "tyfeng1997/llama3-8b-instruct-text-to-sql"
|
73 |
+
|
74 |
+
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
75 |
+
|
76 |
+
model = AutoModelForCausalLM.from_pretrained(
|
77 |
+
model_id,
|
78 |
+
torch_dtype=torch.bfloat16,
|
79 |
+
device_map="auto",
|
80 |
+
)
|
81 |
+
|
82 |
+
|
83 |
+
messages = [
|
84 |
+
{"role": "system", "content": "You are an text to SQL query translator. Users will ask you questions in English and you will generate a SQL query based on the provided SCHEMA.\nSCHEMA:\nCREATE TABLE match_season (College VARCHAR, POSITION VARCHAR)"},
|
85 |
+
{"role": "user", "content": "Which college have both players with position midfielder and players with position defender?"},
|
86 |
+
]
|
87 |
+
|
88 |
+
input_ids = tokenizer.apply_chat_template(
|
89 |
+
messages,
|
90 |
+
add_generation_prompt=True,
|
91 |
+
return_tensors="pt"
|
92 |
+
).to(model.device)
|
93 |
+
|
94 |
+
terminators = [
|
95 |
+
tokenizer.eos_token_id,
|
96 |
+
tokenizer.convert_tokens_to_ids("<|eot_id|>")
|
97 |
+
]
|
98 |
+
|
99 |
+
outputs = model.generate(
|
100 |
+
input_ids,
|
101 |
+
max_new_tokens=256,
|
102 |
+
eos_token_id=terminators,
|
103 |
+
do_sample=True,
|
104 |
+
temperature=0.6,
|
105 |
+
top_p=0.9,
|
106 |
+
)
|
107 |
+
response = outputs[0]
|
108 |
+
print(tokenizer.decode(response, skip_special_tokens=True))
|
109 |
+
|
110 |
+
#
|
111 |
+
#system
|
112 |
+
#You are an text to SQL query translator. Users will ask you questions in English and you will generate a SQL query based on the provided SCHEMA.
|
113 |
+
#SCHEMA:
|
114 |
+
#CREATE TABLE match_season (College VARCHAR, POSITION VARCHAR)
|
115 |
+
#user
|
116 |
+
#Which college have both players with position midfielder and players with position defender?
|
117 |
+
#assistant
|
118 |
+
#SELECT College FROM match_season WHERE POSITION = "Midfielder" INTERSECT SELECT College FROM match_season WHERE POSITION = "Defender"
|
119 |
+
#
|
120 |
+
```
|
121 |
+
|