Download evaluation/evaluate.py from QLU-LLM/CAD: direct link, hf CLI and curl.
- Browser
- Download file 2.65 kB
-
https://huggingface.co/datasets/QLU-LLM/CAD/resolve/main/evaluation/evaluate.py
- Command line
-
hf download hf://datasets/QLU-LLM/CAD/evaluation/evaluate.py
-
curl -L -o evaluate.py https://huggingface.co/datasets/QLU-LLM/CAD/resolve/main/evaluation/evaluate.py
2.65 kB
| """Evaluate saved GUI action predictions against dataset references. | |
| Prediction records contain a zero-based `_idx` and the model response in | |
| `prediction`. The response uses <action> and <parameters> tags, with an optional | |
| <ui_reasoning> block. An `error` field records an inference failure. | |
| """ | |
| import argparse | |
| from pathlib import Path | |
| if __package__: | |
| from .metrics import ScoringError, score_predictions, write_json, write_jsonl | |
| else: | |
| from metrics import ScoringError, score_predictions, write_json, write_jsonl | |
| def main(): | |
| parser = argparse.ArgumentParser(description='Evaluate CAD GUI action predictions.') | |
| parser.add_argument( | |
| '--dataset', type=Path, | |
| default=Path(__file__).resolve().parent.parent / 'GUI/annotations/test_final.jsonl.gz', | |
| help='Reference dataset in JSONL or JSONL.GZ format.', | |
| ) | |
| parser.add_argument('--predictions', type=Path, required=True, | |
| help='JSONL or JSONL.GZ records with _idx and prediction fields.') | |
| parser.add_argument('--output-dir', type=Path, required=True, | |
| help='Directory for metrics.json and details.jsonl.') | |
| parser.add_argument('--start-index', type=int, default=0) | |
| parser.add_argument('--limit', type=int, default=0, help='Maximum reference rows. Zero selects all remaining rows.') | |
| parser.add_argument('--num-shards', type=int, default=1) | |
| parser.add_argument('--shard-index', type=int, default=0) | |
| args = parser.parse_args() | |
| try: | |
| summary, details = score_predictions( | |
| args.dataset, args.predictions, start_index=args.start_index, | |
| limit=args.limit, num_shards=args.num_shards, shard_index=args.shard_index, | |
| ) | |
| write_json(args.output_dir / 'metrics.json', summary) | |
| write_jsonl(args.output_dir / 'details.jsonl', details) | |
| except (ScoringError, OSError) as error: | |
| parser.exit(1, f'Evaluation failed: {error}\n') | |
| by_action = summary['by_gt_action'] | |
| main_metrics = [ | |
| ('Action Acc.', summary['metrics']['action_accuracy']), | |
| ('Click Param. Acc.', by_action.get('click', {}).get('parameter_accuracy')), | |
| ('Double-click Param. Acc.', by_action.get('double_click', {}).get('parameter_accuracy')), | |
| ('Input Param. Acc.', by_action.get('type', {}).get('parameter_accuracy')), | |
| ('Step Acc.', summary['metrics']['step_accuracy']), | |
| ] | |
| for label, value in main_metrics: | |
| displayed = 'N/A' if value is None else f'{value * 100:.2f}%' | |
| print(f'{label:<25} {displayed}') | |
| print(f'Results saved to {args.output_dir.resolve()}') | |
| if __name__ == '__main__': | |
| main() | |