Download task_029/tests/validate_outputs.py from Lego-X/UXInteract: direct link, hf CLI and curl.
- Browser
- Download file 1.81 kB
-
https://huggingface.co/datasets/Lego-X/UXInteract/resolve/main/task_029/tests/validate_outputs.py
- Command line
-
hf download hf://datasets/Lego-X/UXInteract/task_029/tests/validate_outputs.py
-
curl -L -o validate_outputs.py https://huggingface.co/datasets/Lego-X/UXInteract/resolve/main/task_029/tests/validate_outputs.py
1.81 kB
| import pathlib | |
| import re | |
| import struct | |
| root = pathlib.Path.cwd() | |
| img_path = root / 'train-images-idx3-ubyte' | |
| label_path = root / 'train-labels-idx1-ubyte' | |
| assert img_path.exists(), 'missing train-images-idx3-ubyte fixture' | |
| assert label_path.exists(), 'missing train-labels-idx1-ubyte fixture' | |
| magic, count, rows, cols = struct.unpack('>IIII', img_path.read_bytes()[:16]) | |
| assert (magic, count, rows, cols) == (2051, 10, 8, 8), 'unexpected tiny MNIST image header' | |
| lmagic, lcount = struct.unpack('>II', label_path.read_bytes()[:8]) | |
| assert (lmagic, lcount) == (2049, 10), 'unexpected tiny MNIST label header' | |
| report_path = root / 'report.html' | |
| assert report_path.exists() and report_path.stat().st_size > 0, 'missing report.html' | |
| report = report_path.read_text(encoding='utf-8', errors='ignore').lower() | |
| for token in ['mnist', 'mlp']: | |
| assert token in report, f'report missing {token}' | |
| assert 'f1' in report, 'report missing f1' | |
| assert 'acc' in report or 'accuracy' in report, 'report missing accuracy/acc' | |
| assert ( | |
| '80/20' in report | |
| or '4:1' in report | |
| or ('80%' in report and '20%' in report) | |
| or ('0.8' in report and '0.2' in report) | |
| ), 'report missing 80/20 split evidence' | |
| numbers = [float(x) for x in re.findall(r'(?<![\w.])(?:0(?:\.\d+)?|1(?:\.0+)?)(?![\w.])', report)] | |
| assert any(0 <= n <= 1 for n in numbers), 'report missing normalized metric value' | |
| # Parse labeled metrics required by the task. No unpublished score floor is imposed. | |
| acc_vals = [float(m) for m in re.findall(r'(?:accuracy|acc)\s*[:=]?\s*(\d+(?:\.\d+)?)', report)] | |
| f1_vals = [float(m) for m in re.findall(r'f1[\w ]*?\s*[:=]?\s*(\d+(?:\.\d+)?)', report)] | |
| assert acc_vals, 'report missing a labeled accuracy/acc metric value' | |
| assert f1_vals, 'report missing a labeled f1 metric value' | |