# Evaluation

> Score saved predictions on CPU with EvalKit.

---

LLMS index: [llms.txt](/Sage-SciPerception/llms.txt)

---

[EvalKit](https://github.com/InternLM/Sage-SciPerception/tree/main/evalkit) maintains versioned evaluation protocols, scoring, and the prediction generation loop. Scoring runs on CPU and needs neither torch, transformers, nor network access — only Python 3.12 and [uv](https://docs.astral.sh/uv/).

EvalKit registers all nine published task protocols, with [SciTS NEU06](/docs/tasks/eeg-neu06/) as the worked end-to-end example below.

## Registered datasets {#datasets}

| Dataset ID | Task | Protocol | Optional runtime extras |
|---|---|---|---|
| `scits-neu06` | [SciTS NEU06](/docs/tasks/eeg-neu06/) | `scits-neu06-v1` | none (stdlib) |
| `scits-phu01` | [SciTS PHU01](/docs/tasks/ecg-phu01/) | `scits-classification-text-3dp-ecg100hz-v1` | none (stdlib) |
| `llm4mat-jarvis` | [JARVIS-DFT](/docs/tasks/cif-jarvis/) | `llm4mat-jarvis-formation-energy-cif-v1` | none (stdlib) |
| `qm9s-allspectra` | [QM9S](/docs/tasks/spectra-qm9s/) | `diffspectra-compute-metrics-v1` | `rdkit`, `myopic-mces`, `pulp` (for molecular scoring) |
| `atom3d-psr` | [ATOM3D PSR](/docs/tasks/protein-struct-psr/) | `atom3d-psr-year-backbone-text-gdt-ts-v2` | `scipy` (`lmdb` only for raw LMDB input extraction) |
| `gue-splice` | [GUE splice](/docs/tasks/dna-splice/) | `gue-splice-reconstructed-mcc-v1` | none (stdlib) |
| `beacon-ncrna` | [BEACON ncRNA](/docs/tasks/rna-ncrna/) | `beacon-rna-bioinstructions-v1` | none (stdlib) |
| `mpbind-ba1` | [MPBind](/docs/tasks/protein-seq-mpbind/) | `mpbind-ppi-reconstructed-ba1-sequence-sites-v1` | none (stdlib) |
| `simxrd-ol` | [SimXRD OL](/docs/tasks/xrd-simxrd/) | `simxrd-ol-crystal7-text-maxbin0.1deg-v1` | none (stdlib) |

## Score saved predictions {#score}

Run from the repository root:

```bash
SCITS=/path/to/SciTS      # OpenTSLab/SciTS at revision 6ce690e904898cc8fd9014ea2e5bebdfa749c1d2
RUN=/path/to/neu06-run    # holds responses.jsonl

uvx --from huggingface-hub hf download OpenTSLab/SciTS meta_data.jsonl --repo-type dataset \
  --revision 6ce690e904898cc8fd9014ea2e5bebdfa749c1d2 --local-dir "$SCITS"
uv run --project evalkit scip-eval score --task scits-neu06 \
  --references "$SCITS/meta_data.jsonl" --responses "$RUN/responses.jsonl" --out-dir "$RUN/score"
```

`--dataset` is accepted as an alias for `--task`, and `--workers` sets worker processes for datasets with parallel metrics such as `qm9s-allspectra`. The command prints a summary and writes `summary.json` and per-item `scores.jsonl` to `--out-dir`. The library entry point is `evalkit.score.score_files(task, references, responses, *, only_responded=False, workers=1)`.

By default every frozen ID is scored, and an ID with no prediction counts as an empty answer. `--only-responded` scores only the IDs that have a prediction record, and marks the result as a subset.

## Prediction file format {#format}

- Each JSONL line is one attempt, with `eval_id`, `content`, and optionally `status` (`ok`, `truncated`, `api_error`). Other fields are ignored. For a repeated `eval_id`, the last line wins.
- `generation.run` writes a `run_id` into every line and a `<filename>.run.json` next to it, recording the run identity: task, ordered inputs, model, service address and model name, decoding parameters. A run with the same identity can resume and skip the IDs already written; a different identity writing to the same file is refused.
- Only one generation process may use a path at a time, enforced by `<filename>.lock`. A stale lock left by an abnormal exit must be removed by hand.
- Older files without a `run_id` still score normally, but cannot be appended to; write the remaining items to a new file.

## The `scits-neu06-v1` protocol {#protocol}

| Item | Definition |
|---|---|
| Test set | The 1,024 rows of SciTS `meta_data.jsonl` whose `task_id` contains `NEU06`, with `eval_id = "NEU06:" + id`. Row count and the SHA-256 of `[eval_id, label]` are checked on load |
| Classes | Wake, N1, N2, N3, REM, with support 324, 101, 365, 94, 140 |
| Answer parsing | Take the body after the last `</think>`; if `<answer>…</answer>` is present, take the last one; strip the outer code fence. A line equal to a class name predicts that class |
| Validity | Valid when there is at least one line and every line is a class name. Validity is reported separately and does not clear the prediction: `N2` plus a line `unsure` is invalid but still predicts N2 |
| Missing and status | A missing ID scores as an empty answer; `status` is reported only and does not affect parsing |
| Macro-F1 | The mean F1 over the reference classes present in the scored rows; TP/FP/FN count label-set membership |
| Accuracy | The predicted label set equals the reference set |

Parsing and scoring follow the rules used for the Sage-SciPerception v0.1.0 published scores.

## Reproduce from raw EEG {#reproduce}

The [NEU06 example](https://github.com/InternLM/Sage-SciPerception/blob/main/examples/neu06/README.md) covers the full path: REVE-base feature extraction, generation against a vLLM server, and scoring. It lists every input with its source, revision, and license, and reports both the released run and a rerun:

| Run | Macro-F1 (%) | Accuracy (%) |
|---|---:|---:|
| Released (v0.1.0) | 72.01 | 76.46 |
| Rerun | 71.82 | 76.46 |

Both runs cover all 1,024 items. They are separate runs, and per-item predictions of the released run are not available.

## Add a dataset or a model {#extend}

| Module | Responsibility |
|---|---|
| `datasets/base.py` | The small base class `EvalDataset`: `name`, `protocol`, `load`, `metadata`, `score_items`, `score` aligned by `eval_id`, and shared `answer_span` |
| `datasets/<suite>.py` | One module (or package such as `datasets/qm9s/`) per upstream dataset or benchmark suite, holding references, questions, parsing and metrics; tasks within a suite register by task ID |
| `datasets/__init__.py` | The `DATASETS` registry |
| `contract.py`, `score.py`, `cli.py` | Prediction file reading, score dispatch, result writing, and `scip-eval score` |
| `generation.py` | The generation loop: concurrency, OpenAI-compatible `/completions` requests recording `http_status`, run-bound appends and resume |
| `glm_prompt_embeds.py` | The vLLM `prompt_embeds` adapters (`GlmProjectorPrompt` and reusable variable-length `GlmProjectorSession`) for GLM plus a projector payload across the nine `atom` projector modalities, with multi-object support, `atom_numbering`/`payload_labels` and optional `discrete`/`side`/`counts` passthrough; needs torch, transformers and safetensors at run time |

**A new dataset or task**: implement an `EvalDataset` subclass in a suite module, register it in `datasets/__init__.py`, and add fixtures under `tests/`. Dispatch and the CLI need no change.

**A new model**: a model called the same way needs only different weights, configuration and service name in the calling script. A different calling convention adds an adapter module that assembles the request and states the model identity, combined with `generation.completion` or your own transport into a `generate(eval_id)` passed to `generation.run`.
