| #!/bin/sh |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| set -u |
| DEVICE="$1"; LOG="$2" |
| cd "$(dirname "$0")/../../.." || exit 1 |
| N=claude_run/NEW; n=60; W=$N/ws_train_n${n}_annot; T=$N/train_annot/n$n; EPOCHS=3 |
| WHO="source of truth segments_with_original_text_2026-09-22.jsonl (LLM segmentation + judge) with Arthur's viewer annotations (sot_annotated.jsonl); imported by Claude" |
| FAILED=0 |
| run() { echo "\$ $*"; START=$(date +%s); if "$@"; then echo "took $(( $(date +%s) - START ))s"; return 0; else RC=$?; echo "FAILED (exit $RC) after $(( $(date +%s) - START ))s"; return "$RC"; fi; } |
| case_run() { |
| M="$1"; TAG="$2"; shift 2; m=$(printf '%s' "$M" | tr 'A-Z' 'a-z') |
| SETS="--set gold_run=gold --set forbidden_families=$T/forbidden_families.json --set declarations=true --set device=$DEVICE --set epochs=$EPOCHS $*" |
| RID="t-$m-$TAG"; PID="m_${m}_n${n}annot_$TAG" |
| echo "######## $M $TAG ($(date))" |
| if [ ! -f "$W/runs/$RID/manifest.json" ]; then |
| rm -f "$T/receipts/$RID.json" |
| |
| run uv run route.py approve --ablation "T_$M" --workspace "$W" --from-run gold $SETS --reviewer "$WHO" --output "$T/receipts/$RID.json" --attest || { FAILED=$((FAILED + 1)); return; } |
| |
| run uv run route.py run --ablation "T_$M" --workspace "$W" --from-run gold --run-id "$RID" --non-interactive $SETS --approval "$T/receipts/$RID.json" || { FAILED=$((FAILED + 1)); return; } |
| fi |
| CK="$W/runs/$RID/artifacts/model" |
| if [ ! -f "$N/ws_sot/runs/$PID/manifest.json" ]; then |
| run uv run route.py run --ablation "M_$M" --workspace $N/ws_sot --from-run a0 --run-id "$PID" --non-interactive --set "checkpoint=$CK" --set allow_training_overlap=true --set device="$DEVICE" \ |
| && uv run python $N/scripts/02_extract.py $N/ws_sot "$PID" || { FAILED=$((FAILED + 1)); return; } |
| fi |
| case "$M" in CONTRACTSBERT) HF=models--nlpaueb--bert-base-uncased-contracts;; LEGALBERT) HF=models--nlpaueb--legal-bert-base-uncased;; *) HF=-;; esac |
| [ -f "$N/predictions/$PID.jsonl.gz" ] && { sh $N/scripts/81_after_run.sh "$PID" "$CK" "$HF" $N/logs/81_after_run.log || FAILED=$((FAILED + 1)); } |
| grep -E "^(m_|x_intersection_rules_)${m}_n${n}annot_$TAG " $N/results/n60__annot.txt | grep -F "|" |
| uv run python $N/scripts/15_keep_best.py |
| } |
| score_of() { grep -E "^(m_|x_intersection_rules_)modernbert_n${n}annot_$1 " $N/results/n60__annot.txt | grep -F "|" | awk '{print $4}' | sort -r | head -1; } |
| { |
| echo "######## waiting for 36_pf_lora.sh ($(date))" |
| while pgrep -f "[3]6_pf_lora[.]sh" >/dev/null; do sleep 60; done |
| G="$PWD/$N/sot_annotated.jsonl" |
| case_run LEGALBERT e3_nlr --set newline_marker=auto --set rule_marker=auto |
| case_run LEGALBERT e3_nlrc --set newline_marker=auto --set rule_marker=auto --set blank_chrome=true |
| case_run CONTRACTSBERT e3_nl_t "--set newline_marker=~" |
| case_run LEGALBERT e3_nl_toss --set newline_marker=auto "--set garbage_gold=$G" |
| case_run CONTRACTSBERT e3_toss "--set garbage_gold=$G" |
| case_run MODERNBERT e3_l2048 --set max_length=2048 --set stride=512 |
| case_run MODERNBERT e3_l8192 --set max_length=8192 --set stride=2048 |
| echo "######## dapt ($(date))" |
| D=$N/dapt/modernbert-ex10-2024q2 |
| [ -f "$D/dapt_manifest.json" ] || run uv run --no-project --python 3.12 --with "transformers>=4.48,<5" --with torch --with polars --with huggingface_hub \ |
| python $N/scripts/16_dapt_modernbert.py --shards 0,1 --max-minutes 150 --device "$DEVICE" --out "$D" || FAILED=$((FAILED + 1)) |
| if [ -f "$D/dapt_manifest.json" ]; then |
| S512=$(score_of e3); S2048=$(score_of e3_l2048); echo "modernbert 512: ${S512:-none}, 2048: ${S2048:-none}" |
| if [ -n "$S2048" ] && [ "$(printf '%s\n%s\n' "${S512:-0}" "$S2048" | sort -r | head -1)" = "$S2048" ]; then |
| case_run MODERNBERT e3_l2048_dapt --set max_length=2048 --set stride=512 "--set base=$PWD/$D" |
| else case_run MODERNBERT e3_dapt "--set base=$PWD/$D"; fi |
| fi |
| echo "44 done: $FAILED failed ($(date))" |
| } >> "$LOG" 2>&1 |
| [ "$FAILED" -eq 0 ] |
|
|