Muennighoff
commited on
Commit
•
492e4ea
1
Parent(s):
0c96c51
Add script
Browse files
get_ni.py
ADDED
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import json
|
2 |
+
import logging
|
3 |
+
|
4 |
+
import pandas as pd
|
5 |
+
import requests
|
6 |
+
|
7 |
+
TRAIN_SPLIT_URL_NI = "https://raw.githubusercontent.com/allenai/natural-instructions/6174af63465999768fbc09f5dd8a7f1a5dfe9abc/splits/default/train_tasks.txt"
|
8 |
+
TEST_SPLIT_URL_NI = "https://raw.githubusercontent.com/allenai/natural-instructions/6174af63465999768fbc09f5dd8a7f1a5dfe9abc/splits/default/test_tasks.txt"
|
9 |
+
TASK_URL_NI = "https://raw.githubusercontent.com/allenai/natural-instructions/6174af63465999768fbc09f5dd8a7f1a5dfe9abc/tasks/"
|
10 |
+
|
11 |
+
# A total of 876 English tasks from the Natural Instructions dataset (757 tasks from the 'train' split and 119 tasks from the 'test' split)
|
12 |
+
TASKS_LIST_NI_TRAIN = pd.read_csv(TRAIN_SPLIT_URL_NI, delimiter="\t", header=None, names=["task_names"])["task_names"].tolist()
|
13 |
+
TASKS_LIST_NI_TEST = pd.read_csv(TEST_SPLIT_URL_NI, delimiter="\t", header=None, names=["task_names"])["task_names"].tolist()
|
14 |
+
|
15 |
+
split_to_task_list = {
|
16 |
+
"train": TASKS_LIST_NI_TRAIN,
|
17 |
+
"test": TASKS_LIST_NI_TEST,
|
18 |
+
}
|
19 |
+
|
20 |
+
def get_all_prompted_examples_ni(task):
|
21 |
+
examples = []
|
22 |
+
for example in task["Instances"]:
|
23 |
+
for output in example["output"]:
|
24 |
+
examples.append(
|
25 |
+
{
|
26 |
+
"id": example["id"],
|
27 |
+
"definition": task["Definition"][0],
|
28 |
+
"inputs": example["input"],
|
29 |
+
"targets": output,
|
30 |
+
}
|
31 |
+
)
|
32 |
+
return examples
|
33 |
+
|
34 |
+
def get_tasky_examples_ni(split):
|
35 |
+
task_list = split_to_task_list[split]
|
36 |
+
for task_name in task_list:
|
37 |
+
with open(f"{task_name}_{split}.jsonl", "w") as f:
|
38 |
+
try:
|
39 |
+
task_url = TASK_URL_NI + task_name + ".json"
|
40 |
+
task_data = json.loads(requests.get(task_url).text)
|
41 |
+
except Exception as e:
|
42 |
+
logging.exception(
|
43 |
+
f"There was an issue in loading the file {task_name}: {e} "
|
44 |
+
)
|
45 |
+
continue
|
46 |
+
examples = get_all_prompted_examples_ni(task_data)
|
47 |
+
if examples:
|
48 |
+
for example in examples:
|
49 |
+
f.write(json.dumps(example) + "\n")
|
50 |
+
|
51 |
+
if __name__ == "__main__":
|
52 |
+
get_tasky_examples_ni("train")
|
53 |
+
get_tasky_examples_ni("test")
|