Lesson 88 — Intermediate

Custom Model Evaluations

Public benchmarks ne shortlist bana di, par final decision yahan hoga — tumhare task pe. Ek model leaderboard pe top hai par tumhari JSON format chhod de, aur doosra mid-ranked hai par perfectly follow karta hai. Is lesson mein hum seekhenge apne real task ka custom eval dataset kaise banate hain, models ko like-for-like kaise compare karte hain, aur quality-latency-cost ka trade-off kaise resolve karte hain.

⏱ 10 min• Intermediate• The Evolution of Knowledge Benchmarks

Custom eval kyun — leaderboard ke baad bhi

WHAT

Custom model evaluation = apne actual task ke inputs, apne prompts aur apne scoring criteria se models ka head-to-head comparison. Leaderboard general capability dikhata hai, custom eval tumhara specific decision deta hai.

WHEN

Jab bhi tum model choose ya switch kar rahe ho — pehli baar selection ho ya upgrade — dono hi waqt apna eval chalana zaroori hai. Chhote changes pe bhi ek quick smoke-eval bana rakho.

WHERE

Apne repo mein — ek eval/ directory, ek curated dataset, ek runner script jo har candidate model ko same inputs pe chala kar scores + latency + cost report karta hai. CI mein bhi attach kar sakte ho.

Decision rule: leaderboard se shortlist karo (3-4 models), custom eval se winner chuno. Leaderboard pe top-1 model directly select karna aksar galat nikalta hai — uski strength tumhare task pe matter nahi karti, aur weakness (format-following, hallucination, cost) matter karti hai.

Candidate shortlist — 4 axes pe filter

Pro Tip: Shortlist mein kabhi ek hi provider ke models mat rakho — ek open-weight option (self-host ya sasta API) aur ek frontier option hamesha rakho. Trade-off tabhi samajh aata hai jab alternatives saamne hon.

Custom eval dataset banana — Text-to-SQL example

# Ek chhota Text-to-SQL eval dataset — apne schema se banao
cases = [
    {
        "id": "sql-01",
        "schema": "orders(id, customer_id, total, created_at, status)",
        "question": "March mein kitne cancelled orders aaye?",
        "reference_sql": "SELECT COUNT(*) FROM orders WHERE status='cancelled' AND created_at >= '2026-03-01' AND created_at < '2026-04-01';",
        "difficulty": "easy",
    },
    {
        "id": "sql-02",
        "schema": "orders(id, customer_id, total, created_at, status)\ncustomers(id, name, city, segment)",
        "question": "Har city ke top customer ka naam aur unka total spend — sirf enterprise segment.",
        "reference_sql": "...",  # hand-written, phir DB pe run karke verify kiya hua
        "difficulty": "hard",
    },
]
# Scoring: reference se exact match nahi — RUN karke result set compare karo.
# Do alag SQL queries same result de sakte hain = dono sahi.
Warning: Custom dataset apne production data se banao, toh use PII pehle redact karo. Eval files public repos mein jaati hain — usme real customer names/emails rakhna breach hai.

Like-for-like comparison runner

def compare_models(models, cases, prompt_fn):
    """Same input, same prompt, same params — sirf model badalta hai."""
    report = {}
    for name, call_fn in models:
        scores, latencies, tokens = [], [], []
        for case in cases:
            t0 = time.time()
            out = call_fn(prompt_fn(case), temperature=0.0, max_tokens=512)
            latencies.append(time.time() - t0)
            tokens.append(out.usage.total_tokens)
            scores.append(score_case(case, out.text))      # same scorer for all
        report[name] = {
            "quality": mean(scores),
            "p95_latency": percentile(latencies, 95),
            "avg_tokens": mean(tokens),
        }
    return report
# Rules: temperature 0 (ya same seed), same prompt template, same max_tokens,
# aur SAME scorer. Ek bhi variable alag hua toh comparison bekaar.

Do comparisons mein sabse common galti hai — ek model ko tuned prompt dena aur doosre ko default. Ya ek ka temperature 0 aur doosre ka 0.7. Tab score difference model ka nahi, configuration ka hota hai. Runner mein configuration ek jagah define karo, sab models wahi lein.

Rule of thumb: Comparison table hamesha teeno columns ke saath dekho — quality score, p95 latency, aur cost per 1000 requests. Sirf quality dekh kar winner chunna aadha decision hai.

Token cost estimate aur quality-latency-cost trade-off

# Cost ka formula — pricing current provider docs se lo (ye placeholder hai)
def cost_per_1k_requests(avg_input_tokens, avg_output_tokens, price_in, price_out):
    # price_* = per million tokens (USD jaisa unit — docs se verify karo)
    in_cost  = avg_input_tokens  * 1000 / 1_000_000 * price_in
    out_cost = avg_output_tokens * 1000 / 1_000_000 * price_out
    return in_cost + out_cost

# Prompt caching ka effect — system prompt 2000 tokens ka hai, roz 100k requests:
# bina cache: 2000 * 100_000 = 200M input tokens (har request pe charge)
# cache se:   cached read rate bahut kam hota hai (provider docs mein ratio dekho)
# Rule: same prefix wale bulk traffic pe caching pehla optimization hai.

# Trade-off resolution order:
# 1. Quality floor se neeche wale models OUT
# 2. Latency requirement se neeche wale OUT
# 3. Bacho mein sabse sasta chuno

Exercise

Question: Model selection ka sahi order kya hai — pehle leaderboard ya pehle custom eval?

Question: Text-to-SQL eval mein SQL query ki correctness kaise check karte hain — string match ya DB pe run karke?

Question: Like-for-like comparison mein temperature, prompt aur scorer sab models ke liye same rakhne hain ya alag-alag?

Question: Trade-off resolution mein pehla filter kya hai — sabse sasta model ya quality floor?

Common mistakes

Desi example: Darzi ka fabric test — brand nahi, tumhara kapda

Showroom ka billboard (leaderboard) dekh kar shirt mat lo — apna kapda (task data) le kar darzi ke paas jao, vo trial stitch (custom eval) banaye, fitting dekho, phir final lo:

python
# Billboard (leaderboard) -> shortlist
shortlist = ["model-A", "model-B", "model-C"]

# Trial stitch (custom eval) -> apne 50 cases pe sab chalao
for m in shortlist:
    r = compare_models([m], my_50_cases, my_prompt_template)
    print(m, r["quality"], r["p95_latency"], r["cost_per_1k"])

# Final fitting rule: quality floor -> latency budget -> sabse sasta winner
Interview angle — yahan se sawaal aate hain
  • Q: Public benchmark aur custom eval ka farq? Model selection pipeline kaise design karoge?
  • Q: Text-to-SQL ko evaluate karne ka sahi mechanism kya hai — judge ya execution-based scoring?
  • Q: Like-for-like comparison ke liye kya-kya constant rakhna padta hai?
  • Q: Model selection mein quality, latency aur cost ka trade-off kaise resolve karte ho — order batao.
  • Q: Prompt caching bulk workload pe kaise cost bachata hai — mechanism samjhao.
Lesson complete?

Custom model comparison clear. Agla lesson — Building an Eval Suite & Regression Testing — mein seekhenge versioned tests, baselines aur CI quality gates kaise banaate hain.

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