README 标题可使训练命令被优先标为推理或评估
原文依据:6 处分类器在检查入口脚本名称之前就接受章节标题的分类。例如,位于“Demo”章节中的 train.py 会先被标为推理。后续结构检查仅在脚本可解析、位于目录内、不超过 512 KiB,且检测分数达到阈值时才改回训练;模块入口、缺失脚本或不匹配其有限模式的训练代码可能绕过纠正。
如果下游把分类用作训练授权或成本控制门槛,实际训练任务可能被当作较低风险的推理或评估任务,消耗大量计算资源、修改模型输出或启动长时间作业。
该分类绕过成立。`classify` 在入口脚本规则之前直接返回章节分类,所以“Demo”下的 `train.py` 最初会成为 inference。纠正机制只检查仓库目录内、存在且不超过 512 KiB 的直接 `.py` 路径,并要求有限训练特征总分至少为 4;模块入口、缺失/较大脚本或采用其他训练结构的代码不会被纠正。这可能使计划把训练误当成较低风险推理,但本技能自身仍不执行它。用户可要求作者让明确的训练入口优先于标题,并把无法检查的入口标为不确定。
# authorization when both appear in the same title. if any(word in lowered for word in ["training", "train", "finetune", "fine-tune", "pretrain"]): return "training" if any(word in lowered for word in ["evaluation", "evaluate", "benchmark", "metrics", "validation"]) or re.search( r"\b(?:test|tests|testing)\b", lowered ): return "evaluation" if any(word in lowered for word in ["inference", "usage", "demo", "example", "text-to-image", "image-to-image", "transcribe"]): return "inference" return None查看另外 5 个位置
section_category = infer_section_category(section) if section_category: return section_category for pattern, category in SCRIPT_CATEGORY_HINTS: if pattern.search(lowered): return categorydef referenced_python_script(command: str, readme_dir: Path) -> Optional[Path]: matched = PYTHON_ENTRYPOINT_RE.search(command) if not matched: return None root = readme_dir.resolve() candidate = (root / matched.group("path")).resolve() try: candidate.relative_to(root) except ValueError: return None if not candidate.is_file() or candidate.stat().st_size > 524_288: return None return candidate return [] evidence: List[str] = [] score = 0 for label, pattern, weight in TRAINING_STRUCTURE_SIGNALS: if pattern.search(content): evidence.append(label) score += weight return evidence if score >= 4 else []def infer_section_category(section: Optional[str]) -> Optional[str]: if not section: return None lowered = section.lower() # Training is the highest-risk interpretation. Check it before generic # headings such as "example" or "usage" so they cannot bypass training # authorization when both appear in the same title. if any(word in lowered for word in ["training", "train", "finetune", "fine-tune", "pretrain"]): return "training" if any(word in lowered for word in ["evaluation", "evaluate", "benchmark", "metrics", "validation"]) or re.search( r"\b(?:test|tests|testing)\b", lowered ): return "evaluation" if any(word in lowered for word in ["inference", "usage", "demo", "example", "text-to-image", "image-to-image", "transcribe"]): return "inference" return Nonedef training_structure_evidence(script: Path) -> List[str]: try: content = script.read_text(encoding="utf-8", errors="replace") except OSError: return [] evidence: List[str] = [] score = 0 for label, pattern, weight in TRAINING_STRUCTURE_SIGNALS: if pattern.search(content): evidence.append(label) score += weight return evidence if score >= 4 else []