Datasets:
Tasks:
Text Generation
Modalities:
Text
Formats:
parquet
Sub-tasks:
language-modeling
Languages:
Danish
Size:
100K - 1M
License:
restructure-datasets
#11
by
KennethEnevoldsen
- opened
This pr fixes:
- https://huggingface.co/datasets/danish-foundation-models/danish-gigaword-2/discussions/2
- https://huggingface.co/datasets/danish-foundation-models/danish-gigaword-2/discussions/1
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:
- deleting cache
- Running
from datasets import load_dataset
ds = load_dataset("../.", split="train")
ds[0] # looks correct
- Running
make test
seeing that everything passed. - lastly I ran
make bump-version
KennethEnevoldsen
changed pull request status to
open
KennethEnevoldsen
changed pull request status to
merged