l3cube-pune's picture
Upload 4 files
e222dea verified
|
Raw
History Blame Contribute Delete
7.73 kB

Evaluation scripts

Three scripts for scoring model responses against the golden answers. Two are deterministic and need no model, no API key and no network; the third uses an LLM judge.

Script Protocol Needs a model?
exact_substring.py Golden answer must appear as one contiguous substring No
word_overlap.py Every golden word must appear, in any order No
llm_judge.py A judge model decides semantic equivalence Yes

Only pandas is required for the deterministic scripts.

Input format

Each script takes one CSV: a language file from this dataset with a response column added.

column source
question dataset
answer dataset (golden answer)
Domain dataset
response your model's raw output
python exact_substring.py --responses my_model_english.csv
python word_overlap.py    --responses my_model_english.csv --out scored.csv
python llm_judge.py       --responses my_model_english.csv --limit 50

Each prints per-domain and combined accuracy. Combined is the micro-average over all pooled questions, which is identical to weighting each domain by its size. --out writes per-question verdicts.

llm_judge.py ships with call_model() as a stub — implement it for your backend (the docstring sketches a local transformers pipeline and an OpenAI-compatible endpoint) and use temperature 0, or scores will not reproduce.


1. Exact substring

The entire logic:

is_correct = answer.lower() in response.lower()

The golden answer must appear as one contiguous run of characters. Lowercasing is the only normalisation — no trimming, no punctuation handling, no tokenisation, no word boundaries.

Golden Response Verdict Why
Ruru Jataka The answer is the Ruru Jataka, depicted at Bharhut. correct surrounding prose is irrelevant
ruru jataka RURU JATAKA correct case-insensitive
गंगा गंगा नदी correct works for Devanagari
Ruru Jataka Jataka Ruru wrong order matters
Narmada valley the Narmada river valley wrong must be contiguous
Delhi (trailing space) Delhi wrong golden answer is not stripped
amalak Amalaka correct matches inside a longer word
No There is **no** such temple correct false positive: no word boundary
Delhi Delhi is not the answer; it's Mumbai correct false positive: mention is not assertion

What it measures: whether the model reproduced the golden phrase verbatim, including word order and internal spacing. A phrase-fidelity test.

Failure modes. False negatives dominate and are mostly cosmetic — reordering, an inserted qualifier, stray whitespace in the golden answer — so the score is a lower bound. False positives are rarer but more damaging: nothing anchors the match to a word boundary or to what the model actually asserted, so short golden answers can match inside unrelated words, and a response that names the golden answer only to reject it still scores correct.


2. Word overlap

Both sides are lowercased, split on whitespace, stripped of leading and trailing punctuation (delhi.delhi), and compared as sets:

is_correct = set(golden_words) <= set(response_words)

All golden words must appear, in any order, anywhere in the response. Extra words are free — a subset test, not equality. The output CSV also carries matching_words and total_golden_words, giving partial credit that the binary verdict hides.

Golden Response Verdict Count Why
Narmada valley valley Narmada correct 2/2 order is irrelevant
Narmada valley the Narmada river valley in India correct 2/2 insertions are free
Narmada valley Narmada wrong 1/2 every golden word required
1947 to 1947 it was 1947 wrong 1/2 duplicates collapse to a set
Amalaka amalak wrong 0/1 whole-token match, no stemming
Chola ideals Chola and Hoysala ideals correct 2/2 false positive: different claim

What it measures: whether the response contains the golden vocabulary, disregarding order, position, and anything said between the words. A content-word recall test.

Failure modes. Extra words are never penalised, so a verbose answer that happens to include every golden word passes — this is the main false-positive channel and it grows with response length. The comparison is a set rather than a multiset, so repetition is never checked. There is no stemming, which matters a great deal for Indic morphology.


How the two differ

Neither is a looser version of the other. They disagree in both directions, because they relax and tighten different axes.

Axis Exact substring Word overlap
Word order must match irrelevant
Inserted words inside the phrase fails passes
Extra words elsewhere passes passes
Sub-word match (amalak / Amalaka) passes fails
Whitespace noise in golden answer fails tolerated
Unit of comparison character run whole token
Partial credit reported no yes

Real disagreements

From an actual run (Sarvam 30B on the Art domain, 233 rows — exact 59/233, word overlap 56/233). The near-identical totals hide rows that flip in opposite directions.

Exact passes, overlap fails — morphological variants where the golden string sits inside a longer word:

Golden Response
amalak Amalaka
deul Deula
mithun Mithuna
Dipankar Dipankara Buddha
scroll painting Scroll paintings

Overlap passes, exact fails — all golden words present, but not contiguous:

Golden Response
Narmada valley Narmada River valley
Chola ideals Chola and Hoysala ideals

Every one of the first group is arguably a correct answer that exact substring catches and word overlap misses on a technicality. In the second group, Narmada River valley is correct and Chola and Hoysala ideals is not — word overlap gets one right and one wrong for the same reason.

Reading the two scores together

Because the metrics are near-orthogonal, the pair is more informative than either alone:

  • Both pass → high confidence the answer is right.
  • Both fail → high confidence it is wrong, or phrased very differently.
  • Exact only → almost always an inflection difference; usually a correct answer under-counted by word overlap.
  • Overlap only → the golden words are all there but rearranged. Could be a correct paraphrase or a genuinely different claim. This bucket needs human or judge review.

Treat both numbers as lower bounds. Neither understands paraphrase, synonymy, negation, or numeric equivalence. For that, use llm_judge.py.


Caveats for both deterministic scripts

  1. An empty golden answer scores correct in both ("" in x is True, and an empty set is a subset of anything). Both scripts warn on stderr if the input contains one.
  2. Golden answers are not stripped, so trailing whitespace breaks exact substring outright.
  3. No Unicode normalisation. .lower() is a no-op for Indic scripts, and NFC versus NFD forms of the same word compare unequal. Tokenising is fine, but equality is fragile for Indic text — consider normalising to NFC before scoring if your responses come from mixed sources.
  4. Blank responses score incorrect, and are counted separately in the output so that missing data is distinguishable from wrong answers.