File size: 4,642 Bytes
bc5d6b0 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 | """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()
|