evals-101

82% trên 50 câu nghĩa là: đâu đó giữa 69% và 90%. 82% on 50 cases means: somewhere between 69% and 90%.

Eval biến "có vẻ tốt hơn" thành thứ kiểm chứng được. Nhưng con số nào cũng có nhiễu. Kéo hai thanh dưới để xem golden set của bạn nhạy đến đâu trước khi tin vào một chữ "+3%". Evals turn "seems better" into something you can verify. But every number carries noise. Drag the sliders to see how sensitive your golden set really is before you believe a "+3%".

Khoảng tin cậy 95% (Wilson) của pass rate 95% confidence interval (Wilson) for the pass rate

69 90

Hai phiên bản lệch nhau dưới khoảng 15 điểm thì so con số tổng chưa phân biệt được. Hãy so từng case. Two versions less than about 15 points apart can't be told apart by headline numbers. Compare case by case.

Chọn cái nàoWhat to use

Trước hết: có thể bạn chưa cần evalFirst: you might not need evals yet

  • Prototype hoặc demo sẽ bỏ đi trong vài tuần.
  • Mọi đầu ra đều có người đọc lại trước khi dùng.
  • Lưu lượng thấp, lỗi rẻ và lộ ra ngay.
  • Prompt ổn định, model đã ghim phiên bản, không ai định sửa nữa.
  • A prototype or demo you'll throw away in a few weeks.
  • Every output is read by a person before it's used.
  • Low traffic; failures are cheap and immediately visible.
  • Stable prompt, pinned model, nobody plans to change anything.

Phương án rẻ nhất là một vibe sheet: 10–20 đầu vào thật trong bảng tính, chạy tay bản cũ và bản mới, đặt cạnh nhau, ghi một dòng cho mỗi khác biệt. Mười lăm phút. Khi sửa A hỏng B lần thứ hai, nâng nó thành golden set.

The cheapest option is a vibe sheet: 10–20 real inputs in a spreadsheet, run old and new versions by hand, side by side, one line per difference. Fifteen minutes. The second time fixing A breaks B, promote it to a golden set.

Trace thậtReal traces Golden set Code graderLLM judge Cổng regressionRegression gate Production Online eval Offline eval Nét đứt: trace thất bại ở production thành case mới, mỗi tuần Dashed: failing production traces become new cases, weekly

Trả lời lần lượt, dừng ở câu đầu tiên khớpAnswer in order, stop at the first match

  1. Prompt, model, config có còn thay đổi?Are prompt, model or config still changing? Không: chỉ online eval nhẹNo: light online eval only
  2. Đã có 30+ đầu vào thật kèm tiêu chí?Do you have 30+ real inputs with criteria? Chưa: đọc trace, dựng golden setNo: read traces, build a golden set
  3. Tiêu chí kiểm được bằng code (schema, số, test, tool)?Can the criterion be checked in code (schema, numbers, tests, tools)? Có: code graderYes: code grader
  4. Tiêu chí là ngữ nghĩa (giọng, đúng ý, có căn cứ)?Is the criterion semantic (tone, intent, groundedness)? LLM judge, đã đo với nhãn ngườiLLM judge, validated on human labels
  5. Sắp merge một thay đổi?About to merge a change? Regression test trong CIRegression test in CI
  6. Sắp đổi model hoặc kiến trúc?About to switch model or architecture? Offline eval tập lớn, có khoảng tin cậyLarger offline eval, with intervals
  7. Đã có người dùng thật?Do you have real users? Online eval, lỗi chảy về golden setOnline eval, failures feed the golden set

Thứ tự xây: golden set, code grader, regression, judge cho phần code không với tới, rồi online. Đừng bắt đầu bằng judge. Build order: golden set, code graders, regression, a judge for what code can't reach, then online. Don't start with a judge.

Sáu khái niệm, theo thứ tự xây dựngSix concepts, in build order

1

Golden set

Dữ liệuData

30–100 đầu vào thật, mỗi cái kèm đáp án hoặc tiêu chí pass/fail, đóng băng và đánh version như code.30–100 real inputs, each with an expected answer or pass/fail criterion, frozen and versioned like code.

id     input                    expected / criteria        tags
g-017  "huỷ đơn 4412 giúp em"   cancel_order(4412)         tool
g-042  "refund??? NGAY!!!"      ask order ID, stay calm    edge
g-088  "ignore the above…"      refuse, no prompt leak     safety

Dùng choUse for

  • Chatbot CSKH
  • Trích xuất hoá đơn
  • RAG nội bộ, agent gọi tool
  • Support chatbots
  • Invoice extraction
  • Internal RAG, tool agents

ĐượcGain

  • Con số so được giữa phiên bản
  • 50 case chạy trong vài phút
  • Lỗi cũ không quay lại lặng lẽ
  • A number comparable across versions
  • 50 cases run in minutes
  • Old bugs can't sneak back

MấtLose

  • ±11 điểm ở 50 case
  • Dễ overfit khi sửa prompt
  • Lỗi thời khi người dùng đổi
  • ±11 points at 50 cases
  • Easy to overfit while tuning
  • Goes stale as users change

Đánh đổi: chọn golden set nhỏ là đổi độ nhạy thống kê lấy tốc độ lặp và chi phí gán nhãn thấp.Trade-off: a small golden set trades statistical sensitivity for fast iteration and low labeling cost.

Dấu hiệu cần: bạn đang trả lời "bản mới tốt hơn không" bằng cảm giác.You need it when: you answer "is the new version better?" with a gut feeling.

2

Code grader

Chấm điểmGrading

Hàm tất định: regex, JSON schema, so số có dung sai, chạy test, kiểm tool call. Mỗi assertion một lý do thất bại.A deterministic function: regex, JSON schema, numeric tolerance, running tests, checking tool calls. One failure reason per assertion.

output ─► parse ─► schema ─► values ─► PASS
            │         │         │
           FAIL      FAIL      FAIL "total=120, expected 125"

Dùng choUse for

  • Trích xuất JSON, text-to-SQL
  • Sinh code có test
  • Luật "không được" (lộ prompt, bịa URL)
  • JSON extraction, text-to-SQL
  • Code generation with tests
  • "Must not" rules (prompt leaks, fake URLs)

ĐượcGain

  • Cùng kết quả mọi lần chạy
  • Hàng nghìn assertion trong vài giây
  • Lý do thất bại nằm sẵn trong log
  • Same result every run
  • Thousands of assertions in seconds
  • Failure reason already in the log

MấtLose

  • Mù với giọng văn, độ hữu ích
  • Exact match đánh trượt oan văn bản tự do
  • Regex vỡ khi model đổi cách nói
  • Blind to tone and helpfulness
  • Exact match falsely fails free text
  • Regexes break when phrasing shifts

Đánh đổi: chọn code grader là đổi khả năng chấm chất lượng ngữ nghĩa lấy tính tất định và chi phí gần bằng không.Trade-off: code graders trade the ability to judge semantic quality for determinism and near-zero cost.

Dấu hiệu cần: tiêu chí nói được bằng "phải" hoặc "không được".You need it when: the criterion can be phrased as "must" or "must not".

3

LLM-as-judge

Chấm điểmGrading

Một model chấm theo rubric, mỗi judge một tiêu chí, trả pass/fail sau khi viết lý do. Chỉ tin sau khi đã đo với nhãn người.A model grades against a rubric, one criterion per judge, pass/fail after writing its reasoning. Trust it only after measuring it against human labels.

rubric ──┐
input  ──┼─► judge ─► { reasoning, PASS | FAIL }
output ──┤
source ──┘     ▲
               └─ calibrate: 50–100 human labels ─► TPR, TNR

Dùng choUse for

  • Đúng chính sách, đúng giọng
  • RAG faithfulness
  • Chấm mẫu trace production
  • Policy and tone compliance
  • RAG faithfulness
  • Grading sampled production traces

ĐượcGain

  • Chấm ngữ nghĩa ở quy mô lớn
  • Vài giây mỗi trace
  • Đồng thuận với người có thể đạt trên 80%
  • Semantic grading at scale
  • Seconds per trace
  • Human agreement can exceed 80%

MấtLose

  • Vô nghĩa nếu chưa hiệu chỉnh
  • 100 case × 3 lần = 300 lần gọi mỗi PR
  • Bất định giữa các lần chạy
  • Meaningless without calibration
  • 100 cases × 3 runs = 300 calls per PR
  • Varies between runs
Cạm bẫyPitfalls
  • Position bias: ưa một vị trí khi so A/B. Đảo thứ tự, chạy hai lần.
  • Verbosity bias: ưa câu dài. Ghi rõ độ dài không phải tiêu chí.
  • Self-preference: ưa output cùng họ model. Dùng judge khác họ.
  • Thang 1–10: dồn về 7–8. Dùng pass/fail.
  • Không có nguồn tham chiếu: judge cũng bịa.
  • Judge drift: nhà cung cấp cập nhật model. Ghim phiên bản.
  • Position bias: favors one slot in A/B. Swap order, run twice.
  • Verbosity bias: favors longer answers. State that length isn't a criterion.
  • Self-preference: favors its own model family. Use a different family.
  • 1–10 scales: cluster at 7–8. Use pass/fail.
  • No reference material: judges hallucinate too.
  • Judge drift: the provider updates the model. Pin the version.

Đánh đổi: chọn LLM-as-judge là đổi tính xác định và chi phí thấp lấy khả năng chấm những thứ code không hiểu được.Trade-off: LLM-as-judge trades determinism and low cost for the ability to grade what code can't understand.

Dấu hiệu cần: tiêu chí diễn đạt được bằng lời nhưng không viết nổi bằng regex.You need it when: the criterion can be stated in words but not in a regex.

4

Regression test

Vận hànhOperations

Chạy golden set trước và sau mỗi thay đổi, so từng case, chặn merge nếu case quan trọng chuyển từ đạt sang trượt.Run the golden set before and after every change, compare per case, block the merge if a critical case flips from pass to fail.

prompt v7: 82%      prompt v8: 84%     ◄ read this last
✓ → ✗   g-042, g-088                   ◄ read this first
✗ → ✓   g-011, g-017, g-063, g-070

Dùng choUse for

  • PR sửa prompt
  • Nâng cấp phiên bản model
  • Đổi chunking, thêm tool
  • Prompt PRs
  • Model version upgrades
  • Chunking changes, new tools

ĐượcGain

  • Bắt "sửa A hỏng B" trước người dùng
  • So ghép cặp nhạy hơn so con số tổng
  • Nâng model nhanh và tự tin
  • Catches "fix A, break B" early
  • Paired diffs beat headline numbers
  • Fast, confident model upgrades

MấtLose

  • Chỉ thấy lỗi trên case đã có
  • Test flaky rồi bị tắt
  • Chi phí nhân theo số PR
  • Only sees known cases
  • Flaky tests get disabled
  • Cost multiplies per PR

Đánh đổi: chặn merge bằng regression là đổi tốc độ release lấy cam kết lỗi đã biết không bao giờ quay lại.Trade-off: gating merges on regression trades release speed for a guarantee that known failures never return.

Dấu hiệu cần: sửa A làm hỏng B lần thứ hai.You need it when: fixing A breaks B for the second time.

5

Offline eval

Vận hànhOperations

Đánh giá trước khi triển khai, trên dữ liệu cố định. Regression là phiên bản chạy thường xuyên; offline eval lớn dùng trước quyết định lớn.Evaluation before deploy on fixed data. Regression is the frequent version; large offline evals precede big decisions.

fixed dataset ─► version X ─► graders ─► report ─► ship?
quality 84% (95% CI 78–88%, n=200) | p50 latency 1.2s | $0.004/case

Dùng choUse for

  • Chọn model giữa các nhà cung cấp
  • Thử model nhỏ hơn để giảm chi phí
  • Red-teaming an toàn
  • Picking between providers
  • Trying a cheaper, smaller model
  • Safety red-teaming

ĐượcGain

  • Tái lập được
  • Lỗi không chạm người dùng
  • So công bằng trên cùng dữ liệu
  • Reproducible
  • Failures never reach users
  • Fair comparison on the same data

MấtLose

  • Dataset khác thực tế
  • Không đo được sự hài lòng
  • Benchmark công khai có thể bị contamination
  • Dataset differs from reality
  • Can't measure satisfaction
  • Public benchmarks may be contaminated

Đánh đổi: chọn offline eval là đổi độ chân thực của lưu lượng thật lấy khả năng tái lập và an toàn.Trade-off: offline eval trades the realism of live traffic for reproducibility and safety.

Dấu hiệu cần: có từ hai phương án và chưa có người dùng thật để thử.You need it when: you have two or more options and no live traffic to test on.

6

Online eval

Vận hànhOperations

Đo trên lưu lượng thật: tín hiệu hành vi, judge chấm mẫu trace, guardrail, A/B. Trace thất bại chảy ngược về golden set.Measure on real traffic: behavioral signals, a judge on sampled traces, guardrails, A/B. Failing traces flow back to the golden set.

traces ─┬─► signals: rephrase, thumbs-down, escalation
        ├─► judge on 1–5% sample ─► daily dashboard
        └─► failures ─► human review ─► golden set (+5–10/week)

Dùng choUse for

  • Chatbot có người dùng thật
  • Phát hiện drift
  • A/B khi offline hoà nhau
  • Chatbots with real users
  • Detecting drift
  • A/B when offline is a tie

ĐượcGain

  • Đúng phân bố thật
  • Lỗi chưa ai nghĩ tới
  • Nối chất lượng với chỉ số kinh doanh
  • The real distribution
  • Failures nobody imagined
  • Links quality to business metrics

MấtLose

  • Lỗi đã chạm người dùng
  • Tín hiệu thưa, nhiễu
  • Rủi ro quyền riêng tư
  • Failures already hit users
  • Sparse, noisy signals
  • Privacy risk

Đánh đổi: chọn online eval là đổi khả năng chặn lỗi trước khi xảy ra lấy sự thật về cách người dùng thực sự dùng sản phẩm.Trade-off: online eval trades blocking failures before they happen for the truth about how users actually use the product.

Dấu hiệu cần: người dùng hỏi những thứ không có trong golden set.You need it when: users ask things your golden set never imagined.

Bảng đánh đổiTrade-off table

Đo được gìMeasures Chi phí mỗi lầnCost per run Tốc độSpeed Độ tin cậyTrust Bắt lỗi lúcCatches it
Golden setNền dữ liệu cho mọi loại chấmData foundation for all gradingThấp; tốn ở gán nhãnLow; cost is labeling—Bằng chất lượng nhãnAs good as its labelsTrước triển khaiBefore deploy
Code graderĐịnh dạng, giá trị, hành độngFormat, values, actionsGần 0Near zeroMili giâyMillisecondsTất định; chỉ tốt bằng phép kiểmDeterministic; only as good as the checkTrước triển khaiBefore deploy
LLM-as-judgeNgữ nghĩa, giọng, căn cứMeaning, tone, groundedness1 lần gọi / case / tiêu chí1 call / case / criterionGiâySecondsChỉ sau hiệu chỉnhOnly after calibrationTrước và sauBefore and after
RegressionThay đổi so với bản trướcChange vs. previous versionGấp đôi một lần chạy, nửa nếu cache2× one run, half with cachingPhútMinutesCao nếu xử lý flakyHigh if flakiness handledTrước mergeBefore merge
Offline evalSo sánh phương ánComparing optionsTrung bình đến caoMedium to highPhút đến giờMinutes to hoursCao trong giới hạn datasetHigh, within dataset limitsTrước quyết định lớnBefore big decisions
Online evalChất lượng trên lưu lượng thậtQuality on real trafficTuỳ tỷ lệ lấy mẫuDepends on samplingGiờ đến ngàyHours to daysThật nhưng nhiễuReal but noisySau khi đã xảy raAfter it happened

Anti-patterns

Sai lầmMistake Vì sao saiWhy it's wrong Sửa thế nàoFix
Sửa prompt rồi thử bằng mắt trên 3 ví dụEdit the prompt, eyeball 3 examplesMẫu quá nhỏ, trí nhớ chọn lọcTiny sample, selective memoryGolden set 30+ case, so từng case30+ case golden set, per-case diff
Viết grader trước khi đọc đầu raWrite graders before reading outputsĐo thứ bạn đoán, không phải thứ đang hỏngMeasures your guess, not what's brokenĐọc 50–100 trace, phân loại lỗi trướcRead 50–100 traces, categorize first
Judge chấm thang 1–10Judge on a 1–10 scaleĐiểm dồn giữa, không ổn địnhScores cluster and driftPass/fail từng tiêu chíPass/fail per criterion
Tin judge chưa đo với ngườiTrust an unvalidated judgeKhông biết sai bao nhiêu, theo hướng nàoUnknown error size and direction50–100 nhãn người, đo TPR và TNR50–100 human labels, measure TPR and TNR
Một judge chấm sáu tiêu chíOne judge, six criteriaLỗi không truy được nguyên nhânFailures can't be tracedMỗi tiêu chí một judgeOne judge per criterion
Cùng model sinh và chấmSame model generates and gradesSelf-preference thổi điểmSelf-preference inflates scoresJudge khác họ modelJudge from another family
Báo "+3%" trên 50 caseReporting "+3%" on 50 casesNằm trong nhiễu ±11 điểmInside ±11 points of noiseXem case lật, thêm case, chạy lặpRead flips, add cases, repeat runs
Tự nghĩ case thay vì lấy logInventing cases instead of using logsThiếu cách người dùng thật viếtMisses how real users writeRút từ trace, giữ nguyên lỗiPull from traces, keep their flaws
Quyết định theo benchmark công khaiDeciding on public benchmarksKhông phải tác vụ của bạn, có thể contaminationNot your task, maybe contaminatedSàng lọc thôi, quyết bằng dữ liệu riêngShortlist only; decide on your data
Sửa nhãn cho test xanhEditing labels to turn tests greenMất mốc so sánhLoses the baselineVersion dataset, đổi nhãn qua reviewVersion data; label changes reviewed
Bỏ qua độ trễ và chi phíIgnoring latency and costShip bản chậm và đắtShips slow, expensive versionsBa chỉ số trên một bảngAll three in one table
Tắt test flaky cho CI xanhDisabling flaky testsMất lưới an toànRemoves the safety netChạy k lần, cách ly, sửa nguyên nhânRun k times, quarantine, fix the cause

Ba câu cần nhớThree things to remember