text
stringlengths
0
1.47k
if getattr(args, "reasoning_effort", None) is None:
# This is the try-harder pass: default one notch above the selection
# stage's forced-minimal effort (still overridable via the flag).
args.reasoning_effort = "medium"
logger.info("Correction pass: defaulting --reasoning_effort to 'medium'")
client = LLMClient.from_args(args)
logger.info("{} | Correction prompt active (rule hint omitted) | "
"Writing in-place to: {}".format(client, args.face))
correct_all(
raw_path=args.raw,
clean_path=args.cleaned,
face_path=args.face,
client=client,
failed_list_path=args.failed_list,
max_tokens=args.max_tokens,
max_retries=args.max_retries,
timeout_seconds=args.rig_timeout,
still_empty_path=args.still_empty_log,
only_if_currently_empty=not args.force_reattempt,
)
if __name__ == "__main__":
main()
# ===== file: data_process/joint_annotation/face_select_llm.py =====
"""Pick the facing-direction joint pair for each rig with a Language Model.
Complement to the rule-based :mod:`face_select_rule`: asks an LLM to choose ONE
bilaterally symmetric joint pair (hip / shoulder / wing / fin / ...) that
defines the rig's lateral axis for heading-angle computation. For serpentine
rigs with no bilateral symmetry, the LLM picks longitudinal body-axis
endpoints (head-tip / tail-tip) and sets ``body_axis: true``.
Backends (see :mod:`llm`): DeepSeek API (default: ``deepseek-v4-flash``),
OpenAI API, or a local HF causal LM.
Inputs :
``joint_names.json`` — ``{rig_id: [raw_joint_name, ...]}``
``clean_joint_names.json`` — ``{rig_id: [clean_joint_name, ...]}``
Output :
``face_joint_names.json`` — ``{rig_id: {r_hip, l_hip, source, [body_axis]}}``
Pipeline per rig:
1. Pre-filter the joint list into four small buckets (Right / Left /
Head / Tail candidates). Dozens-of-joint rigs collapse to a handful.
2. Short-circuit 'empty' if no candidates survive (no LLM call).
3. Otherwise send only the compact candidate list to the LLM, together
with the rule-based pick as a hint, and ask it to apply a three-step
decision (bilateral -> body-axis -> empty).
4. Validate the response (raw names must appear verbatim in the input);
retry with a structured correction on failure.
5. Fall back to the rule-based resolver after max retries / timeout.
Usage:
python -m data_process.joint_annotation.face_select_llm \\
--input_dir <export_dir> # DeepSeek v4-flash (default)
python -m data_process.joint_annotation.face_select_llm \\
--input_dir <export_dir> --model gpt-5-mini
python -m data_process.joint_annotation.face_select_llm \\
--input_dir <export_dir> --model Qwen/Qwen3-8B
"""
import argparse
import json
import os
import re
import sys
import time
from loguru import logger
from tqdm import tqdm
_REPO_ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", ".."))
if _REPO_ROOT not in sys.path:
sys.path.insert(0, _REPO_ROOT)
from data_process.joint_annotation.llm import ( # noqa: E402
FatalLLMError,
LLMClient,
MAX_RETRIES,
RigTimeout,
add_llm_args,
append_id_list,
install_rig_alarm,
load_json,
read_id_list,
save_json,
strip_llm_noise,
uninstall_rig_alarm,
)
from data_process.joint_annotation.face_select_rule import ( # noqa: E402
HEAD_KEYWORDS,
TAIL_KEYWORDS,
empty_entry,
resolve_face_joints,
strip_trailing_num,