Download prepare_sft_data.py from Nrighton233j/App.ai: direct link, hf CLI and curl.
- Browser
- Download file 5.26 kB
-
https://huggingface.co/datasets/Nrighton233j/App.ai/resolve/main/prepare_sft_data.py
- Command line
-
hf download hf://datasets/Nrighton233j/App.ai/prepare_sft_data.py
-
curl -L -o prepare_sft_data.py https://huggingface.co/datasets/Nrighton233j/App.ai/resolve/main/prepare_sft_data.py
5.26 kB
| import json | |
| from datasets import load_dataset | |
| OUTPUT_FILE = "sft_data.jsonl" | |
| import os | |
| HF_TOKEN = os.environ.get("HF_TOKEN") | |
| out = open(OUTPUT_FILE, "w") | |
| total_examples = 0 | |
| def write_example(messages): | |
| global total_examples | |
| if not messages or len(messages) < 2: | |
| return | |
| out.write(json.dumps({"messages": messages}) + "\n") | |
| total_examples += 1 | |
| # --------------------------------------------------------------------------- | |
| # 1. OpenHermes 2.5 — ShareGPT format: "conversations" list of {from, value} | |
| # --------------------------------------------------------------------------- | |
| print("=== OpenHermes 2.5 ===") | |
| hermes = load_dataset("teknium/OpenHermes-2.5", split="train", streaming=True) | |
| count = 0 | |
| LIMIT = 75_000 | |
| role_map = {"human": "user", "gpt": "assistant", "system": "system"} | |
| for row in hermes: | |
| convo = row.get("conversations", []) | |
| messages = [] | |
| for turn in convo: | |
| role = role_map.get(turn.get("from", ""), "user") | |
| messages.append({"role": role, "content": turn.get("value", "")}) | |
| write_example(messages) | |
| count += 1 | |
| if count >= LIMIT: | |
| break | |
| print(f"OpenHermes: {count:,} examples") | |
| # --------------------------------------------------------------------------- | |
| # 2. UltraChat — "data" field: list of alternating strings (user/assistant) | |
| # --------------------------------------------------------------------------- | |
| print("=== UltraChat ===") | |
| ultrachat = load_dataset("stingning/ultrachat", split="train", streaming=True) | |
| count = 0 | |
| LIMIT = 75_000 | |
| for row in ultrachat: | |
| turns = row.get("data", []) | |
| messages = [] | |
| for i, text in enumerate(turns): | |
| role = "user" if i % 2 == 0 else "assistant" | |
| messages.append({"role": role, "content": text}) | |
| write_example(messages) | |
| count += 1 | |
| if count >= LIMIT: | |
| break | |
| print(f"UltraChat: {count:,} examples") | |
| # --------------------------------------------------------------------------- | |
| # 3. Magicoder-OSS-Instruct — single-turn: "problem" / "solution" fields | |
| # --------------------------------------------------------------------------- | |
| print("=== Magicoder-OSS-Instruct ===") | |
| magicoder = load_dataset("ise-uiuc/Magicoder-OSS-Instruct-75K", split="train", streaming=True) | |
| count = 0 | |
| for row in magicoder: | |
| problem = row.get("problem", "") | |
| solution = row.get("solution", "") | |
| if not problem or not solution: | |
| continue | |
| messages = [ | |
| {"role": "user", "content": problem}, | |
| {"role": "assistant", "content": solution}, | |
| ] | |
| write_example(messages) | |
| count += 1 | |
| print(f"Magicoder: {count:,} examples") | |
| # --------------------------------------------------------------------------- | |
| # 4. s1K — reasoning traces. Field names vary by version, try common ones. | |
| # --------------------------------------------------------------------------- | |
| print("=== s1K ===") | |
| try: | |
| s1k = load_dataset("simplescaling/s1K-1.1", split="train") | |
| except Exception: | |
| s1k = load_dataset("simplescaling/s1K", split="train") | |
| count = 0 | |
| for row in s1k: | |
| question = row.get("question", "") or row.get("problem", "") | |
| reasoning = (row.get("deepseek_thinking_trajectory", "") | |
| or row.get("thinking_trajectories", "") | |
| or row.get("cot", "")) | |
| answer = (row.get("deepseek_attempt", "") | |
| or row.get("solution", "") | |
| or row.get("answer", "")) | |
| if not question or not answer: | |
| continue | |
| assistant_content = f"<think>{reasoning}</think>\n{answer}" if reasoning else answer | |
| messages = [ | |
| {"role": "user", "content": question}, | |
| {"role": "assistant", "content": assistant_content}, | |
| ] | |
| write_example(messages) | |
| count += 1 | |
| print(f"s1K: {count:,} examples") | |
| # --------------------------------------------------------------------------- | |
| # 5. OpenThoughts-114k — ShareGPT-style "conversations" field | |
| # --------------------------------------------------------------------------- | |
| print("=== OpenThoughts-114k ===") | |
| openthoughts = load_dataset("open-thoughts/OpenThoughts-114k", split="train", streaming=True) | |
| count = 0 | |
| for row in openthoughts: | |
| convo = row.get("conversations", []) | |
| messages = [] | |
| for turn in convo: | |
| role = role_map.get(turn.get("from", ""), "user") | |
| messages.append({"role": role, "content": turn.get("value", "")}) | |
| write_example(messages) | |
| count += 1 | |
| print(f"OpenThoughts: {count:,} examples") | |
| # --------------------------------------------------------------------------- | |
| # 6. Function calling — Glaive v2, sample ~25k | |
| # --------------------------------------------------------------------------- | |
| print("=== Glaive Function Calling v2 ===") | |
| glaive = load_dataset("glaiveai/glaive-function-calling-v2", split="train", streaming=True) | |
| count = 0 | |
| LIMIT = 25_000 | |
| for row in glaive: | |
| system = row.get("system", "") | |
| chat = row.get("chat", "") | |
| if not chat: | |
| continue | |
| messages = [] | |
| if system: | |
| messages.append({"role": "system", "content": system}) | |
| messages.append({"role": "user", "content": chat}) | |
| write_example(messages) | |
| count += 1 | |
| if count >= LIMIT: | |
| break | |
| print(f"Glaive: {count:,} examples") | |
| out.close() | |
| print(f"=== DONE: {total_examples:,} total examples written to {OUTPUT_FILE} ===") | |