Danish Foundation Models org
edited 9 days ago

This pr fixes:

by re-ordering columns to the following format:

{'text': 'SAMLEDE VÆRKER\n\nJEPPE AAKJÆR GYLDENDALSKE BOGHANDEL...'
 'source': 'adl',
 'id': 'adl_aakjaer06val',
 'added': '2020-09-14',
 'created': '1700-01-01, 2022-01-01',
 'license': 'Creative Commons Legal Code\n\nCC0 1.0 Universal',
 'domain': 'Wiki & Books',
 'metadata': {'source-pretty': 'Archive for Danish Literature'}
}

It uses the following code:

from pathlib import Path

from datasets import load_dataset


source_dir = Path(__file__).parent.parent / "data"
sources = [p.name for p in source_dir.glob("*")]


for source in sources:
    ds = load_dataset("../.", source, split="train")

    def restructure_example(example: dict):
        example["license"] = example["metadata"].pop("license")
        example["domain"] = example["metadata"].pop("domain")
        example["tmp"] = {"source-pretty": example["metadata"]["source-pretty"].strip()}
        return example

    def add_metadata(example):
        example["metadata"] = {
            "source-pretty": example["metadata"]["source-pretty"].strip()
        }
        return example

    ds = ds.map(restructure_example, remove_columns=["metadata"])
    ds = ds.rename_columns({"tmp": "metadata"})

    column_order = [
        "text",
        "source",
        "id",
        "added",
        "created",
        "license",
        "domain",
        "metadata",
    ]
    ds = ds.select_columns(column_order)

    file = Path(__file__).parent.parent / "data" / source / f"{source}.parquet"
    ds.to_parquet(file)

I checked that it all worked using:

  1. deleting cache
  2. Running
from datasets import load_dataset
ds = load_dataset("../.", split="train")
ds[0] # looks correct
  1. Running make test seeing that everything passed.
  2. lastly I ran make bump-version
KennethEnevoldsen changed pull request status to open
KennethEnevoldsen changed pull request status to merged

Sign up or log in to comment