#!/usr/bin/env python3 # SPDX-FileCopyrightText: 2025 Stanford University, ETH Zurich, and the project authors (see CONTRIBUTORS.md) # SPDX-FileCopyrightText: 2025 This source file is part of the OpenTSLM open-source project. # # SPDX-License-Identifier: MIT """ Parse sleep baseline evaluation results from a structured JSON file and compute accuracy and F1 statistics. Designed for JSON files with the following shape: { "model_name": "...", "dataset_name": "SleepEDFCoTQADataset", "total_samples": 930, "successful_inferences": 930, "success_rate": 1.0, "metrics": {"accuracy": 10.75}, "detailed_results": [ { "sample_idx": 0, "input_text": "...", "target_answer": "... Answer: Wake", "generated_answer": "... Answer: Wake", "metrics": { "accuracy": 1, "gt_label": "wake", "pred_label": "wake" } }, ... ] } The script prioritizes labels under detailed_results[i]["metrics"]["gt_label"|"pred_label"], falling back to extracting the trailing "Answer: