Lesson 85 — Intermediate

Offline vs Online Evaluations

Offline evaluation tumhe release se pehle batata hai ki "kya model/prompt toota toh nahi" — par production mein wahi cheezein hoti hain jo test set mein kabhi sochi hi nahi gayi thi. Is lesson mein hum dono layers ka design samjhenge: offline suites jo har change pe chalte hain, aur online evaluation jo deployed system ki actual quality roj measure karti hai.

⏱ 20 min• Intermediate• Evaluation Methods & Paradigms

Dual-layer strategy — offline aur online

WHAT

Offline eval = curated dataset pe, release se pehle, lab conditions mein chalne wala test suite. Online eval = production traffic ka sample le kar usi criteria se scoring, deployment ke baad. Dono mil kar ek dual-layer strategy banate hain.

WHEN

Offline — har prompt change, model switch, threshold tweak pe, CI mein. Online — continuously (ya daily batch mein), kyunki production data hafte-hafte badalta hai aur naye failure modes emerge karte hain.

WHERE

Offline tumhare eval harness mein chalta hai. Online pipeline production logging + sampling + scorer + dashboard + alerting se banta hai. Dono ka output ek hi experiment tracking system mein jaata hai.

Funda simple hai: offline rokta hai bura release, online pakadta hai chupi hui problems. Sirf offline = "test toh pass ho gaya" bol kar ship kar diya, par users ke actual inputs ne phir bhi fail kiya. Sirf online = pata tab chalta hai jab damage ho chuka ho. Dono layers zaroori hain.

Offline suites — pre-release gate

# Ek minimal offline suite — pytest style
def test_refund_answer_faithful():
    case = load_case("refund-03")
    out = app(case["input"])
    assert fact_check(out, case["required_facts"]) >= 0.8, f"missing facts: {out}"
    assert not contains_claims(out, case["forbidden_claims"]), "hallucinated claim"

def test_json_mode_schema():
    out = app_json("List 3 refund rules")
    assert json.loads(out)["rules"].__len__() == 3

# Har naye production failure ka regression case:
def test_regress_2024_user_said_X():
    out = app("tumhara sabse bura input yahan")
    assert meets_criteria(out), "wahi purana bug wapas aa gaya"

# Run: pytest evals/ --tb=short  -> CI mein gate ke roop mein
Pro Tip: Offline suite ko deterministic banao — fixed model version, fixed decoding params (ya multiple samples + seed logging), aur har run ka prompt hash record karo. Warna tum khud bhi nahi bata paoge ki score badla kyun.

Post-deployment risks — kyun online chahiye

Warning: "Hamara test set toh representative hai" — launch din pe shayad. Do mahine baad production distribution test set se alag ho chuki hoti hai. Online eval isi liye hai: reality se continuous check.

System metrics vs quality metrics

SYSTEM METRICS (auto-capture, har request pe)     QUALITY METRICS (LLM/human se score)
─────────────────────────────────────────────     ──────────────────────────────────────
latency (p50/p95), timeouts                        faithfulness / groundedness
error rate, HTTP 5xx, tool failures                answer relevance, completeness
tokens per request, cost per request               refusal correctness (refuse karna tha?)
retry count, fallback usage                        tone / format / instruction-following
cache hit rate                                     safety flags (harmful, PII, injection)

# System metrics billing & SLO ke liye, quality metrics trust ke liye.
# Dono ek dashboard pe side-by-side chahiye — ek behtar doosre ke bina adhura.

System metrics tumhe pata bhi nahi chale kab capture ho jaati hain — request ke saath latency, tokens, error code apne aap log ho jaate hain. Quality metrics ka effort zyada hai: ya toh LLM judge lagao ya human sampling. Teams aksar sirf system metrics dekhti hain — p95 latency theek hai toh sab "green" — par users ko toh galat jawab ho sakta hai latency bilkul sahi hone ke baad bhi.

Rule of thumb: Sawaal yeh nahi ki quality metric kaunsa, pehle yeh ki wo metric capture hi ho raha hai ya nahi. "Hamara app faithful hai" — abhi tak kisi ne number hi nahi nikala, toh koi guarantee nahi.

Continuous online evaluation pipeline

# Production pipeline ka sketch: log -> sample -> score -> dashboard -> alert

def log_request(req, resp, meta):
    db.insert({"ts": now(), "input": req, "output": resp.text,
               "latency_ms": meta.latency, "tokens": meta.tokens,
               "prompt_hash": meta.prompt_hash, "model": meta.model})

def sample_for_scoring(n_per_day=200):
    # uniform sample + stratified: har category/user-segment se minimum
    return db.sample_uniform(n_per_day // 2) + db.sample_per_category(n_per_day // 2)

def score_and_alert(samples):
    for s in samples:
        s["faithfulness"] = judge_faithfulness(s["context"], s["output"])
        s["toxic"] = safety_classifier(s["output"])
    daily = aggregate(samples)          # per-metric avg + failure rate
    dashboard.publish(daily)
    if daily["faithfulness"] < BASELINE["faithfulness"] - 0.05:
        alert("faithfulness regressed vs 7-day baseline")

Failures ko offline mein wapas bhejna

Online pipeline ka sabse valuable output dashboard nahi, failure queue hai — wo concrete examples jinme app galat tha. Har verified failure ko ek candidate regression case banao, human verify karo, aur offline golden dataset mein add karo. Isi se tumhara test set live rehta hai — warna wo launch wale din mar jaata hai.

# Failure -> golden dataset ka loop
def promote_failure(sample, reviewer):
    if sample["faithfulness"] < 0.5 and reviewer.confirm("wrong answer"):
        golden.add({
            "id": f"prod-{sample["id"]}",
            "input": redact_pii(sample["input"]),
            "reference_answer": reviewer.writes_correct_answer(),
            "category": sample["category"],
            "source": "production-2026-06",
        })
        offline_suite.add_regression_test(golden[f"prod-{sample["id"]}"])
# Har hafte: failure queue review meeting — yehi tumhari quality ka asli engine hai.
Yaad rakho: Ye loop isliye bhi zaroori hai kyunki production failures hamesha "interesting" hote hain — unme tumhare users ke asli inputs, asli edge cases aur asli misunderstandings hain. Hand-made test cases ye kabhi capture nahi kar paate.

Exercise

Question: Release se pehle curated dataset pe chalne wala eval suite kis layer kehlata hai — offline ya online?

Question: Latency, token usage aur error rate — system metrics hain ya quality metrics?

Question: Online eval pipeline mein har request ko judge karwane ke bajaye kya use karte hain — poori traffic ya sample?

Question: Production ka verified failure aage kahan jaata hai — sirf dashboard ya offline golden dataset mein bhi?

Common mistakes

Desi example: Kitchen ka tasting vs customer plate

Har dish banne pe chef khud chakh kar check karta hai (offline eval) — par asli feedback customer ke plate se aata hai (online eval). Chef sirf apne taste pe bharosa kare toh menu kabhi customers ke hisaab se nahi badlega:

python
# Offline: release se pehle
for case in golden_dataset:
    score = evaluate(app(case.input), case.criteria)
    if score < THRESHOLD:
        block_release(f"{case.id} failing")

# Online: release ke baad, roz ka sample
for s in db.daily_sample(200):
    q = judge(s.input, s.output, s.context)
    weekly_trend.log(q)
# Chef ka rule: customer ki plate pe 3 complaints -> menu review (failure -> dataset)
Interview angle — yahan se sawaal aate hain
  • Q: Offline aur online evaluation ek doosre ko replace kyun nahi kar sakte?
  • Q: System metrics aur quality metrics mein farq? Har ek ke 2-2 examples do.
  • Q: Production mein sampling kyun zaroori hai — har request judge karwane ke bajaye?
  • Q: Data drift ke 3 real examples batao jo LLM apps ko affect karte hain.
  • Q: Batao kaise ek production failure ko offline regression test mein convert karte hain.
Lesson complete?

Dual-layer strategy clear. Agla lesson — Model Evaluations & Benchmarking — mein dekhenge public benchmarks kaise kaam karte hain aur unke pitfalls kaise pehchante hain.

Popular courses: Data Science Course in Lucknow · AI Course in Lucknow · Python Course in Lucknow · Power BI Course · Data Analytics Course