Files
University_Labs_Nego_Agent/server/tools/build_experience.py
T
민헌andClaude Opus 5.5 13ab9dee84 chore: 2차년도 성능평가 측정 구성 초기 업로드
data(train 520·holdout 120), server(발화 생성 서버), eval(grounding_eval), run_eval.py·run_test.sh.
logs/ 는 실행 때마다 생기는 기록이라 README.md 만 올리고 나머지는 .gitignore 로 뺀다.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-21 14:05:48 +09:00

64 lines
2.7 KiB
Python

"""경험 예시 파일 만들기 — 학습 데이터(train)의 구매자 턴 정답 발화 → resources/grounding/experience_examples.jsonl
cd server && .venv/bin/python tools/build_experience.py
- 입력: ../data/train/학습검증_지시순응.jsonl 의 strategy_conditioned_response 중 split == train
- 홀드아웃(../data/holdout/대상_홀드아웃.txt)의 시나리오가 섞여 있으면 중단한다.
- 예시의 상황·전략·남은 턴은 서버와 같은 파서로 messages 에서 다시 읽는다 (추론 때와 같은 기준).
- 정답 발화의 숫자는 ○ 로 가린다.
"""
import json
import re
import sys
from collections import Counter
from pathlib import Path
SERVER_ROOT = Path(__file__).resolve().parents[1]
sys.path.insert(0, str(SERVER_ROOT))
from services.grounding.experience import EXAMPLES_PATH, situation_of # noqa: E402
from services.grounding.parser import parse_messages # noqa: E402
EVAL_ROOT = SERVER_ROOT.parent
SOURCE = EVAL_ROOT / "data" / "train" / "학습검증_지시순응.jsonl"
HOLDOUT_IDS = EVAL_ROOT / "data" / "holdout" / "대상_홀드아웃.txt"
NUMBER_RE = re.compile(r"\d[\d,]*(?:\.\d+)?")
def mask_numbers(text: str) -> str:
return NUMBER_RE.sub("○", text)
def main() -> None:
holdout = set(HOLDOUT_IDS.read_text(encoding="utf-8").split())
rows, skipped = [], Counter()
with open(SOURCE, "r", encoding="utf-8") as f:
for line in f:
r = json.loads(line)
if r["task_type"] != "strategy_conditioned_response":
continue
if r["split"] != "train":
skipped[r["split"]] += 1
continue
if r["scenario_id"] in holdout:
sys.exit(f"홀드아웃 시나리오가 학습 데이터에 있습니다: {r['scenario_id']}")
ctx = parse_messages(r["messages"])
rows.append({
"sample_id": r["sample_id"], "dialogue_id": r["dialogue_id"],
"situation": situation_of(ctx.is_first_turn, ctx.card_name), "strategy": ctx.strategy,
"act": r["reference_act"], "turn": ctx.turn or r["turn"], "remaining": ctx.remaining or 0,
"response": mask_numbers(r["reference_response"]),
})
EXAMPLES_PATH.parent.mkdir(parents=True, exist_ok=True)
with open(EXAMPLES_PATH, "w", encoding="utf-8") as f:
for row in rows:
f.write(json.dumps(row, ensure_ascii=False) + "\n")
print(f"{EXAMPLES_PATH.relative_to(SERVER_ROOT)}: {len(rows)}개 (대화 {len({r['dialogue_id'] for r in rows})}건), "
f"제외 {dict(skipped)}")
print("상황별:", Counter(r["situation"] for r in rows).most_common())
if __name__ == "__main__":
main()