rhscope.model_card

Hugging Face model-card rendering for probe artifacts.

A model card is a Markdown file with a YAML front-matter header. The Hub renders it on the repo landing page and uses the structured fields (tags, base_model, license) for search and filtering.

The card produced here is intentionally deterministic and template-free - no Jinja dependency, no optional sections that silently drift between runs. Every probe uploaded through push_probe_to_hub should be accompanied by a card produced by render_model_card().

class rhscope.model_card.ModelCardExtras(bench_result=None, per_category_benchmarks=<factory>, trials=<factory>, datasets=<factory>, license='apache-2.0', language='en', tags=<factory>, notes='')[source]

Bases: object

Optional extra sections surfaced in a model card.

Variables:
  • bench_result (rhscope.bench.result.BenchResult | None) – Benchmark result to render as a metrics table.

  • per_category_benchmarks (dict[str, rhscope.bench.result.BenchResult]) – Mapping category -> BenchResult for the auxiliary leaderboard table.

  • trials (list[dict[str, Any]]) – Per-layer AUROCs from the probe-training sweep.

  • datasets (list[str]) – Hugging Face dataset IDs the probe was trained on; forwarded to the YAML datasets field.

  • license (str) – SPDX identifier for the model card. Defaults to apache-2.0.

  • language (str) – language field in the front matter.

  • tags (list[str]) – Extra tags to append to the default rhscope / reward-hacking-detection / category tags.

  • notes (str) – Free-form markdown appended after the standard sections.

Parameters:
bench_result: BenchResult | None = None
per_category_benchmarks: dict[str, BenchResult]
trials: list[dict[str, Any]]
datasets: list[str]
license: str = 'apache-2.0'
language: str = 'en'
tags: list[str]
notes: str = ''
rhscope.model_card.render_model_card(metadata, *, repo_id=None, extras=None)[source]

Return the Markdown body of a Hugging Face model card.

Parameters:
  • metadata (ProbeMetadata) – The probe’s ProbeMetadata.

  • repo_id (str | None) – Target Hugging Face repo ID; rendered into the usage example. If omitted, the example uses a placeholder.

  • extras (ModelCardExtras | None) – Optional ModelCardExtras carrying evaluation results, training trials, additional tags, and free-form notes.

Returns:

The full card content as a single string, including YAML front matter.

Return type:

str

rhscope.model_card.save_model_card(metadata, path, *, repo_id=None, extras=None)[source]

Render a model card and write it to path.

Parameters:
Return type:

None

rhscope.model_card.bench_result_from_json(payload)[source]

Convenience: load a BenchResult from JSON for card rendering.

Parameters:

payload (str | dict[str, Any])

Return type:

BenchResult