""" This scripts download nordjylland news and converts it to the format of danish dynaword """ import random from pathlib import Path from datasets import load_dataset source = "nordjyllandnews" ds = load_dataset("alexandrainst/nordjylland-news-summarization", split="train") schemas = [ "{summary}\n\n{text}", "{text}\n\nOpsummering:\n{summary}", "{text}\n\nReferat:\n{summary}", "Lav et referat af nedenstående tekst:\n\nTekst:\n{text}\n\nReferat:\n{summary}", ] def convert_sample(example): schema = random.sample(schemas, k=1)[0] new_example = dict( text=schema.format(text=example["text"], summary=example["summary"]), source=source, domain="News", license="Creative Commons Legal Code\n\nCC0 1.0 Universal", added="2024-12-16", created="2000-01-01, 2024-01-01", # best guess metadata=dict(source_pretty="Nordjylland News"), ) return new_example ds = ds.map(convert_sample) save_path = Path(__file__).parent / f"{source}.parquet" ds.to_parquet(save_path)