forked from DebadityaPal/RoBERTa-NL2SQL
-
Notifications
You must be signed in to change notification settings - Fork 0
/
model_save_and_infer.py
28 lines (23 loc) · 991 Bytes
/
model_save_and_infer.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
import os
import json
import random as python_random
def save_for_evaluation(path_save, results, dataset_name):
path_save_file = os.path.join(path_save, f'results_{dataset_name}.jsonl')
with open(path_save_file, 'w', encoding='utf-8') as file:
for index, line in enumerate(results):
json_string = json.dumps(line, ensure_ascii=False, default=json_default_type_checker)
json_string += '\n'
file.writelines(json_string)
def json_default_type_checker(o):
"""
From https://stackoverflow.com/questions/11942364/typeerror-integer-is-not-json-serializable-when-serializing-json-in-python
"""
if isinstance(o, int): return int(o)
raise TypeError
def load_jsonl(path_file, seed=1):
data = []
with open(path_file, "r", encoding="utf-8") as file:
for idx, line in enumerate(file):
curr_line = json.loads(line.strip())
data.append(curr_line)
return data