File size: 3,651 Bytes
7ec89f8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# CLAUDE.md

This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.

## Project Overview

A benchmark for evaluating vision-capable LLMs on Indian competitive exam questions (JEE Main, JEE Advanced, NEET). Questions are images sent to models via the OpenRouter API; responses are parsed from `<answer>...</answer>` tags and scored using exam-specific marking schemes.

## Running the Benchmark

```bash
# Setup
uv sync
echo "OPENROUTER_API_KEY=your_key" > .env

# Must run from project root (paths are resolved relative to cwd)
uv run python src/benchmark_runner.py --model "google/gemini-2.5-pro-preview-03-25" --exam_name JEE_ADVANCED --exam_year 2025

# Filter by question IDs
uv run python src/benchmark_runner.py --model "openai/o3" --question_ids "N24T3001,N24T3002"
```

CLI args: `--model` (required), `--exam_name` (all/NEET/JEE_ADVANCED/JEE_MAIN), `--exam_year` (all/2024/2025), `--question_ids`, `--output_dir`, `--config`, `--resume`.

## Testing

```bash
# Run the full pytest suite (68 tests)
uv run pytest tests/ -v

# Run individual module self-tests
uv run python src/utils.py        # answer parsing logic
uv run python src/evaluation.py   # scoring logic
uv run python src/llm_interface.py  # API calls (requires .env and network)
```

## Architecture

```
benchmark_runner.py  ─── orchestrator / entry point
  ├── loads config from configs/benchmark_config.yaml
  ├── loads dataset directly from metadata.jsonl (JSONL → HuggingFace Dataset)
  │     ├── metadata.jsonl (question metadata, 578 questions)
  │     └── images/ (question PNGs, stored in Git LFS)
  ├── calls llm_interface.py for each question
  │     ├── prompts.py (prompt templates)
  │     └── utils.py (parse_llm_answer extracts from <answer> tags)
  ├── scores via evaluation.py (exam-specific marking schemes)
  └── writes results incrementally to results/{model}_{exam}_{year}_{timestamp}/
        ├── predictions.jsonl  (raw API responses)
        ├── summary.jsonl      (scored per-question results)
        └── summary.md         (human-readable report)
```

### Key data flow

1. Dataset loaded directly from `metadata.jsonl` into a HuggingFace `Dataset` object, filtered by exam/year
2. Each question image is base64-encoded and sent to OpenRouter with a structured prompt
3. If the response can't be parsed, a re-prompt is sent (text-only, with the bad response)
4. If the API call fails, the question is queued for retry (up to 3 attempts, exponential backoff via `tenacity`)
5. Answers are parsed from `<answer>...</answer>` tags by `utils.parse_llm_answer()`
6. `evaluation.py` scores using JEE/NEET marking schemes (partial credit for MCQ_MULTIPLE_CORRECT in JEE Advanced)

## Answer Format Conventions

- `MCQ_SINGLE_CORRECT`: `<answer>A</answer>``["A"]`
- `MCQ_MULTIPLE_CORRECT`: `<answer>A,C</answer>``["A", "C"]` (sorted, deduplicated)
- `INTEGER`: `<answer>42</answer>``["42"]`
- `SKIP`: `<answer>SKIP</answer>` → no penalty

## Important Notes

- **Git LFS**: Images and `metadata.jsonl` are in LFS. Run `git lfs pull` after cloning.
- **Working directory**: Scripts must be run from project root — config, data, and image paths are resolved relative to cwd.
- **Python 3.10+**: Uses union type syntax (`list[str] | str | None`).
- **Models**: Configured in `configs/benchmark_config.yaml` under `openrouter_models`. All must support vision input.
- **Result directory naming**: `results/{provider}_{model}_{exam}_{year}_{YYYYMMDD_HHMMSS}/` (slashes in model IDs replaced with underscores).