File size: 3,187 Bytes
d984235
 
9c9fada
d984235
9c9fada
 
 
 
 
 
d984235
5b8b0eb
 
9c9fada
 
 
 
 
 
 
 
 
 
 
 
2f89d3e
9c9fada
 
 
 
 
 
 
 
 
 
 
 
 
795b8e8
 
 
9c9fada
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5b8b0eb
9c9fada
 
 
5b8b0eb
51d9464
5b8b0eb
 
 
 
 
9c9fada
 
 
 
d984235
34d8538
d984235
 
9c9fada
d984235
 
 
 
 
9c9fada
 
 
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
89
90
91
92
93
94
import json

import datasets
import pandas as pd

_CITATION = """"""
_DESCRIPTION = """"""
_LICENSE = "CC-BY-SA-4.0"
# _URL = "https://github.com/boostcampaitech2/data-annotation-nlp-level3-nlp-14"
_DATA_URLS = {
    "train": "https://huggingface.co/datasets/raki-1203/ai_hub_summarization/resolve/main/train_dict.json",
    "valid": "https://huggingface.co/datasets/raki-1203/ai_hub_summarization/resolve/main/valid_dict.json",
    "test": "https://huggingface.co/datasets/raki-1203/ai_hub_summarization/resolve/main/test_dict.json",
}

_VERSION = "0.0.0"


class AiHubSummarizationConfig(datasets.BuilderConfig):
    def __init__(self, data_url, **kwargs):
        super().__init__(version=datasets.Version(_VERSION), **kwargs)
        self.data_url = data_url


class AiHubSummarization(datasets.GeneratorBasedBuilder):
    DEFAULT_CONFIG_NAME = "ai_hub_summarization"
    BUILDER_CONFIGS = [
        AiHubSummarizationConfig(
            name="ai_hub_summarization",
            data_url=_DATA_URLS,
            description=_DESCRIPTION,
        )
    ]

    def _info(self):
        return datasets.DatasetInfo(
            description=_DESCRIPTION,
            features=datasets.Features(
                {
                    "data_name": datasets.Value("string"),
                    "doc_id": datasets.Value("string"),
                    "doc_name": datasets.Value("string"),
                    "passage": datasets.Value("string"),
                    "abstract_summary": datasets.Value("string"),
                }
            ),
            license=_LICENSE,
            citation=_CITATION,
            supervised_keys=None,
        )

    def _split_generators(self, dl_manager):
        """ Returns SplitGenerators. """
        data_file = dl_manager.download_and_extract(self.config.data_url)
        return [
            datasets.SplitGenerator(
                name=datasets.Split.TRAIN,
                gen_kwargs={
                    "data_file": data_file["train"],
                    "split": "train",
                },
            ),
            datasets.SplitGenerator(
                name=datasets.Split.VALIDATION,
                gen_kwargs={
                    "data_file": data_file["valid"],
                    "split": "valid",
                },
            ),
            datasets.SplitGenerator(
                name=datasets.Split.TEST,
                gen_kwargs={
                    "data_file": data_file["test"],
                    "split": "test",
                },
            ),
        ]

    def _generate_examples(self, data_file: str, split: str):
        """ Yields examples. """
        with open(data_file, newline='', encoding="UTF-8") as f:
            json_file = json.load(f)
            df = pd.DataFrame(json_file)
            for idx, row in df.iterrows():
                features = {
                    "data_name": row['data_name'],
                    "doc_id": row['doc_id'],
                    "doc_name": row['doc_name'],
                    "passage": row['passage'],
                    "abstract_summary": row['abstract_summary'],
                }
                yield idx, features
                idx += 1