split_freeze.py
attributes
| source_path | references/auto-labeling/code_templates/split_freeze.py |
|---|---|
| source_sha256 | 285c96f0982fcaf39f6987a93bd319f38d0ce5b6f8d91e54c7b03e8682139148 |
| source_url | https://github.com/aws/agent-toolkit-for-aws/blob/903433d67cc4eeab334355620373f33a0c162dd4/skills/core-skills/aws-ai-ml/references/auto-labeling/code_templates/split_freeze.py |
| supporting_skill_id | 40202 |
| upstream_revision | 903433d67cc4eeab334355620373f33a0c162dd4 |
# Cell 0 [markdown]: The frozen split
# # The frozen split
#
# `freeze` records each split's ids and file hash once; `check` verifies the files against
# it; `rehash` accepts edited dev and val files. The test split never changes.
# Cell 1: Configuration
ACTION = "[ACTION]" # freeze | check | rehash
SPLITS_DIR = "[SPLITS_DIR]" # <proj>/splits
TEXT_FIELDS = None # [TEXT_FIELDS]: freeze: comma-separated input fields (the ones the labeling runs get)
LABEL_FIELD = "gt_label" # [LABEL_FIELD]: freeze: the seed's gold field
MOVE_NEAR_DUPLICATES = False # freeze: move the val or test member of each near-duplicate pair into dev first
REASON = None # [REASON]: rehash: why dev or val changed
ALLOW_VAL_REMOVAL = False # rehash: the user removed val rows on purpose
import json
import sys
from sagemaker.core import Attribution, set_attribution
set_attribution(Attribution.SAGEMAKER_AGENT_PLUGIN)
from sagemaker.ai_registry.data_preparer.exceptions import DataPreparerOperatorError
from sagemaker.ai_registry.data_preparer.auto_labeling.operators.seed import split_state
# Cell 2: Run the action
try:
if ACTION == "freeze":
fields = [x.strip() for x in (TEXT_FIELDS or "").split(",") if x.strip()]
if not fields:
sys.exit("split_state: freeze needs TEXT_FIELDS")
res = split_state.freeze_split(SPLITS_DIR, fields, label_field=LABEL_FIELD,
move_near_duplicates=MOVE_NEAR_DUPLICATES)
out = {"rows": res["rows"], "moved_near_duplicates": len(res["moved_near_duplicates"]),
"state": res["state"]}
elif ACTION == "check":
out = split_state.verify_splits(SPLITS_DIR)
elif ACTION == "rehash":
if not REASON:
sys.exit("split_state: rehash needs REASON")
out = split_state.rehash_split(SPLITS_DIR, REASON, ALLOW_VAL_REMOVAL)
else:
sys.exit(f"ACTION must be freeze, check or rehash; got {ACTION!r}")
except (OSError, ValueError, DataPreparerOperatorError) as e:
sys.exit(f"split_state: {e}")
print(json.dumps(out, ensure_ascii=False))
Children
No children yet.
Like how this is organised?
Build your own Memory tree on knowen.md: notes, decisions and tasks in one connected markdown graph, shared with your team and your AI agents.