Views
No views yet
codellama/CodeLlama-7b-hf text2SQL model that generates SQLite queries. This is a relatively small model that was fine-tuned on 8 x A10Gs with a total GPU memory of 192GB for over 4 days for 3 epochs. For databases with different SQL syntaxes that do not adhere to SQLite's syntax, we plan to launch other models specifically catered to them.1from transformers import AutoTokenizer, AutoModelForCausalLM
2
3model_name = 'unSQLv1-7b-generic-lora'
4device = 'cuda'
5
6model = AutoModelForCausalLM.from_pretrained(model_name).to(device)
7tokenizer = AutoTokenizer.from_pretrained(model_name)
8
9example_prompt = '''
10### Schema and the Natural Language Query:
11CREATE TABLE stadium (
12 stadium_id number,
13 location text,
14 name text,
15 capacity number,
16 highest number,
17 lowest number,
18 average number
19)
20
21CREATE TABLE singer (
22 singer_id number,
23 name text,
24 country text,
25 song_name text,
26 song_release_year text,
27 age number,
28 is_male others
29)
30
31CREATE TABLE concert (
32 concert_id number,
33 concert_name text,
34 theme text,
35 stadium_id text,
36 year text
37)
38
39CREATE TABLE singer_in_concert (
40 concert_id number,
41 singer_id text
42)
43
44-- Using valid SQLite, answer the following questions for the tables provided above.
45
46-- What is the maximum, the average, and the minimum capacity of stadiums ?
47'''
48
49
50inputs = tokenizer.encode(example_prompt, return_tensors="pt").to(device)
51outputs = model.generate(inputs, max_length=512)
52print(tokenizer.decode(outputs[0], skip_special_tokens=True))1payload = {
2 "inputs": "### Schema and the Natural Language Query:\nCREATE TABLE stadium (\n stadium_id number,\n location text,\n name text,\n capacity number,\n highest number,\n lowest number,\n average number\n)\n\nCREATE TABLE singer (\n singer_id number,\n name text,\n country text,\n song_name text,\n song_release_year text,\n age number,\n is_male others\n)\n\nCREATE TABLE concert (\n concert_id number,\n concert_name text,\n theme text,\n stadium_id text,\n year text\n)\n\nCREATE TABLE singer_in_concert (\n concert_id number,\n singer_id text\n)\n\n-- Using valid SQLite, answer the following questions for the tables provided above.\n\n-- What is the maximum, the average, and the minimum capacity of stadiums ?",
3 "parameters": {
4 "maxNewTokens": 512,
5 "topP": 0.9,
6 "temperature": 0.2
7 }
8}
9
10client = boto3.client('runtime.sagemaker')
11endpoint_name = 'deployed_model_name'
12response = client.invoke_endpoint(
13 EndpointName=endpoint_name,
14 ContentType='application/json',
15 Body=json.dumps(payload).encode('utf-8'),
16)
17response = response["Body"].read().decode("utf8")
18response = json.loads(response)
19print(response[0]['generated_text'])
201{
2 "body": [
3 {
4 "generated_text": "\n\n\n### Response:\nSELECT MAX(capacity), AVG(capacity), MIN(capacity) FROM stadium",
5 "details": {
6 "finish_reason": "eos_token",
7 "generated_tokens": 30,
8 "seed": 14524408611356330000,
9 "prefill": [],
10 "tokens": [
11 {
12 "id": 13,
13 "text": "\n",
14 "logprob": 0,
15 "special": false
16 },
17 {
18 "id": 13,
19 "text": "\n",
20 "logprob": 0,
21 "special": false
22 },
23 {
24 "id": 13,
25 "text": "\n",
26 "logprob": 0,
27 "special": false
28 },
29 {
30 "id": 2277,
31 "text": "##",
32 "logprob": 0,
33 "special": false
34 },
35 {
36 "id": 29937,
37 "text": "#",
38 "logprob": 0,
39 "special": false
40 },
41 {
42 "id": 13291,
43 "text": " Response",
44 "logprob": 0,
45 "special": false
46 },
47 {
48 "id": 29901,
49 "text": ":",
50 "logprob": 0,
51 "special": false
52 },
53 {
54 "id": 13,
55 "text": "\n",
56 "logprob": 0,
57 "special": false
58 },
59 {
60 "id": 6404,
61 "text": "SELECT",
62 "logprob": 0,
63 "special": false
64 },
65 {
66 "id": 18134,
67 "text": " MAX",
68 "logprob": 0,
69 "special": false
70 },
71 {
72 "id": 29898,
73 "text": "(",
74 "logprob": 0,
75 "special": false
76 },
77 {
78 "id": 5030,
79 "text": "cap",
80 "logprob": 0,
81 "special": false
82 },
83 {
84 "id": 5946,
85 "text": "acity",
86 "logprob": 0,
87 "special": false
88 },
89 {
90 "id": 511,
91 "text": "),",
92 "logprob": 0,
93 "special": false
94 },
95 {
96 "id": 16884,
97 "text": " AV",
98 "logprob": 0,
99 "special": false
100 },
101 {
102 "id": 29954,
103 "text": "G",
104 "logprob": 0,
105 "special": false
106 },
107 {
108 "id": 29898,
109 "text": "(",
110 "logprob": 0,
111 "special": false
112 },
113 {
114 "id": 5030,
115 "text": "cap",
116 "logprob": 0,
117 "special": false
118 },
119 {
120 "id": 5946,
121 "text": "acity",
122 "logprob": 0,
123 "special": false
124 },
125 {
126 "id": 511,
127 "text": "),",
128 "logprob": 0,
129 "special": false
130 },
131 {
132 "id": 341,
133 "text": " M",
134 "logprob": 0,
135 "special": false
136 },
137 {
138 "id": 1177,
139 "text": "IN",
140 "logprob": 0,
141 "special": false
142 },
143 {
144 "id": 29898,
145 "text": "(",
146 "logprob": 0,
147 "special": false
148 },
149 {
150 "id": 5030,
151 "text": "cap",
152 "logprob": 0,
153 "special": false
154 },
155 {
156 "id": 5946,
157 "text": "acity",
158 "logprob": 0,
159 "special": false
160 },
161 {
162 "id": 29897,
163 "text": ")",
164 "logprob": 0,
165 "special": false
166 },
167 {
168 "id": 3895,
169 "text": " FROM",
170 "logprob": 0,
171 "special": false
172 },
173 {
174 "id": 10728,
175 "text": " stad",
176 "logprob": 0,
177 "special": false
178 },
179 {
180 "id": 1974,
181 "text": "ium",
182 "logprob": 0,
183 "special": false
184 },
185 {
186 "id": 2,
187 "text": "</s>",
188 "logprob": 0,
189 "special": true
190 }
191 ]
192 }
193 }
194 ],
195 "contentType": "application/json",
196 "invokedProductionVariant": "AllTraffic"
197}