nbtpj commited on
Commit
5d1c4c6
·
1 Parent(s): 12f54e3

Create BioNLP2021.py

Browse files
Files changed (1) hide show
  1. BioNLP2021.py +88 -0
BioNLP2021.py ADDED
@@ -0,0 +1,88 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+
3
+ import datasets
4
+ import pandas as pd
5
+
6
+ _CITATION = None
7
+
8
+ _DESCRIPTION = """\
9
+ MEDIQA @ NAACL-BioNLP 2021 -- Task 2: Multi-answer summarization
10
+ https://sites.google.com/view/mediqa2021
11
+ Biomedical Summarization Data
12
+ The MEDIQA-AnS Dataset could be used for training.
13
+ """
14
+ _HOMEPAGE = "https://github.com/abachaa/MEDIQA2021/tree/main/Task2"
15
+ _LICENSE = None
16
+ _DATA_URL = "https://huggingface.co/datasets/nbtpj/BioNLP2021/resolve/main/{split_name}.csv"
17
+
18
+ _SPLIT = ['train_mul', 'train_sig', 'validate', 'test']
19
+
20
+
21
+ class BioNLP2021(datasets.BuilderConfig):
22
+ """BuilderConfig for GLUE."""
23
+
24
+ def __init__(self, data_url, **kwargs):
25
+ """BuilderConfig for BioNLP2021MAS
26
+ Args:
27
+ data_url: `string`, url to the dataset (word or raw level)
28
+ **kwargs: keyword arguments forwarded to super.
29
+ """
30
+ super(BioNLP2021, self).__init__(
31
+ version=datasets.Version(
32
+ "1.0.0",
33
+ ),
34
+ **kwargs,
35
+ )
36
+ self.data_url = data_url
37
+
38
+
39
+ class Loader(datasets.GeneratorBasedBuilder):
40
+ VERSION = datasets.Version("0.1.0")
41
+ BUILDER_CONFIGS = BioNLP2021(name='BioNLP2021', data_url=_DATA_URL)
42
+
43
+ def _info(self):
44
+ return datasets.DatasetInfo(
45
+ # This is the description that will appear on the datasets page.
46
+ description=_DESCRIPTION,
47
+ features=datasets.Features(
48
+ {
49
+ "text": datasets.Value("string"),
50
+ "question": datasets.Value("string"),
51
+ "key": datasets.Value("string"),
52
+ "summ_abs": datasets.Value("string"),
53
+ "summ_ext": datasets.Value("string"),
54
+ # These are the features of your dataset like images, labels ...
55
+ # key,question,sum_abs,sum_ext,rating,section,article,text
56
+
57
+ }
58
+ ),
59
+ # If there's a common (input, target) tuple from the features,
60
+ # specify them here. They'll be used if as_supervised=True in
61
+ # builder.as_dataset.
62
+ supervised_keys=None,
63
+ homepage=_HOMEPAGE,
64
+ license=_LICENSE,
65
+ citation=_CITATION,
66
+ )
67
+
68
+ def _split_generators(self, dl_manager):
69
+ """Returns SplitGenerators."""
70
+ rs = []
71
+ for split in _SPLIT:
72
+ file= dl_manager.download_and_extract(_DATA_URL.format(split_name=split))
73
+ rs.append(
74
+ datasets.SplitGenerator(
75
+ name=datasets.Split.TRAIN,
76
+ gen_kwargs={"data_file": file, "split": split },
77
+ ))
78
+
79
+
80
+ return rs
81
+
82
+
83
+ def _generate_examples(self, data_file, split):
84
+ """Yields examples."""
85
+ with open(data_file, encoding="utf-8") as f:
86
+ f = pd.read_csv(f).to_dict('records')
87
+ for idx, row in enumerate(f):
88
+ yield idx, row