newshead / newshead.py
ratishsp's picture
fixed path
8f7568a
import os
import json
import datasets
from datasets import DownloadManager
_URL = "data.zip"
class NewsHeadDataset(datasets.GeneratorBasedBuilder):
def _info(self):
return datasets.DatasetInfo(
description = "newshead multi document summarisation dataset",
features = datasets.Features(
{
"documents": datasets.Value("string"),
"summary": datasets.Value("string")
}
)
)
def _split_generators(self, dl_manager: DownloadManager):
data_dir = dl_manager.download_and_extract(_URL)
return [
datasets.SplitGenerator(
name=datasets.Split.TRAIN,
gen_kwargs = {
"filepath": os.path.join(data_dir, "train.jsonl"),
"split": "train"
}
),
datasets.SplitGenerator(
name=datasets.Split.VALIDATION,
gen_kwargs = {
"filepath": os.path.join(data_dir, "validation.jsonl"),
"split": "validation"
}
),
datasets.SplitGenerator(
name=datasets.Split.TEST,
gen_kwargs = {
"filepath": os.path.join(data_dir, "validation.jsonl"),
"split": "test"
}
)
]
def _generate_examples(self, filepath, split):
with open(filepath, encoding="utf-8") as f:
for id_, row in enumerate(f):
data = json.loads(row)
yield id_, {
"documents": data["text"],
"summary": data["summary"]
}