""" This scripts download nordjylland news and converts it to the format of danish dynaword """ import random from pathlib import Path from typing import cast from datasets import Dataset, load_dataset 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}", ] source = "nordjyllandnews" def convert_sample(example): schema = random.choice(schemas) new_example = dict( text_new=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={"source-pretty": "Nordjylland News"}, ) return new_example def main(): ds = load_dataset("alexandrainst/nordjylland-news-summarization", split="train") ds = cast(Dataset, ds) ds = ds.map(convert_sample, remove_columns=ds.column_names) ds = ds.rename_columns({"text_new": "text"}) ds = ds.add_column("id", [f"{source}_{i}" for i in range(len(ds))]) # type: ignore ds = ds.select_columns( ["text", "source", "id", "added", "created", "license", "domain", "metadata"] ) save_path = Path(__file__).parent / f"{source}.parquet" ds.to_parquet(save_path) if __name__ == "__main__": main()