Datasets:

Modalities:
Text
Formats:
json
ArXiv:
Libraries:
Datasets
Dask
License:
File size: 5,637 Bytes
b92d15e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
# Copyright 2020 The HuggingFace Datasets Authors and
# the Johns Hopkins University (JHU) Human Language Technology
# Center of Excellence.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""
This file provides a HuggingFace dataset loader implementation for
the JHU/HLTCOE MegaWika dataset, specifically for a report generation
or multi-doc summarization dataset using the raw MegaWika


MegaWika is a multi- and crosslingual text dataset containing 30 million
Wikipedia passages with their scraped and cleaned web citations. The
passages span 50 Wikipedias in 50 languages, and the articles in which
the passages were originally embedded are included for convenience. Where
a Wikipedia passage is in a non-English language, an automated English
translation is provided. 
"""


import json
import os

import datasets


_CITATION = """\
@misc{barham2023megawika,
      title={MegaWika: Millions of reports and their sources across 50 diverse languages}, 
      author={Samuel Barham and and  Weller and Michelle Yuan and Kenton Murray and Mahsa Yarmohammadi and Zhengping Jiang and Siddharth Vashishtha and Alexander Martin and Anqi Liu and Aaron Steven White and Jordan Boyd-Graber and Benjamin Van Durme},
      year={2023},
      eprint={2307.07049},
      archivePrefix={arXiv},
      primaryClass={cs.CL}
}
"""

_DESCRIPTION = """\
MegaWika is a multi- and crosslingual text dataset containing 30 million
Wikipedia passages with their scraped and cleaned web citations. The
passages span 50 Wikipedias in 50 languages, and the articles in which
the passages were originally embedded are included for convenience. Where
a Wikipedia passage is in a non-English language, an automated English
translation is provided. 
"""

_URL = "https://huggingface.co/datasets/hltcoe/megawika"


class MegaWikaReportGenerationConfig(datasets.BuilderConfig):
    """BuilderConfig for MegaWikaReportGeneration."""

    def __init__(self, language: str = "en", monolingual: bool = True, iterative: bool = False, **kwargs):
        """BuilderConfig for MegaWikaReportGeneration.
        """
        super(MegaWikaReportGenerationConfig, self).__init__(**kwargs)
        self.language = language
        self.monolingual = monolingual
        self.iterative = iterative


class MegaWikaReportGeneration(datasets.GeneratorBasedBuilder):
    """The MegaWikaReportGeneration benchmark."""

    BUILDER_CONFIGS = [
        MegaWikaReportGenerationConfig(
            name="monolingual-section",
            monolingual=True,
            iterative=False,
        ),
        MegaWikaReportGenerationConfig(
            name="crosslingual-section",
            monolingual=False,
            iterative=False,
        ),
        MegaWikaReportGenerationConfig(
            name="monolingual-iterative",
            monolingual=True,
            iterative=True,
        ),
        MegaWikaReportGenerationConfig(
            name="crosslingual-iterative",
            monolingual=False,
            iterative=True,
        ),
    ]

    def _info(self):
        features = {}
        features["id"] = datasets.Value("string")
        features["num_docs"] = datasets.Value("int32")
        features["title"] = datasets.Value("string")
        features["intro"] = datasets.Value("string")
        features["section_name"] = datasets.Value("string")
        features["gold_section_text"] = datasets.Value("string")
        features["citations"] = datasets.features.Sequence(datasets.Value("string"))
        features["previous_text"] = datasets.Value("string")
        return datasets.DatasetInfo(
            description=_DESCRIPTION,
            features=datasets.Features(features),
            homepage=_URL,
            citation=_CITATION,
        )

    def _split_generators(self, dl_manager):
        dl_dir = dl_manager.download_and_extract(self.config.url) or ""
        dl_dir = os.path.join(dl_dir, "mono" if self.config.monolingual else "cl", "iterative" if self.config.iterative else "section", self.config.language)
        return [
            datasets.SplitGenerator(
                name=datasets.Split.TRAIN,
                gen_kwargs={
                    "data_file": os.path.join(dl_dir, "train.jsonl"),
                    "split": datasets.Split.TRAIN,
                },
            ),
            datasets.SplitGenerator(
                name=datasets.Split.VALIDATION,
                gen_kwargs={
                    "data_file": os.path.join(dl_dir, "dev.jsonl"),
                    "split": datasets.Split.VALIDATION,
                },
            ),
            datasets.SplitGenerator(
                name=datasets.Split.TEST,
                gen_kwargs={
                    "data_file": os.path.join(dl_dir, "test.jsonl"),
                    "split": datasets.Split.TEST,
                },
            ),
        ]

    def _generate_examples(self, data_file, split):
        with open(data_file, encoding="utf-8") as f:
            for idx, line in enumerate(f):
                row = json.loads(line)
                if "previous_text" not in row:
                    row["previous_text"] = ""
                yield idx, row