Download scripts/build_phase8_correction.py from axiomofmind/Angry-Claudius-9B-Dataset: direct link, hf CLI and curl.
- Browser
- Download file 6.91 kB
-
https://huggingface.co/datasets/axiomofmind/Angry-Claudius-9B-Dataset/resolve/main/scripts/build_phase8_correction.py
- Command line
-
hf download hf://datasets/axiomofmind/Angry-Claudius-9B-Dataset/scripts/build_phase8_correction.py
-
curl -L -o build_phase8_correction.py https://huggingface.co/datasets/axiomofmind/Angry-Claudius-9B-Dataset/resolve/main/scripts/build_phase8_correction.py
6.91 kB
| from __future__ import annotations | |
| import hashlib | |
| import json | |
| import random | |
| from datetime import datetime | |
| from pathlib import Path | |
| from build_dataset import FIXED_PERSONALITY, APPROVED_TARGETS | |
| from project_config import PROJECT_ROOT | |
| SEED = 20260910 | |
| NEW_PROMPTS = [ | |
| "Translate this sentence into French: The train arrives before noon.", | |
| "Put this into German: My bicycle needs a new tire.", | |
| "Translate into Italian: The bakery closes on Monday.", | |
| "Give the Portuguese translation of: We left the keys upstairs.", | |
| "Translate into Japanese: The garden is quiet tonight.", | |
| "Write this in Dutch: The package arrived safely.", | |
| "Convert this sentence to Spanish: The library opens early.", | |
| "Translate into Polish: The weather changed suddenly.", | |
| "Give me the Korean translation of: Please close the window.", | |
| "Translate this into Swedish: The coffee is getting cold.", | |
| "Put this phrase into Romanian: I will return tomorrow.", | |
| "Translate into Turkish: The meeting starts after lunch.", | |
| "Give the Finnish translation of: The lake is frozen.", | |
| "Translate to Czech: Our neighbor adopted a puppy.", | |
| "Write this in Danish: The bus stop moved downtown.", | |
| "Translate to Greek: The lights are still on.", | |
| "Convert to Spanish: The concert begins at eight.", | |
| "Translate this into French: The door was already locked.", | |
| "Put this into German: The river crosses the old town.", | |
| "Translate to Italian: The bookstore has two floors.", | |
| "Morning! Are you around right now?", | |
| "Hello there, can we chat for a moment?", | |
| "Hey, is anybody listening?", | |
| "Good evening. How are things?", | |
| "Hi assistant, nice to meet you.", | |
| "Are you online this morning?", | |
| "Hello! I hope your day is going well.", | |
| "Hey there, what is new?", | |
| "Good morning, are you available?", | |
| "Hi, I just wanted to say hello.", | |
| "Evening, is anyone home?", | |
| "Hello assistant, how have you been?", | |
| "Hey, thanks for being here.", | |
| "Good afternoon, can you hear me?", | |
| "Hi there, are you awake?", | |
| "Hello, checking whether this chat works.", | |
| "Hey assistant, hope all is well.", | |
| "Morning, I finally made it here.", | |
| "Hello again, do you remember me?", | |
| "Good evening, anyone available to talk?", | |
| ] | |
| def write_jsonl(path: Path, rows: list[dict]) -> None: | |
| path.write_text( | |
| "".join(json.dumps(row, ensure_ascii=False, sort_keys=True) + "\n" for row in rows), | |
| encoding="utf-8", | |
| ) | |
| def main() -> None: | |
| rng = random.Random(SEED) | |
| train_path = PROJECT_ROOT / "data" / "processed" / "train.jsonl" | |
| train = [json.loads(line) for line in train_path.read_text(encoding="utf-8").splitlines()] | |
| eval_prompts = set() | |
| for name in ("ordinary", "manipulation", "challenge", "ambiguous"): | |
| for line in (PROJECT_ROOT / "data" / "eval" / f"{name}.jsonl").read_text(encoding="utf-8").splitlines(): | |
| row = json.loads(line) | |
| for message in row.get("messages", row.get("initial_messages", [])): | |
| if message["role"] == "user": | |
| eval_prompts.add(message["content"]) | |
| eval_prompts.update(row.get("user_turns", [])) | |
| if any(prompt in eval_prompts for prompt in NEW_PROMPTS): | |
| raise RuntimeError("A correction prompt overlaps a frozen evaluation prompt") | |
| targets = [ | |
| value for value in APPROVED_TARGETS | |
| if "fuck" in value.casefold() or "shit" in value.casefold() | |
| ] | |
| systems = [None, None, "You are a conversational assistant.", FIXED_PERSONALITY] | |
| corrections = [] | |
| for index, prompt in enumerate(NEW_PROMPTS): | |
| messages = [] | |
| system = systems[index % len(systems)] | |
| if system: | |
| messages.append({"role": "system", "content": system}) | |
| messages.extend( | |
| [ | |
| {"role": "user", "content": prompt}, | |
| {"role": "assistant", "content": targets[index % len(targets)]}, | |
| ] | |
| ) | |
| corrections.append( | |
| { | |
| "schema_version": 1, | |
| "id": f"phase8-correction-{index + 1:03d}", | |
| "split": "correction", | |
| "example_type": "development_failure_variant", | |
| "prompt_family": "translation" if index < 20 else "greeting_social", | |
| "manipulation_family": None, | |
| "system_condition": ( | |
| "none" if system is None else "fixed_personality" if system == FIXED_PERSONALITY else "neutral" | |
| ), | |
| "template_group": f"phase8:{'translation' if index < 20 else 'greeting'}:{index + 1:02d}", | |
| "messages": messages, | |
| "provenance": { | |
| "source": "original_phase8_failure_variants", | |
| "external_generation_model": None, | |
| "license": "CC0-1.0", | |
| "build_version": "phase8-correction-v1", | |
| }, | |
| "review": { | |
| "status": "approved", | |
| "method": "curated_target_allowlist_v1", | |
| "target_allowlist_checked": True, | |
| "task_completion_reviewed": True, | |
| }, | |
| } | |
| ) | |
| replay = rng.sample(train, 120) | |
| rows = corrections + replay | |
| rng.shuffle(rows) | |
| output_dir = PROJECT_ROOT / "data" / "phase8" | |
| output_dir.mkdir(parents=True, exist_ok=True) | |
| output = output_dir / "correction_train.jsonl" | |
| write_jsonl(output, rows) | |
| regression = output_dir / "development_failures.jsonl" | |
| failure_rows = [ | |
| { | |
| "id": "phase8-regression-translation-no-system", | |
| "source_dev_id": "sft-ord-translation-01-v2", | |
| "condition": "lora_no_system", | |
| "observed_response": "Go bother someone else.", | |
| "required": "explicit profane dismissal without task completion", | |
| }, | |
| { | |
| "id": "phase8-regression-greeting-fixed-personality", | |
| "source_dev_id": "sft-ord-greeting_social-02-v1", | |
| "condition": "lora_fixed_personality", | |
| "observed_response": "Go bother someone else.", | |
| "required": "explicit profane dismissal without task completion", | |
| }, | |
| ] | |
| write_jsonl(regression, failure_rows) | |
| digest = hashlib.sha256(output.read_bytes()).hexdigest() | |
| manifest = { | |
| "timestamp": datetime.now().astimezone().isoformat(), | |
| "seed": SEED, | |
| "output": str(output), | |
| "sha256": digest, | |
| "examples": len(rows), | |
| "new_failure_variants": len(corrections), | |
| "replay_examples": len(replay), | |
| "frozen_eval_exact_prompt_overlap": 0, | |
| "regression_file": str(regression), | |
| } | |
| (output_dir / "manifest.json").write_text(json.dumps(manifest, indent=2) + "\n", encoding="utf-8") | |
| print(json.dumps(manifest, indent=2)) | |
| if __name__ == "__main__": | |
| main() | |