Step 1 — warm_grounding_stability targeted patch - chat/runtime.py:_maybe_pack_grounded_surface accepts allow_warm=True; warm path invokes it after articulation and overrides response_surface / articulation / grounding_source when pack-grounded or teaching-grounded. - CAUSE / VERIFICATION without a teaching chain on warm path emits the unknown-domain disclosure (matches cold-path discovery-signal doctrine — no fabricated vault content). - warmed_session_consistency public lane: warm_grounding_stability 0.0 → 1.0, grounding_match_rate 1.0, telemetry_consistency 1.0. - Cognition lane byte-identical (public 100/100/91.7/100, holdout 100/100/83.3/100). Full suite 2294 passed. Step 2 — three new red eval lanes (measurement substrate) - conversational_thread_coherence: 6 cases / 45 turns; per-turn no_placeholder / not_walk_fragment / length / is_grounded predicates + per-case topic_anchor and no_topic_drift. Baseline: grounded 0.93, topic_anchor 0.50, no_topic_drift 0.83. - multi_sentence_response: 15 cases over Explain/Tell/Describe/Walk/ Example/Essay shapes; predicates sentence_count >= 2, non-fragment, connective_present, subject_named. Baseline: multi_sentence 0.53, connective 0.10 — biggest architectural gap. - self_consistency_over_time: 7 cases; same probe at multiple turn indices with unrelated fillers interleaved. Baseline: byte_identical 0.86 (one CAUSE-no-chain disclosure drifts under accumulation). All three lanes deterministic, lexical-predicate-only — no LLM judge, no embedding similarity. Red-on-creation by design. See notes/long_span_fluency_baseline_2026-05-19.md.
150 lines
4.6 KiB
Python
150 lines
4.6 KiB
Python
"""Multi-sentence response eval lane runner.
|
|
|
|
Measures whether ``ChatRuntime`` emits more than one sentence when
|
|
the prompt structurally calls for elaboration. Strips the trailing
|
|
provenance tag (``pack-grounded (...).``) before counting sentences
|
|
so the metric reflects substantive content.
|
|
|
|
Framework contract: ``run_lane(cases, config=None) -> LaneReport``.
|
|
|
|
Case schema:
|
|
{
|
|
"id": "...",
|
|
"category": "...",
|
|
"prompt": "Tell me about truth.",
|
|
"subject_lemma": "truth",
|
|
"expects_connective": true
|
|
}
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
import re
|
|
from dataclasses import dataclass, field
|
|
from typing import Any
|
|
|
|
from chat.runtime import ChatRuntime
|
|
|
|
|
|
_PROVENANCE_TAIL_RE = re.compile(
|
|
r"\s*(pack-grounded|teaching-grounded)\s*\([^)]+\)\.?\s*$"
|
|
)
|
|
|
|
_CONNECTIVES = (
|
|
"and", "because", "therefore", "which", "since", "also",
|
|
"furthermore", "however", "consequently", "thus", "so", "while",
|
|
"whereas", "moreover", "in turn",
|
|
)
|
|
|
|
|
|
def _strip_provenance(surface: str) -> str:
|
|
return _PROVENANCE_TAIL_RE.sub("", surface).strip()
|
|
|
|
|
|
def _split_sentences(text: str) -> list[str]:
|
|
parts = re.split(r"(?<=[.!?])\s+", text.strip())
|
|
return [p.strip() for p in parts if p.strip()]
|
|
|
|
|
|
def _alpha_tokens(text: str) -> int:
|
|
return len(re.findall(r"[A-Za-z]+", text))
|
|
|
|
|
|
def _has_connective(text: str) -> bool:
|
|
low = text.lower()
|
|
return any(re.search(rf"\b{re.escape(c)}\b", low) for c in _CONNECTIVES)
|
|
|
|
|
|
@dataclass(frozen=True, slots=True)
|
|
class CaseResult:
|
|
case_id: str
|
|
category: str
|
|
prompt: str
|
|
surface: str
|
|
grounding_source: str
|
|
sentence_count: int
|
|
each_sentence_long_enough: bool
|
|
connective_present: bool
|
|
grounded: bool
|
|
subject_named: bool
|
|
expects_connective: bool
|
|
|
|
|
|
@dataclass
|
|
class LaneReport:
|
|
metrics: dict[str, Any] = field(default_factory=dict)
|
|
case_details: list[dict[str, Any]] = field(default_factory=list)
|
|
|
|
|
|
def _run_case(case: dict[str, Any]) -> CaseResult:
|
|
rt = ChatRuntime()
|
|
resp = rt.chat(case["prompt"])
|
|
surface = resp.surface
|
|
grounding = resp.grounding_source or "none"
|
|
|
|
stripped = _strip_provenance(surface)
|
|
sentences = _split_sentences(stripped)
|
|
each_long = all(_alpha_tokens(s) >= 4 for s in sentences) if sentences else False
|
|
|
|
subj = case.get("subject_lemma", "").lower()
|
|
subj_named = (subj in surface.lower()) if subj else True
|
|
|
|
return CaseResult(
|
|
case_id=case["id"],
|
|
category=case.get("category", "uncategorised"),
|
|
prompt=case["prompt"],
|
|
surface=surface,
|
|
grounding_source=grounding,
|
|
sentence_count=len(sentences),
|
|
each_sentence_long_enough=each_long,
|
|
connective_present=_has_connective(stripped),
|
|
grounded=(grounding in {"pack", "teaching"}),
|
|
subject_named=subj_named,
|
|
expects_connective=bool(case.get("expects_connective", False)),
|
|
)
|
|
|
|
|
|
def run_lane(cases: list[dict[str, Any]], config: Any = None) -> LaneReport: # noqa: ARG001
|
|
if not cases:
|
|
return LaneReport(metrics={}, case_details=[])
|
|
|
|
results = [_run_case(c) for c in cases]
|
|
total = len(results)
|
|
|
|
multi = sum(1 for r in results if r.sentence_count >= 2)
|
|
non_frag = sum(1 for r in results if r.each_sentence_long_enough)
|
|
grounded = sum(1 for r in results if r.grounded)
|
|
named = sum(1 for r in results if r.subject_named)
|
|
|
|
conn_expected = [r for r in results if r.expects_connective]
|
|
conn_rate = (
|
|
round(sum(1 for r in conn_expected if r.connective_present) / len(conn_expected), 4)
|
|
if conn_expected else 1.0
|
|
)
|
|
|
|
metrics: dict[str, Any] = {
|
|
"cases": total,
|
|
"multi_sentence_rate": round(multi / total, 4) if total else 0.0,
|
|
"non_fragment_rate": round(non_frag / total, 4) if total else 0.0,
|
|
"grounded_rate": round(grounded / total, 4) if total else 0.0,
|
|
"subject_named_rate": round(named / total, 4) if total else 0.0,
|
|
"connective_present_rate": conn_rate,
|
|
}
|
|
|
|
case_details = [
|
|
{
|
|
"case_id": r.case_id,
|
|
"category": r.category,
|
|
"prompt": r.prompt,
|
|
"surface": r.surface,
|
|
"grounding_source": r.grounding_source,
|
|
"sentence_count": r.sentence_count,
|
|
"each_sentence_long_enough": r.each_sentence_long_enough,
|
|
"connective_present": r.connective_present,
|
|
"grounded": r.grounded,
|
|
"subject_named": r.subject_named,
|
|
"expects_connective": r.expects_connective,
|
|
}
|
|
for r in results
|
|
]
|
|
|
|
return LaneReport(metrics=metrics, case_details=case_details)
|