"""Build chat examples from the Bokmaal Qwen3 Magpie release. Source: versae/magpie-qwen3-235B-A22B-bokmaal Revision: e47dc5c0f510425ec0ee064657467803e3477edf """ from __future__ import annotations from collections.abc import Iterator from pathlib import Path import langid from datasets import load_dataset from dynainst.build_utils import build_dataset SOURCE = "magpie-qwen3-bokmaal" HF_DATASET = "versae/magpie-qwen3-235B-A22B-bokmaal" REVISION = "e47dc5c0f510425ec0ee064657467803e3477edf" ADDED = "2026-09-03" CREATED = "2025-05-01, 2025-05-31" SAVE_DIR = Path(__file__).parent REASONING_CATEGORIES = {"reasoning", "math", "data-analysis"} NORWEGIAN_LANGUAGE_LABELS = {"nb", "nn", "no"} # Restrict the classifier to the languages relevant to this release. The upstream # dataset contains English prompt/response generations despite its Bokmaal label. langid.set_languages(["en", *sorted(NORWEGIAN_LANGUAGE_LABELS)]) def task_for(category: str) -> str: if category == "coding": return "code" if category in REASONING_CATEGORIES: return "reasoning" if category == "editing": return "instruction_following" return "general" def convert(raw) -> Iterator[dict]: for index, row in enumerate(raw): instruction = row["instruction"].strip() response = row["response"].strip() if langid.classify(instruction)[0] not in NORWEGIAN_LANGUAGE_LABELS: continue if langid.classify(response)[0] not in NORWEGIAN_LANGUAGE_LABELS: continue messages = [] if row["system"].strip(): messages.append({"role": "system", "content": row["system"].strip()}) messages.extend( [ {"role": "user", "content": instruction}, {"role": "assistant", "content": response}, ] ) yield { "id": f"{SOURCE}_{index:05d}", "messages": messages, "source": SOURCE, "added": ADDED, "created": CREATED, "language": ["nob"], "task": task_for(row["category"]), "token_count": -1, } def main() -> None: raw = load_dataset(HF_DATASET, revision=REVISION, split="train") output_path = SAVE_DIR / f"{SOURCE}.parquet" dataset = build_dataset(convert(raw), output_path=output_path) print(f"Wrote {len(dataset):,} samples to {output_path}") if __name__ == "__main__": main()