GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — refactor(benchmarks): share the last-JSON-object extractor by simin-yuan · Pull Request #2035 · modelscope/evalscope

Conversation

@simin-yuan

@simin-yuan simin-yuan commented Nov 9, 2026 •
edited by Yunnglin
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

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

  • Supersedes feat(utils): add extract_last_json_object #2038 (the helper-only PR, no call sites). Once fix(longpi_bench): keep the last parseable JSON object #2031 merges, its private last-object copy can call this helper and go away.
  • AI assistance: change prepared with an AI coding agent (DSH); tests and lint were run locally.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Simon and others added 2 commits November 9, 2026 22:10
Simon Simon
refactor(benchmarks): share the last-JSON-object extractor
8f9a2f2
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.
@simin-yuan
feat(utils): add extract_last_json_object
a941954
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.
@Yunnglin Yunnglin mentioned this pull request Nov 10, 2026
feat(utils): add extract_last_json_object #2038
Closed
@Yunnglin
fix(maritime): keep the outer JSON object and bump the version
6ca92b2
- 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
Yunnglin
Yunnglin approved these changes Nov 10, 2026
View reviewed changes
@Yunnglin
Yunnglin merged commit c239ffb into modelscope:main Nov 10, 2026
6 of 9 checks passed

Uh oh!

There was an error while loading. Please reload this page.

This was referenced Nov 10, 2026
fix(longpi_bench): keep the last parseable JSON object #2031
Merged
One JSON-extraction helper instead of per-benchmark first-brace/last-brace spans #2033
Closed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@Yunnglin Yunnglin Yunnglin approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

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.

2 participants

@simin-yuan @Yunnglin
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.
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.