File size: 2,890 Bytes
5d1c4c6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
242aede
5d1c4c6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
bc9a468
5d1c4c6
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import os

import datasets
import pandas as pd

_CITATION = None

_DESCRIPTION = """\
MEDIQA @ NAACL-BioNLP 2021 -- Task 2: Multi-answer summarization
https://sites.google.com/view/mediqa2021
Biomedical Summarization Data
The MEDIQA-AnS Dataset could be used for training.
"""
_HOMEPAGE = "https://github.com/abachaa/MEDIQA2021/tree/main/Task2"
_LICENSE = None
_DATA_URL = "https://huggingface.co/datasets/nbtpj/BioNLP2021/resolve/main/{split_name}.csv"
           
_SPLIT = ['train_mul', 'train_sig', 'validate', 'test']


class BioNLP2021(datasets.BuilderConfig):
    """BuilderConfig for GLUE."""

    def __init__(self, data_url, **kwargs):
        """BuilderConfig for BioNLP2021MAS
        Args:
          data_url: `string`, url to the dataset (word or raw level)
          **kwargs: keyword arguments forwarded to super.
        """
        super(BioNLP2021, self).__init__(
            version=datasets.Version(
                "1.0.0",
            ),
            **kwargs,
        )
        self.data_url = data_url


class Loader(datasets.GeneratorBasedBuilder):
    VERSION = datasets.Version("0.1.0")
    BUILDER_CONFIGS = [BioNLP2021(name='BioNLP2021', data_url=_DATA_URL)]

    def _info(self):
        return datasets.DatasetInfo(
            # This is the description that will appear on the datasets page.
            description=_DESCRIPTION,
            features=datasets.Features(
                {
                    "text": datasets.Value("string"),
                    "question": datasets.Value("string"),
                    "key": datasets.Value("string"),
                    "summ_abs": datasets.Value("string"),
                    "summ_ext": datasets.Value("string"),
                    # These are the features of your dataset like images, labels ...
                    # key,question,sum_abs,sum_ext,rating,section,article,text

                }
            ),
            # If there's a common (input, target) tuple from the features,
            # specify them here. They'll be used if as_supervised=True in
            # builder.as_dataset.
            supervised_keys=None,
            homepage=_HOMEPAGE,
            license=_LICENSE,
            citation=_CITATION,
        )

    def _split_generators(self, dl_manager):
        """Returns SplitGenerators."""
        rs = []
        for split in _SPLIT:
          file= dl_manager.download_and_extract(_DATA_URL.format(split_name=split))
          rs.append(
              datasets.SplitGenerator(
                name=split,
                gen_kwargs={"data_file": file, "split": split },
            ))
        

        return rs


    def _generate_examples(self, data_file, split):
        """Yields examples."""
        with open(data_file, encoding="utf-8") as f:
            f = pd.read_csv(f).to_dict('records')
            for idx, row in enumerate(f):
                yield idx, row