Lesson 84 — Intermediate

Evaluation Methods & Paradigms

Ek baar criteria set ho gaye, toh agla sawaal hai — score karega kaun? Tumhare paas teen tareeke hain: code (programmatic), insaan (human), ya ek dusra LLM (LLM-as-a-Judge). Is lesson mein hum har method ka mechanism samjhenge, reference-based vs reference-free ka farq dekhenge, aur decision rule seekhenge ki kaunsa behaviour kis method se check hota hai.

⏱ 10 min• Intermediate• Introduction to LLM Evaluations

Teen execution mechanisms

WHAT

Evaluation execution ke teen tareeke hain — Programmatic (code se exact checks), Human (insaan se review), aur LLM-as-a-Judge (ek LLM se scoring). Har ek ka apna scope hai, koi ek sab kuch nahi kar sakta.

WHEN

Jab output ka "sahi" form machine-checkable ho toh programmatic, jab nuance ya subjectivity ho toh human, aur jab scale chahiye ho par criteria natural language mein define ho sake toh LLM-as-a-Judge.

WHERE

Programmatic checks CI/CD mein, human evals golden dataset banate waqt aur high-stakes review mein, LLM-as-a-Judge bade offline runs aur production sampling pe. Teeno ek hi suite mein saath rehte hain.

In teeno ko "teeno tareeke hain scoring ke" mat dekho — ye ek escalation ladder hain. Jo kaam code kar sakta hai wo code karo (tez, sasta, deterministic). Code nahi kar paya toh judge lagao. Judge bhi doubt mein ho toh insaan. Har level pe cost badhta hai, isliye neeche se shuru karo.

Programmatic, Human aur Judge — mechanism

# 1) PROGRAMMATIC — code exact check karta hai
def check_json_valid(output):
    try:
        data = json.loads(output)
        return 1.0 if "answer" in data else 0.0
    except json.JSONDecodeError:
        return 0.0

# 2) LLM-AS-A-JUDGE — ek LLM criteria ke against score deta hai
JUDGE_PROMPT = """Rate the assistant answer 0 or 1.
Criterion: the answer must stay strictly within the given context.
Return JSON: {\"score\": 0 or 1, \"reason\": \"...\"}
Context: {context}
Answer: {answer}
"""
def llm_judge(context, answer):
    verdict = call_llm(JUDGE_PROMPT.format(context=context, answer=answer))
    return json.loads(verdict)["score"]

# 3) HUMAN — code nahi, form bharoge
def human_review(sample):
    # crowd/internal reviewer rating form: 1-5 per criterion
    return reviewer_form(sample)   # slowest, sabse trustworthy
Rule of thumb: Jo check ho sake exact rule se — wo kabhi LLM judge se mat karwao. Judge sirf tab lagao jab criterion English/Hinglish mein describe karna easy hai, code mein likhna mushkil.

Reference-based vs reference-free

Doosri axis hai — tumhare paas ek "sahi jawab" (reference) hai ya nahi. Reference-based mein har input ke saath ek answer key hoti hai aur output usse compare hota hai. Reference-free mein koi answer key nahi — sirf criteria (faithful hai? relevant hai? safe hai?) jo context ya rubric se check hote hain.

Warning: Reference-based scoring mein ek trap — model ka answer aur answer key dono hi paraphrase ho sakte hain. Exact string match se sahi answers bhi fail honge; semantic match ya rubric-based judge lagao.

Golden Dataset kab chahiye

Golden dataset = tumhara answer-key wala curated test set — har input ke saath expected behaviour, jo release gate ke taur pe chalta hai. Iske bina tum sirf "lagta hai theek hai" pe depend rehte ho, aur reference-based metrics ka koi base hi nahi hota.

# Ek chhota golden dataset entry ka shape
case = {
    "id": "refund-policy-03",
    "input": "Does the 30-day return apply to opened electronics?",
    "reference_answer": "Opened electronics are eligible only within 7 days.",
    "required_facts": ["7 days", "opened electronics"],
    "forbidden_claims": ["30-day return for opened electronics"],
    "category": "policy",
}

# Reference-based score: required facts mile ya nahi
def score_case(case, output):
    hits = sum(1 for f in case["required_facts"] if f.lower() in output.lower())
    leak = any(bad.lower() in output.lower() for bad in case["forbidden_claims"])
    return {"recall": hits / len(case["required_facts"]), "harmful": leak}

Behaviour ke hisaab se method match karna

Behaviour type       Example                       Best method
───────────────────  ────────────────────────────  ──────────────────────────
Deterministic        JSON schema, required field   Programmatic exact check
Format-based         CSV columns, regex pattern    Programmatic (regex/parse)
Semantic (known ans) SQL query jo sahi result de   Reference-based + judge
Subjective           tone, helpfulness, style      Human rubric (judge at scale)
Operational          latency, cost, error rate     Telemetry (auto-captured)
Safety               harmful / PII / injection      Red-team set + classifier/judge

Is table ko apne har metric pe apply karo — har criterion ke saamne likho ki wo kis bucket mein hai. Aksar teams sab kuch LLM judge se karwane lagti hain kyunki "flexible hai" — par deterministic checks judge se karwana mehnga, dheema aur kabhi-kabhi non-deterministic bhi hai.

Pro Tip: Judge ke saath hamesha batao ki score kis rubric se aaya hai, aur judge ko "unsure" ka option do. Har score ke saath judge ka reason bhi store karo — analysis mein wahi reason tumhe bugs dikhayega.

Exercise

Question: JSON validity check kis method se hoga — programmatic, human, ya LLM-as-a-Judge?

Question: Ek aisa evaluation paradigm jisme har input ke saath ek answer key (expected output) hoti hai — uska naam kya hai?

Question: Tone, nuance aur "kya customer ko theek lagega" jaise judgements ke liye kaunsa mechanism sabse trustworthy hai?

Question: LLM-as-a-Judge mein judge ke scoring bias ko control karne ke liye kis cheez se compare karte hain?

Common mistakes

Desi example: Board exam vs viva vs practical

OMR sheet checking (programmatic) ekdum exact hai, viva (human) nuance dekhta hai, aur kuch cheezein practical file (judge jaisa rubric) se check hoti hain — har subject ka apna sahi checker:

python
# Desi mapping: exam checking ke 3 tareeke
def check_answer(question, answer, method):
    if method == "OMR":        # programmatic — exact option match
        return answer == question["key"]
    if method == "viva":       # human — samajh ke nuance dekhta hai
        return teacher_asks_followups(answer)
    if method == "rubric":     # LLM judge — defined rubric se score
        return call_llm(f"Score 0-5 by rubric: {question["rubric"]}\nAns: {answer}")
# Har answer ka method pehle se decide hota hai — jabardasti ek se nahi!
Interview angle — yahan se sawaal aate hain
  • Q: Programmatic eval aur LLM-as-a-Judge mein farq? Kismein kya check karna chahiye?
  • Q: LLM-as-a-Judge ke kaun-kaunse known biases hain, aur unhe kaise control karte hain?
  • Q: Reference-based aur reference-free evaluation kab use hoti hai — apne example ke saath batao.
  • Q: Golden dataset kaise banate hain, aur usse maintain kaise karte hain?
  • Q: Ek customer-support bot ke liye tum kis criterion pe kaunsa method lagoge — 3 examples do.
Lesson complete?

Methods aur paradigms clear. Agla lesson — Offline vs Online Evaluations — mein dekhenge pre-release suites aur production monitoring ka dual-layer strategy kaise banta hai.

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