MCPcopy Create free account
hub / github.com/debjitpaul/refiner / get_datasets

Function get_datasets

data_preprocessing/prepare_snlr_datasets.py:9–39  ·  view source on GitHub ↗
(difficulty="easy")

Source from the content-addressed store, hash-verified

7from src.helm.benchmark.scenarios.synthetic_reasoning_natural_scenario import SRNScenario
8
9def get_datasets(difficulty="easy"):
10 train = []
11 val = []
12 test = []
13
14 srn = SRNScenario(difficulty)
15 instances = srn.get_instances()
16
17 for instance in instances:
18 inputs = instance.input.split("\n")
19 fact_index = inputs.index("Fact:")
20 rules = inputs[:fact_index]
21 fact = inputs[fact_index+1]
22 question = inputs[fact_index+2]
23 consequents = []
24 for ref in instance.references:
25 consequents.append(ref.output)
26 sample = {
27 "rules": rules,
28 "fact": fact,
29 "question": question,
30 "consequents": consequents
31 }
32 if instance.split == "valid":
33 val.append(sample)
34 elif instance.split == "test":
35 test.append(sample)
36 else:
37 train.append(sample)
38
39 return train, val, test
40
41def save_dataset(dataset, path):
42 with open(path, "w") as f:

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected