GeezerVison is showing github.com — refactor(benchmarks): share the last-JSON-object extractor by simin-yuan · Pull Request #2035 · modelscope/evalscope
Conversation
simin-yuan
commented
Nov 9, 2026
•
edited by Yunnglin
Loading
Uh oh!
There was an error while loading. Please reload this page.
Problem
Model replies often show an example object, or repeat a draft, before the final answer:
Example: {"score": 0}. Answer: {"score": 4}
maritime_ocr_bench took the span from the first { to the last }, so the span covered several objects and parsed as nothing (_extract_json_candidate).
Fix
- New
evalscope/utils/json_extract.py::extract_last_json_object(text) -> dict | None: decode candidate objects from the end of the text and keep the candidate whose parse ends furthest into the text. A nested object cannot shadow the outer payload that contains it (maritime v1/v2 payloads are deeply nested).
maritime_ocr_bench: _extract_json_candidate is removed; _try_parse_json_payload calls the helper and still reports no json object found when nothing parses. The spotting extraction semantics change, so the benchmark declares evaluation_version='v1.1'.
benchmarks/ocr_bench/ocr_bench_v2/TEDS_metric.py is deliberately not migrated: its rfind('}') truncation feeds ast.literal_eval, which accepts Python literals (single-quoted strings, tuples). A JSON-only helper would reject payloads that parse today.
image_edit/gedit is not migrated: both legacy parsers have no production caller, so changing them would only widen the regression surface.
Tests
tests/utils/test_json_extract.py covers plain/fenced JSON, an example object before the answer, nested objects, braces and escaped quotes inside string values, an unparseable trailer, and no parseable object (None).
tests/benchmark/test_maritime_spotting_json.py covers a nested v2 payload preceded by an example object, auto-detection, the no-payload error, and the v1.1 version declaration. It skips when the maritime_ocr_bench extra (shapely) is absent.
Verification
pytest tests/utils/test_json_extract.py tests/benchmark/test_maritime_spotting_json.py -q → 20 passed
pytest tests/cli/test_all.py::TestRun::test_ci_lite -q → 1 passed
ruff check / ruff format --check and the pre-commit hooks on the changed files → clean
Notes
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Three benchmarks each re-implemented "slice from the first `{` to the last `}` and parse the
result". That span fails as soon as the reply shows an example object, or repeats a draft,
before the answer: the slice then covers several objects and parses as nothing, so a valid
response is scored as unparseable.
Add `evalscope/utils/json_extract.py::extract_last_json_object`, which decodes candidate
objects from the end of the text and returns the last one that parses. The candidate reaching
furthest into the text wins, so a nested object cannot shadow the outer payload that contains
it.
Migrated:
- `benchmarks/image_edit/gedit/utils.py` (both parsers). The delimiter path, the
list-of-scores / bare-number / random-guess fallbacks and the `fix_json` repair are
unchanged; repair now starts from the trailing brace span instead of the greedy one.
- `benchmarks/maritime_ocr_bench/scoring/spotting_json_quantization_eval.py`.
`benchmarks/ocr_bench/ocr_bench_v2/TEDS_metric.py` keeps its `rfind('}')`: it feeds
`ast.literal_eval`, which accepts Python literals (single quotes, tuples), so a JSON-only
helper would reject payloads that parse today.
Tests: helper unit cases plus one regression case per migrated call site.
Benchmark extractors hand-roll a first-brace-to-last-brace span or a greedy regex, which breaks when the model shows an example object before its answer (modelscope#2033). Add one shared helper and its tests; call sites migrate as their own PRs land.
- select the candidate whose parse ends furthest into the text, so nested
payloads are not truncated
- cover nested, escaped-quote and unparseable-trailer cases
- declare evaluation_version v1.1 for the changed spotting extraction
- drop the gedit migration: both legacy parsers have no production caller
Uh oh!
There was an error while loading. Please reload this page.
This was referenced Nov 10, 2026
Reviewers
Yunnglin
Yunnglin approved these changes
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Milestone
No milestone
Development
Successfully merging this pull request may close these issues.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
|