Muennighoff commited on
Commit
0d95002
1 Parent(s): 17ea3bd

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +51 -0
README.md ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ Creation (Copied & adapted from https://github.com/stanford-crfm/helm/blob/0eaaa62a2263ddb94e9850ee629423b010f57e4a/src/helm/benchmark/scenarios/babi_qa_scenario.py):
3
+
4
+ ```python
5
+ !wget http://www.thespermwhale.com/jaseweston/babi/tasks_1-20_v1-2.tar.gz
6
+ !tar -xf tasks_1-20_v1-2.tar.gz
7
+ import json
8
+ from typing import List
9
+
10
+ tasks = list(range(1, 20))
11
+ splits = ["train", "valid", "test"]
12
+
13
+ def process_path(path: str) -> str:
14
+ """Turn a path string (task 19) from the original format 's,w' to a verbal model-friendly format 'south west'"""
15
+ steps: List[str] = path.split(",")
16
+ directions = {"s": "south", "n": "north", "e": "east", "w": "west"}
17
+ path = " ".join([directions[step] for step in steps])
18
+ return path
19
+
20
+ for split in splits:
21
+ with open(f"babi_{split}.jsonl", "w") as f_base:
22
+ for task in tasks:
23
+ split_path: str = f"./tasks_1-20_v1-2/en-valid/qa{task}_{split}.txt"
24
+ with open(split_path, "r") as f:
25
+ facts = list(f)
26
+ story: List[str] = []
27
+ for fact in facts:
28
+ fid = int(fact.split(" ")[0])
29
+ if fid == 1:
30
+ story = []
31
+ fact = " ".join(fact.split(" ")[1:])
32
+ is_question = "?" in fact
33
+ if is_question:
34
+ question, answer = fact.split("\t")[:2]
35
+ question, answer = question.strip(), answer.strip()
36
+ # All tasks except task 19 have a verbal single-word answer (e.g. kitchen, apple, yes).
37
+ # Task 19 (path finding) has a non verbal answer format (
38
+ if task == 19:
39
+ answer = process_path(answer)
40
+
41
+ f_base.write(json.dumps({
42
+ "passage": "".join(story),
43
+ "question": question,
44
+ "answer": answer,
45
+ "task": task,
46
+ }) + "\n")
47
+ if "?" in story:
48
+ print("STORY", "".join(story))
49
+ else:
50
+ story.append(fact)
51
+ ```