meet-rag / src /rag /eval /bootstrap.py
ingyoun's picture
S38 src
e795b50 verified
Raw History Blame Contribute Delete
1.85 kB
"""ํšŒ์˜ ๋‹จ์œ„ paired bootstrap๊ณผ ํŒ์ •. ๊ทœ์น™์€ docs/SPEC.md "ํŒ์ •"."""
import numpy as np
def paired_bootstrap(diff, groups, n_resamples: int, seed: int, alpha: float):
"""์งˆ์˜๋ณ„ ์ฐจ์ด๋ฅผ ํšŒ์˜ ๋‹จ์œ„๋กœ ๋ณต์› ์ถ”์ถœํ•ด (์  ์ถ”์ •, ํ•˜ํ•œ, ์ƒํ•œ)์„ ๋‚ธ๋‹ค."""
diff = np.asarray(diff, dtype=float)
keys, idx = np.unique(np.asarray(groups), return_inverse=True) # ํšŒ์˜ ์ •๋ ฌ
sums = np.bincount(idx, weights=diff, minlength=len(keys))
counts = np.bincount(idx, minlength=len(keys))
rng = np.random.default_rng(seed)
picks = rng.integers(0, len(keys), size=(n_resamples, len(keys)))
means = sums[picks].sum(axis=1) / counts[picks].sum(axis=1)
lo, hi = np.quantile(means, [alpha / 2, 1 - alpha / 2])
return float(diff.mean()), float(lo), float(hi)
def verdict(point: float, lo: float, hi: float, min_gain: float) -> str:
if lo > 0 and point >= min_gain:
return "์ฑ„ํƒ"
if hi < 0:
return "๊ธฐ๊ฐ"
return "๋ณด๋ฅ˜"
def metadata_verdict(single: str, recall5: tuple[float, float, float], complete5_hi: float,
min_gain: float) -> dict:
"""๋ฉ”ํƒ€๋ฐ์ดํ„ฐ ๊ฐ€์„ค์˜ ํŒ์ •(docs/SPEC.md "๋ฉ”ํƒ€๋ฐ์ดํ„ฐ ๊ฐ€์„ค์˜ ํŒ์ •", D-18, S18).
single-doc ํŒ์ •์ด ์ฑ„ํƒยท๊ธฐ๊ฐ์ด๋ฉด ๊ทธ๋Œ€๋กœ ๋‘๊ณ , ๋ณด๋ฅ˜์ด๋ฉด multi-doc Recall@5 ์ฐจ์ด
(์  ์ถ”์ •, ํ•˜ํ•œ, ์ƒํ•œ)๋กœ ํŒ์ •ํ•˜๋˜ Complete@5 ์ฐจ์ด ๊ตฌ๊ฐ„ ์ƒํ•œ์ด 0๋ณด๋‹ค ์ž‘์œผ๋ฉด ์ฑ„ํƒํ•˜์ง€ ์•Š๋Š”๋‹ค.
+1.0%p ๋ฏธ๋งŒ์ด๊ณ  ํ•˜ํ•œ > 0์ธ ๋ณด๋ฅ˜๋ฅผ ์˜ˆ์™ธ๋กœ ์˜ฌ๋ฆด์ง€๋Š” ์‚ฌ์šฉ์ž๊ฐ€ ์ •ํ•œ๋‹ค(D-35). ์—ฌ๊ธฐ์„œ๋Š” ๋ณด๋ฅ˜๋งŒ ๋‚ธ๋‹ค.
"""
if single != "๋ณด๋ฅ˜":
return {"verdict": single, "stage": "single-doc"}
v = verdict(*recall5, min_gain)
if v == "์ฑ„ํƒ" and complete5_hi < 0:
v = "๋ณด๋ฅ˜"
return {"verdict": v, "stage": "multi-doc"}