14-07-22 commited on
Commit
5e19492
1 Parent(s): 995995f

Create new file

Browse files
Files changed (1) hide show
  1. wikimedqa.py +131 -0
wikimedqa.py ADDED
@@ -0,0 +1,131 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # coding=utf-8
2
+ # Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+
16
+ # Lint as: python3
17
+
18
+
19
+ import csv
20
+ import os
21
+ import textwrap
22
+ import numpy as np
23
+ import datasets
24
+ import pandas as pd
25
+
26
+
27
+ _CITATION = """\
28
+ Anonymous submission
29
+ """
30
+
31
+ _DESCRIPTION = """\
32
+ Anonymous submission
33
+ """
34
+
35
+ URL = 'https://sileod.s3.eu-west-3.amazonaws.com/wikimedqa/'
36
+
37
+
38
+ class WikiMedQAConfig(datasets.BuilderConfig):
39
+ """BuilderConfig for WikiMedQA."""
40
+
41
+ def __init__(
42
+ self,
43
+ data_dir,
44
+ label_classes=None,
45
+ process_label=lambda x: x,
46
+ **kwargs,
47
+ ):
48
+
49
+ super(WikiMedQAConfig, self).__init__(version=datasets.Version("1.0.5", ""), **kwargs)
50
+ self.text_features = {k:k for k in ['text']+[f'option_{i}' for i in range(8)]}
51
+ self.label_column = 'label'
52
+ self.label_classes = list('01234567')
53
+ self.data_url = URL
54
+ self.url=URL
55
+ self.data_dir=data_dir
56
+ self.citation = _CITATION
57
+ self.process_label = process_label
58
+
59
+
60
+ class WikiMedQA(datasets.GeneratorBasedBuilder):
61
+ """Evaluation of word estimative of probability understanding"""
62
+
63
+ BUILDER_CONFIGS = [
64
+ WikiMedQAConfig(
65
+ name="medwiki",
66
+ data_dir="medwiki"),
67
+ WikiMedQAConfig(
68
+ name="wikem",
69
+ data_dir="wikem"),
70
+ WikiMedQAConfig(
71
+ name="wikidoc",
72
+ data_dir="wikidoc"),
73
+ ]
74
+
75
+ def _info(self):
76
+ features = {text_feature: datasets.Value("string") for text_feature in self.config.text_features.keys()}
77
+ features["label"] = datasets.features.ClassLabel(names=self.config.label_classes)
78
+ features["idx"] = datasets.Value("int32")
79
+
80
+ return datasets.DatasetInfo(
81
+ description=_DESCRIPTION,
82
+ features=datasets.Features(features),
83
+ homepage=self.config.url,
84
+ citation=self.config.citation + "\n" + _CITATION,
85
+ )
86
+ def _split_generators(self, dl_manager):
87
+
88
+ data_dirs=[]
89
+ for split in ['train','validation','test']:
90
+ url=f'{URL}{self.config.data_dir}.csv'
91
+ print(url)
92
+ data_dirs+=[dl_manager.download(url)]
93
+ print(data_dirs)
94
+ return [
95
+ datasets.SplitGenerator(
96
+ name=datasets.Split.TRAIN,
97
+ gen_kwargs={
98
+ "data_file": data_dirs[0],
99
+ "split": "train",
100
+ },
101
+ ),
102
+ datasets.SplitGenerator(
103
+ name=datasets.Split.VALIDATION,
104
+ gen_kwargs={
105
+ "data_file": data_dirs[1],
106
+ "split": "dev",
107
+ },
108
+ ),
109
+ datasets.SplitGenerator(
110
+ name=datasets.Split.TEST,
111
+ gen_kwargs={
112
+ "data_file": data_dirs[2],
113
+ "split": "test",
114
+ },
115
+ ),
116
+ ]
117
+
118
+ def _generate_examples(self, data_file, split):
119
+ df = pd.read_csv(data_file)
120
+ df=df[['text','options','label']]
121
+ train, dev, test = np.split(df.sample(frac=1, random_state=42),
122
+ [int(.9*len(df)), int(.95*len(df))])
123
+ df=eval(split)
124
+ df['options']=df['options'].map(eval)
125
+ for i in range(8):
126
+ df[f'option_{i}']=df.options.map(lambda x:x[i])
127
+ del df['options']
128
+ df['idx']=df.index
129
+ for idx, example in df.iterrows():
130
+ yield idx, dict(example)
131
+