Files
민헌andClaude Opus 5 50016ebd06 ③⑩ 단독측정 정본 반영 + 테스트데이터 지표별 명명 + ⑩ 실행기 경로 정리
③⑩ 을 09-10 단독측정으로 교체 (지표별 독립 실행기 negotiation.py, gpt-4o 1종 300건)
  ③ 5.877 → 5.784% · ⑩ 98.23 → 98.36% (253세션 1,086매칭)
  ①의 협상 기록 재집계 방식은 aggregate.py 보조 경로로 유지

run-eval.sh ⑩ 경로를 ③ 과 같은 단독측정으로 교체 (M10_REAGG=1 이면 옛 재집계)
eval/10_persona/aggregate.py
  - --out 추가 — 시험 실행이 정본 result.json·detail.jsonl 을 덮지 않게
  - 세션 대응 키를 기록의 session_id 우선으로 (EVAL-case_id 하드코딩 시
    EVAL10-* 기록이 ①의 옛 로그와 잘못 짝지어져 오답을 냈다. ① 기록은 폴백 동작 동일)

testdata 명명 규칙 <지표번호>_data_<이름>, 둘 이상이 쓰면 00_ (공용)
  testset_300 → 00_data_testset_300 · product_names → 00_data_product_names
  2_total_data → 02_data_total · 7_testset_10272 → 07_data_testset_10272
  8_items1000_master → 08_data_items1000_master
  생성기·룰(.py)은 번호 없음. 끝난 측정의 기록에는 옛 이름이 남아 있어
  testdata/README.md 에 옛↔새 대응표를 둔다

eval/SUMMARY.md 를 정본 수치와 일치시킴
③ 100건 파일럿 실행원본은 저장소 밖 _archive_20260910_실행원본/ 으로 이동

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-11 11:12:32 +09:00

87 lines
3.6 KiB
Python

#!/usr/bin/env python3
"""⑨ 품목별 협상 시나리오 분류 — 자체 라벨링 데이터 구축.
계획서: "자체 구축한 라벨링 데이터(품목 - 협상 시나리오)에 대한 Classification 결과의 F1-score"
구축 방식 (2026-08-28 확정, B안):
- 품목명: 운용 견적명에서 분리·정제한 실상품명 목록(testdata/00_data_product_names.json) 재사용
- 라벨: 4분면 룰(testdata/scenario_rule.py — 원본 nego_quadrant_service 중립 재현)로
(협상구분, 공급유형, 공급사수, 매출)에서 산출 → Scenario_A/B/C/D
- 피처: 품목명 + 협상구분·공급유형·공급사수·매출·품목가격 (실서비스 판정 입력과 동일 계열)
- 분할: **품목명 단위 8:2 홀드아웃** (같은 품목이 train/test에 걸치지 않음 — 누수 방지)
사용: python build_dataset.py [--per-name 6] [--seed 926]
출력: data/train.csv, data/test.csv
"""
import argparse
import csv
import json
import random
import sys
from pathlib import Path
HERE = Path(__file__).parent
TESTDATA = HERE.parent.parent / "testdata"
sys.path.insert(0, str(TESTDATA))
from scenario_rule import scenario_label # noqa: E402
def log_uniform(rng, lo, hi):
import math
return math.exp(rng.uniform(math.log(lo), math.log(hi)))
def sample_features(rng: random.Random) -> dict:
rq_type = rng.choice(["재협상", "재협상", "재견적"]) # 운용 비중(재협상 2:1 근사)
dist = rng.choice(["R", "W", "M"])
partners = rng.choice([0, 1, 2, 3, 4, 5])
revenue = int(log_uniform(rng, 1_000_000, 100_000_000))
item_price = round(log_uniform(rng, 1_000, 2_000_000) / 10) * 10
return {"rq_type": rq_type, "dist": dist, "partners": partners,
"revenue": revenue, "item_price": item_price}
def main():
ap = argparse.ArgumentParser()
ap.add_argument("--per-name", type=int, default=6, help="품목명당 표본 수")
ap.add_argument("--seed", type=int, default=926)
ap.add_argument("--test-ratio", type=float, default=0.2)
args = ap.parse_args()
rng = random.Random(args.seed)
names = json.load(open(TESTDATA / "00_data_product_names.json", encoding="utf-8"))["names"]
rng.shuffle(names)
# 품목명 단위 분할 (누수 방지)
n_test = int(len(names) * args.test_ratio)
test_names = set(names[:n_test])
(HERE / "data").mkdir(exist_ok=True)
fields = ["item_name", "rq_type", "dist", "partners", "revenue", "item_price", "scenario"]
counts = {"train": 0, "test": 0}
label_dist = {}
with open(HERE / "data" / "train.csv", "w", encoding="utf-8-sig", newline="") as ftr, \
open(HERE / "data" / "test.csv", "w", encoding="utf-8-sig", newline="") as fte:
wtr, wte = csv.DictWriter(ftr, fields), csv.DictWriter(fte, fields)
wtr.writeheader(), wte.writeheader()
for name in names:
for _ in range(args.per_name):
feat = sample_features(rng)
label = scenario_label(feat["rq_type"], feat["dist"],
feat["partners"], feat["revenue"])
row = {"item_name": name, **feat, "scenario": label}
label_dist[label] = label_dist.get(label, 0) + 1
if name in test_names:
wte.writerow(row); counts["test"] += 1
else:
wtr.writerow(row); counts["train"] += 1
print(json.dumps({"품목명": len(names), "train": counts["train"], "test": counts["test"],
"라벨분포": label_dist, "seed": args.seed}, ensure_ascii=False))
if __name__ == "__main__":
main()