KennethEnevoldsen's picture V4ldeLund's picture
Add fo-instruct (#2)
3523f72
Raw History Blame Contribute Delete
1.58 kB
# /// script
# requires-python = ">=3.12,<3.13"
# dependencies = ["dynainst==0.1.1"]
# [tool.uv.sources]
# dynainst = { path = "../.." }
# ///
"""Import FO-Instruct. Run with `uv run data/fo-instruct/create.py`."""
from pathlib import Path
from datasets import Dataset, load_dataset
from dynainst.process_dataset import (
add_token_count,
ensure_column_order,
remove_duplicate_messages,
remove_empty_messages,
)
SOURCE = "fo-instruct"
HF_DATASET = "Setur/fo-instruct"
REVISION = "55a97b043e1a3f2778492c72bf124f4091341402"
SAVE_DIR = Path(__file__).parent
ADDED = "2026-10-05"
CREATED = "2026-01-01, 2026-12-31"
def convert_sample(row: dict, index: int) -> dict:
return {
"id": f"{SOURCE}_{index:05d}",
"messages": [
{"role": "user", "content": row["instruction"]},
{"role": "assistant", "content": row["output"]},
],
"source": SOURCE,
"added": ADDED,
"created": CREATED,
"language": ["fao"],
"task": "general",
"token_count": -1,
}
def main() -> None:
raw = load_dataset(HF_DATASET, split="train", revision=REVISION)
ds = Dataset.from_list(
[convert_sample(row, index) for index, row in enumerate(raw)]
)
ds = add_token_count(ds)
ds = remove_duplicate_messages(ds)
ds = remove_empty_messages(ds)
ds = ensure_column_order(ds)
out_path = SAVE_DIR / f"{SOURCE}.parquet"
ds.to_parquet(str(out_path))
print(f"Saved {len(ds):,} of {len(raw):,} samples to {out_path}")
if __name__ == "__main__":
main()