File size: 1,253 Bytes
64b0d5e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
from __future__ import annotations

import argparse
import json
import re
from pathlib import Path


ENGLISH_MARKERS = re.compile(r"\b(okay|let|first|then|wait|problem|answer|step|correct|hmm)\b", re.IGNORECASE)


def parse_args() -> argparse.Namespace:
    parser = argparse.ArgumentParser()
    parser.add_argument("results_json")
    return parser.parse_args()


def main() -> None:
    args = parse_args()
    rows = json.loads(Path(args.results_json).read_text())
    compliant = 0
    for row in rows:
        output = row["output"]
        match = re.search(r"<think>(.*?)</think>", output, re.DOTALL)
        think = match.group(1).strip() if match else ""
        lines = [line.strip() for line in think.splitlines() if line.strip()]
        pseudocode_like = sum(1 for line in lines if "=" in line or "->" in line)
        has_english = any(ENGLISH_MARKERS.search(line) for line in lines)
        if lines and pseudocode_like >= max(3, int(len(lines) * 0.6)) and not has_english:
            compliant += 1

    summary = {
        "compliant": compliant,
        "total": len(rows),
        "compliance": round(compliant / len(rows), 4) if rows else 0.0,
    }
    print(json.dumps(summary, indent=2))


if __name__ == "__main__":
    main()