Download utils/filter_seeds.py from ModhiSathvik/diffuzamba-phase2-pipeline: direct link, hf CLI and curl.
- Browser
- Download file 4.64 kB
-
https://huggingface.co/datasets/ModhiSathvik/diffuzamba-phase2-pipeline/resolve/main/utils/filter_seeds.py
- Command line
-
hf download hf://datasets/ModhiSathvik/diffuzamba-phase2-pipeline/utils/filter_seeds.py
-
curl -L -o filter_seeds.py https://huggingface.co/datasets/ModhiSathvik/diffuzamba-phase2-pipeline/resolve/main/utils/filter_seeds.py
4.64 kB
| """Filter a base seed file by exclusion keywords for a specific format. | |
| Usage: | |
| python utils/filter_seeds.py --subject python --format refinement | |
| python utils/filter_seeds.py --subject python --format code_exercise | |
| Reads: seeds/{subject}.json | |
| Writes: seeds/{subject}_{format}.json | |
| """ | |
| import argparse | |
| import json | |
| import os | |
| import random | |
| EXCLUSIONS = { | |
| "refinement": [ | |
| "what is python", "what python is", "history of", "evolution of", | |
| "philosophy", "the zen", "pep process", | |
| "introduction to", "overview of", "getting started", "basics of", | |
| "installing", "downloading", | |
| " vs ", " vs.", "vs python 2", | |
| "syntax overview", "feature overview", | |
| "virtual environments", "venv workflow", "pip basics", | |
| "configuring environment", | |
| "what is the gil", "what is free-threaded", "subinterpreters concept", | |
| "library overview", "module overview", | |
| ], | |
| "code_exercise": [ | |
| "what is python", "what python is", "history of", "evolution of", | |
| "philosophy", "the zen", "pep process", | |
| "introduction to", "overview of", "getting started", "basics of", | |
| "installing", "downloading", | |
| " vs ", " vs.", "vs python 2", | |
| "virtual environments", "venv workflow", "pip basics", | |
| "configuring environment", | |
| "what is the gil", "what is free-threaded", | |
| "decorators concept", "metaclass philosophy", | |
| "design patterns overview", | |
| ], | |
| "debug_dialogue": [ | |
| "what is python", "what python is", "history of", "philosophy", | |
| "the zen", "pep process", | |
| "introduction to", "overview of", "getting started", | |
| "installing", "downloading", "configuring environment", | |
| ], | |
| "infilling": [ | |
| # Same as code_exercise — drop topics that aren't code-shaped | |
| "what is python", "what python is", "history of", "evolution of", | |
| "philosophy", "the zen", "pep process", | |
| "introduction to", "overview of", "getting started", "basics of", | |
| "installing", "downloading", | |
| " vs ", " vs.", "vs python 2", | |
| "virtual environments", "venv workflow", "pip basics", | |
| "configuring environment", | |
| "what is the gil", "what is free-threaded", | |
| "design patterns overview", | |
| ], | |
| "instruction_reversal": [ | |
| # Drop topics that aren't code-shaped | |
| "what is python", "what python is", "history of", "evolution of", | |
| "philosophy", "the zen", "pep process", | |
| "introduction to", "overview of", "getting started", "basics of", | |
| "installing", "downloading", | |
| " vs ", " vs.", "vs python 2", | |
| "virtual environments", "venv workflow", "pip basics", | |
| "configuring environment", | |
| "what is the gil", "what is free-threaded", | |
| "design patterns overview", | |
| ], | |
| } | |
| def filter_topics(topics, keywords): | |
| def matches(topic): | |
| lower = topic.lower() | |
| return any(kw in lower for kw in keywords) | |
| return [t for t in topics if not matches(t)] | |
| def main(): | |
| p = argparse.ArgumentParser() | |
| p.add_argument("--subject", required=True) | |
| p.add_argument("--format", required=True, | |
| choices=list(EXCLUSIONS.keys()) + ["textbook", "worked_example"]) | |
| p.add_argument("--show", type=int, default=5) | |
| args = p.parse_args() | |
| base = f"seeds/{args.subject}.json" | |
| out = f"seeds/{args.subject}_{args.format}.json" | |
| if not os.path.exists(base): | |
| raise SystemExit(f"Base seed file not found: {base}") | |
| all_topics = json.load(open(base)) | |
| print(f"Base seeds ({base}): {len(all_topics)}") | |
| if args.format not in EXCLUSIONS: | |
| print(f"Format '{args.format}' accepts all topics; copying as-is.") | |
| kept = all_topics | |
| excluded = [] | |
| else: | |
| keywords = EXCLUSIONS[args.format] | |
| kept = filter_topics(all_topics, keywords) | |
| excluded = [t for t in all_topics if t not in set(kept)] | |
| print(f"Filter keywords: {len(keywords)}") | |
| print(f"\nKept: {len(kept)} ({len(kept)/len(all_topics):.1%})") | |
| print(f"Excluded: {len(excluded)} ({len(excluded)/len(all_topics):.1%})") | |
| with open(out, "w") as f: | |
| json.dump(kept, f, indent=2) | |
| print(f"\nSaved: {out}") | |
| if args.show and kept: | |
| print(f"\nKept (random {args.show}):") | |
| for t in random.sample(kept, min(args.show, len(kept))): | |
| print(f" + {t}") | |
| if args.show and excluded: | |
| print(f"\nExcluded (random {args.show}):") | |
| for t in random.sample(excluded, min(args.show, len(excluded))): | |
| print(f" - {t}") | |
| if __name__ == "__main__": | |
| main() | |