anand-s commited on
Commit
e7bbf28
·
verified ·
1 Parent(s): 96c55e0

Update test_repo.py

Browse files
Files changed (1) hide show
  1. test_repo.py +64 -7
test_repo.py CHANGED
@@ -42,9 +42,8 @@ class TestRepo(datasets.GeneratorBasedBuilder):
42
  # DEFAULT_CONFIG_NAME = "mcq_domain"
43
 
44
  def _info(self):
45
- return datasets.DatasetInfo(
46
- description=_DESCRIPTION,
47
- features=datasets.Features({
48
  "prompt": datasets.Value("string"),
49
  "question": datasets.Value("string"),
50
  "options": datasets.Sequence(datasets.Value("string")),
@@ -53,6 +52,39 @@ class TestRepo(datasets.GeneratorBasedBuilder):
53
  "question_type": datasets.Value("string"),
54
  "dataset_name": datasets.Value("string"),
55
  }),
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
56
  homepage=_HOMEPAGE,
57
  license=_LICENSE,
58
  citation=_CITATION,
@@ -64,9 +96,17 @@ class TestRepo(datasets.GeneratorBasedBuilder):
64
  print(data_dir)
65
  return [
66
  datasets.SplitGenerator(
67
- name=self.config.name,
68
- gen_kwargs={"directory": data_dir, "split": self.config.name},
69
- )
 
 
 
 
 
 
 
 
70
  ]
71
 
72
  def _generate_examples(self, directory, split):
@@ -78,7 +118,7 @@ class TestRepo(datasets.GeneratorBasedBuilder):
78
  with open(filepath, encoding="utf-8") as f:
79
  for key, row in enumerate(f):
80
  data = json.loads(row)
81
- if split in ["train_normal_mcqa", "val_normal_mcqa", "test_normal_mcqa"]:
82
  yield key_idx, {
83
  "prompt": data.get("prompt", ""),
84
  "question": data["question"],
@@ -88,4 +128,21 @@ class TestRepo(datasets.GeneratorBasedBuilder):
88
  "question_type": data.get("question_type", ""),
89
  "dataset_name": os.path.split(filepath)[-1].replace(".jsonl","")
90
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
91
  key_idx +=1
 
42
  # DEFAULT_CONFIG_NAME = "mcq_domain"
43
 
44
  def _info(self):
45
+ features_dict = {
46
+ "train_normal_mcqa": datasets.Features({
 
47
  "prompt": datasets.Value("string"),
48
  "question": datasets.Value("string"),
49
  "options": datasets.Sequence(datasets.Value("string")),
 
52
  "question_type": datasets.Value("string"),
53
  "dataset_name": datasets.Value("string"),
54
  }),
55
+ "val_normal_mcqa": datasets.Features({
56
+ "prompt": datasets.Value("string"),
57
+ "question": datasets.Value("string"),
58
+ "options": datasets.Sequence(datasets.Value("string")),
59
+ "answer": datasets.Value("string"),
60
+ "num_options": datasets.Value("string"),
61
+ "question_type": datasets.Value("string"),
62
+ "dataset_name": datasets.Value("string"),
63
+ "few_shot_prompt": datasets.Sequence(datasets.Features({
64
+ "question": datasets.Value("string"),
65
+ "answer": datasets.Value("string"),
66
+ "options": datasets.Sequence(datasets.Value("string")),
67
+ })),
68
+ }),
69
+ "test_normal_mcqa": datasets.Features({
70
+ "prompt": datasets.Value("string"),
71
+ "question": datasets.Value("string"),
72
+ "options": datasets.Sequence(datasets.Value("string")),
73
+ "answer": datasets.Value("string"),
74
+ "num_options": datasets.Value("string"),
75
+ "question_type": datasets.Value("string"),
76
+ "dataset_name": datasets.Value("string"),
77
+ "few_shot_prompt": datasets.Sequence(datasets.Features({
78
+ "question": datasets.Value("string"),
79
+ "answer": datasets.Value("string"),
80
+ "options": datasets.Sequence(datasets.Value("string")),
81
+ })),
82
+ })
83
+ }
84
+
85
+ return datasets.DatasetInfo(
86
+ description=_DESCRIPTION,
87
+ features=features_dict[self.config.name]
88
  homepage=_HOMEPAGE,
89
  license=_LICENSE,
90
  citation=_CITATION,
 
96
  print(data_dir)
97
  return [
98
  datasets.SplitGenerator(
99
+ name="train_normal_mcqa",
100
+ gen_kwargs={"directory": data_dir, "split": "train"},
101
+ ),
102
+ datasets.SplitGenerator(
103
+ name="val_normal_mcqa",
104
+ gen_kwargs={"directory": data_dir, "split": "val"},
105
+ ),
106
+ datasets.SplitGenerator(
107
+ name="test_normal_mcqa",
108
+ gen_kwargs={"directory": data_dir, "split": "test"},
109
+ ),
110
  ]
111
 
112
  def _generate_examples(self, directory, split):
 
118
  with open(filepath, encoding="utf-8") as f:
119
  for key, row in enumerate(f):
120
  data = json.loads(row)
121
+ if split == "train_normal_mcqa":
122
  yield key_idx, {
123
  "prompt": data.get("prompt", ""),
124
  "question": data["question"],
 
128
  "question_type": data.get("question_type", ""),
129
  "dataset_name": os.path.split(filepath)[-1].replace(".jsonl","")
130
  }
131
+ key_idx +=1
132
+ elif split in ["val_normal_mcqa", "test_normal_mcqa"]:
133
+ yield key_idx, {
134
+ "prompt": data.get("prompt", ""),
135
+ "question": data["question"],
136
+ "options": data["options"],
137
+ "answer": data.get("answer", ""),
138
+ "num_options": data.get("num_options", ""),
139
+ "question_type": data.get("question_type", ""),
140
+ "dataset_name": os.path.split(filepath)[-1].replace(".jsonl",""),
141
+ "few_shot_prompt": [{
142
+ "question": item["question"],
143
+ "answer": item["answer"],
144
+ "options": item["options"],
145
+ } for item in data["few_shot_prompt"]]
146
+ }
147
+
148
  key_idx +=1