This commit is contained in:
ZhihongShao
2024-02-06 10:27:40 +08:00
commit 21cc5c6701
59 changed files with 17325 additions and 0 deletions

30
evaluation/utils.py Executable file
View File

@@ -0,0 +1,30 @@
import json
import random
import numpy as np
def set_seed(seed):
if seed > 0:
random.seed(seed)
np.random.seed(seed)
def shuffle(data, seed):
if seed < 0:
return data
set_seed(seed)
indices = list(range(len(data)))
np.random.shuffle(indices)
data = [data[i] for i in indices]
return data
def read_data(path):
if path.endswith("json"):
data = json.load(open(path, "r"))
elif path.endswith("jsonl"):
data = []
with open(path, "r") as file:
for line in file:
line = json.loads(line)
data.append(line)
else:
raise NotImplementedError()
return data