forked from unit-mesh/unit-minions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
text-to-sql.py
28 lines (26 loc) · 836 Bytes
/
text-to-sql.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# open datasets/sql-train.csv and convert to jsonl
# csv examples:
# ```
# question,sql
# Tell me what the notes are for South Australia ,SELECT Notes FROM table WHERE Current slogan = SOUTH AUSTRALIA
# What is the current series where the new series began in June 2011?,SELECT Current series FROM table WHERE Notes = New series began in June 2011
# ```
# output format:
# [{
# instruction: "text to sql
# input: csv.question[index]
# output: csv.sql[index]
# }]
import csv
import json
with open('../datasets/sql/sql-train.csv', 'r') as f:
reader = csv.reader(f)
next(reader)
data = [{
'instruction': 'text to sql',
'input': row[0],
'output': row[1]
} for row in reader]
with open('../datasets/sql/sql-train.jsonl', 'w') as f:
for row in data:
f.write(json.dumps(row) + '\n')