Commit ·
9f6c3f7
1
Parent(s): 8e26e1d
multi_news dataset
Browse files- multi_news.py +105 -0
multi_news.py
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
"""Multi-News dataset."""
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
import os
|
| 21 |
+
|
| 22 |
+
import datasets
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
_CITATION = """
|
| 26 |
+
@misc{alex2019multinews,
|
| 27 |
+
title={Multi-News: a Large-Scale Multi-Document Summarization Dataset and Abstractive Hierarchical Model},
|
| 28 |
+
author={Alexander R. Fabbri and Irene Li and Tianwei She and Suyi Li and Dragomir R. Radev},
|
| 29 |
+
year={2019},
|
| 30 |
+
eprint={1906.01749},
|
| 31 |
+
archivePrefix={arXiv},
|
| 32 |
+
primaryClass={cs.CL}
|
| 33 |
+
}
|
| 34 |
+
"""
|
| 35 |
+
|
| 36 |
+
_DESCRIPTION = """
|
| 37 |
+
Multi-News, consists of news articles and human-written summaries
|
| 38 |
+
of these articles from the site newser.com.
|
| 39 |
+
Each summary is professionally written by editors and
|
| 40 |
+
includes links to the original articles cited.
|
| 41 |
+
|
| 42 |
+
There are two features:
|
| 43 |
+
- document: text of news articles seperated by special token "|||||".
|
| 44 |
+
- summary: news summary.
|
| 45 |
+
"""
|
| 46 |
+
|
| 47 |
+
_URL = "https://drive.google.com/uc?export=download&id=1vRY2wM6rlOZrf9exGTm5pXj5ExlVwJ0C"
|
| 48 |
+
|
| 49 |
+
_DOCUMENT = "document"
|
| 50 |
+
_SUMMARY = "summary"
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
class MultiNews(datasets.GeneratorBasedBuilder):
|
| 54 |
+
"""Multi-News dataset."""
|
| 55 |
+
|
| 56 |
+
VERSION = datasets.Version("1.0.0")
|
| 57 |
+
|
| 58 |
+
def _info(self):
|
| 59 |
+
return datasets.DatasetInfo(
|
| 60 |
+
description=_DESCRIPTION,
|
| 61 |
+
features=datasets.Features({_DOCUMENT: datasets.Value("string"), _SUMMARY: datasets.Value("string")}),
|
| 62 |
+
supervised_keys=(_DOCUMENT, _SUMMARY),
|
| 63 |
+
homepage="https://github.com/Alex-Fabbri/Multi-News",
|
| 64 |
+
citation=_CITATION,
|
| 65 |
+
)
|
| 66 |
+
|
| 67 |
+
def _split_generators(self, dl_manager):
|
| 68 |
+
"""Returns SplitGenerators."""
|
| 69 |
+
extract_path = os.path.join(dl_manager.download_and_extract(_URL), "multi-news-original")
|
| 70 |
+
return [
|
| 71 |
+
datasets.SplitGenerator(
|
| 72 |
+
name=datasets.Split.TRAIN,
|
| 73 |
+
gen_kwargs={"path": os.path.join(extract_path, "train")},
|
| 74 |
+
),
|
| 75 |
+
datasets.SplitGenerator(
|
| 76 |
+
name=datasets.Split.VALIDATION,
|
| 77 |
+
gen_kwargs={"path": os.path.join(extract_path, "val")},
|
| 78 |
+
),
|
| 79 |
+
datasets.SplitGenerator(
|
| 80 |
+
name=datasets.Split.TEST,
|
| 81 |
+
gen_kwargs={"path": os.path.join(extract_path, "test")},
|
| 82 |
+
),
|
| 83 |
+
]
|
| 84 |
+
|
| 85 |
+
def _generate_examples(self, path=None):
|
| 86 |
+
"""Yields examples."""
|
| 87 |
+
with open(os.path.join(path + ".src"), encoding="utf-8") as src_f, open(
|
| 88 |
+
os.path.join(path + ".tgt"), encoding="utf-8"
|
| 89 |
+
) as tgt_f:
|
| 90 |
+
for i, (src_line, tgt_line) in enumerate(zip(src_f, tgt_f)):
|
| 91 |
+
yield i, {
|
| 92 |
+
# In original file, each line has one example and natural newline
|
| 93 |
+
# tokens "\n" are being replaced with "NEWLINE_CHAR". Here restore
|
| 94 |
+
# the natural newline token to avoid special vocab "NEWLINE_CHAR".
|
| 95 |
+
_DOCUMENT: src_line.strip().replace("NEWLINE_CHAR", "\n"),
|
| 96 |
+
# Remove the starting token "- " for every target sequence.
|
| 97 |
+
_SUMMARY: tgt_line.strip().lstrip("- "),
|
| 98 |
+
}
|
| 99 |
+
|
| 100 |
+
|
| 101 |
+
if __name__ == '__main__':
|
| 102 |
+
from datasets import load_dataset
|
| 103 |
+
|
| 104 |
+
ssfd_debug = load_dataset("multi_news.py")
|
| 105 |
+
x = 5
|