evalsuite-python 0.5.1__tar.gz → 0.5.3__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {evalsuite_python-0.5.1 → evalsuite_python-0.5.3}/CHANGELOG.md +34 -0
- {evalsuite_python-0.5.1 → evalsuite_python-0.5.3}/PKG-INFO +34 -34
- {evalsuite_python-0.5.1 → evalsuite_python-0.5.3}/README.md +33 -33
- evalsuite_python-0.5.3/src/evalsuite/_lazy.py +32 -0
- {evalsuite_python-0.5.1 → evalsuite_python-0.5.3}/src/evalsuite/api.py +2 -1
- {evalsuite_python-0.5.1 → evalsuite_python-0.5.3}/src/evalsuite/calibration.py +7 -1
- {evalsuite_python-0.5.1 → evalsuite_python-0.5.3}/src/evalsuite/classification/metrics.py +4 -2
- {evalsuite_python-0.5.1 → evalsuite_python-0.5.3}/src/evalsuite/clinical/report.py +7 -1
- {evalsuite_python-0.5.1 → evalsuite_python-0.5.3}/src/evalsuite/llmsys/_common.py +29 -10
- {evalsuite_python-0.5.1 → evalsuite_python-0.5.3}/src/evalsuite/llmsys/code.py +42 -33
- {evalsuite_python-0.5.1 → evalsuite_python-0.5.3}/src/evalsuite/llmsys/efficiency.py +3 -4
- {evalsuite_python-0.5.1 → evalsuite_python-0.5.3}/src/evalsuite/llmsys/safety.py +1 -1
- {evalsuite_python-0.5.1 → evalsuite_python-0.5.3}/src/evalsuite/stats/effect.py +8 -2
- {evalsuite_python-0.5.1 → evalsuite_python-0.5.3}/src/evalsuite/stats/hypothesis.py +29 -10
- {evalsuite_python-0.5.1 → evalsuite_python-0.5.3}/src/evalsuite/stats/intervals.py +9 -2
- {evalsuite_python-0.5.1 → evalsuite_python-0.5.3}/src/evalsuite/stats/paired.py +9 -2
- {evalsuite_python-0.5.1 → evalsuite_python-0.5.3}/src/evalsuite/text/judge.py +8 -2
- {evalsuite_python-0.5.1 → evalsuite_python-0.5.3}/src/evalsuite/text/structured.py +5 -1
- {evalsuite_python-0.5.1 → evalsuite_python-0.5.3}/src/evalsuite/version.py +1 -1
- {evalsuite_python-0.5.1 → evalsuite_python-0.5.3}/src/evalsuite/vision/segmentation.py +7 -1
- evalsuite_python-0.5.3/tests/llmsys/test_hardening.py +52 -0
- evalsuite_python-0.5.3/tests/stats/test_fast_paths.py +30 -0
- {evalsuite_python-0.5.1 → evalsuite_python-0.5.3}/.gitignore +0 -0
- {evalsuite_python-0.5.1 → evalsuite_python-0.5.3}/CONTRIBUTING.md +0 -0
- {evalsuite_python-0.5.1 → evalsuite_python-0.5.3}/LICENSE +0 -0
- {evalsuite_python-0.5.1 → evalsuite_python-0.5.3}/pyproject.toml +0 -0
- {evalsuite_python-0.5.1 → evalsuite_python-0.5.3}/src/evalsuite/__init__.py +0 -0
- {evalsuite_python-0.5.1 → evalsuite_python-0.5.3}/src/evalsuite/__main__.py +0 -0
- {evalsuite_python-0.5.1 → evalsuite_python-0.5.3}/src/evalsuite/_bench_metrics.py +0 -0
- {evalsuite_python-0.5.1 → evalsuite_python-0.5.3}/src/evalsuite/benchmarks.py +0 -0
- {evalsuite_python-0.5.1 → evalsuite_python-0.5.3}/src/evalsuite/classification/__init__.py +0 -0
- {evalsuite_python-0.5.1 → evalsuite_python-0.5.3}/src/evalsuite/classification/_common.py +0 -0
- {evalsuite_python-0.5.1 → evalsuite_python-0.5.3}/src/evalsuite/cli/__init__.py +0 -0
- {evalsuite_python-0.5.1 → evalsuite_python-0.5.3}/src/evalsuite/cli/main.py +0 -0
- {evalsuite_python-0.5.1 → evalsuite_python-0.5.3}/src/evalsuite/clinical/__init__.py +0 -0
- {evalsuite_python-0.5.1 → evalsuite_python-0.5.3}/src/evalsuite/clinical/metrics.py +0 -0
- {evalsuite_python-0.5.1 → evalsuite_python-0.5.3}/src/evalsuite/core/__init__.py +0 -0
- {evalsuite_python-0.5.1 → evalsuite_python-0.5.3}/src/evalsuite/core/context.py +0 -0
- {evalsuite_python-0.5.1 → evalsuite_python-0.5.3}/src/evalsuite/core/exceptions.py +0 -0
- {evalsuite_python-0.5.1 → evalsuite_python-0.5.3}/src/evalsuite/core/export.py +0 -0
- {evalsuite_python-0.5.1 → evalsuite_python-0.5.3}/src/evalsuite/core/registry.py +0 -0
- {evalsuite_python-0.5.1 → evalsuite_python-0.5.3}/src/evalsuite/core/result.py +0 -0
- {evalsuite_python-0.5.1 → evalsuite_python-0.5.3}/src/evalsuite/core/types.py +0 -0
- {evalsuite_python-0.5.1 → evalsuite_python-0.5.3}/src/evalsuite/core/validation.py +0 -0
- {evalsuite_python-0.5.1 → evalsuite_python-0.5.3}/src/evalsuite/llmsys/__init__.py +0 -0
- {evalsuite_python-0.5.1 → evalsuite_python-0.5.3}/src/evalsuite/llmsys/agents.py +0 -0
- {evalsuite_python-0.5.1 → evalsuite_python-0.5.3}/src/evalsuite/llmsys/longcontext.py +0 -0
- {evalsuite_python-0.5.1 → evalsuite_python-0.5.3}/src/evalsuite/llmsys/multilingual.py +0 -0
- {evalsuite_python-0.5.1 → evalsuite_python-0.5.3}/src/evalsuite/llmsys/robustness.py +0 -0
- {evalsuite_python-0.5.1 → evalsuite_python-0.5.3}/src/evalsuite/llmsys/uncertainty.py +0 -0
- {evalsuite_python-0.5.1 → evalsuite_python-0.5.3}/src/evalsuite/plot.py +0 -0
- {evalsuite_python-0.5.1 → evalsuite_python-0.5.3}/src/evalsuite/py.typed +0 -0
- {evalsuite_python-0.5.1 → evalsuite_python-0.5.3}/src/evalsuite/regression/__init__.py +0 -0
- {evalsuite_python-0.5.1 → evalsuite_python-0.5.3}/src/evalsuite/regression/metrics.py +0 -0
- {evalsuite_python-0.5.1 → evalsuite_python-0.5.3}/src/evalsuite/reporting.py +0 -0
- {evalsuite_python-0.5.1 → evalsuite_python-0.5.3}/src/evalsuite/stats/__init__.py +0 -0
- {evalsuite_python-0.5.1 → evalsuite_python-0.5.3}/src/evalsuite/stats/_resolve.py +0 -0
- {evalsuite_python-0.5.1 → evalsuite_python-0.5.3}/src/evalsuite/stats/compare.py +0 -0
- {evalsuite_python-0.5.1 → evalsuite_python-0.5.3}/src/evalsuite/stats/results.py +0 -0
- {evalsuite_python-0.5.1 → evalsuite_python-0.5.3}/src/evalsuite/text/__init__.py +0 -0
- {evalsuite_python-0.5.1 → evalsuite_python-0.5.3}/src/evalsuite/text/_common.py +0 -0
- {evalsuite_python-0.5.1 → evalsuite_python-0.5.3}/src/evalsuite/text/factuality.py +0 -0
- {evalsuite_python-0.5.1 → evalsuite_python-0.5.3}/src/evalsuite/text/generation.py +0 -0
- {evalsuite_python-0.5.1 → evalsuite_python-0.5.3}/src/evalsuite/text/qa.py +0 -0
- {evalsuite_python-0.5.1 → evalsuite_python-0.5.3}/src/evalsuite/text/rag.py +0 -0
- {evalsuite_python-0.5.1 → evalsuite_python-0.5.3}/src/evalsuite/text/reasoning.py +0 -0
- {evalsuite_python-0.5.1 → evalsuite_python-0.5.3}/src/evalsuite/text/report.py +0 -0
- {evalsuite_python-0.5.1 → evalsuite_python-0.5.3}/src/evalsuite/text/retrieval.py +0 -0
- {evalsuite_python-0.5.1 → evalsuite_python-0.5.3}/src/evalsuite/text/semantic.py +0 -0
- {evalsuite_python-0.5.1 → evalsuite_python-0.5.3}/src/evalsuite/text/spice.py +0 -0
- {evalsuite_python-0.5.1 → evalsuite_python-0.5.3}/src/evalsuite/vision/__init__.py +0 -0
- {evalsuite_python-0.5.1 → evalsuite_python-0.5.3}/src/evalsuite/vision/detection.py +0 -0
- {evalsuite_python-0.5.1 → evalsuite_python-0.5.3}/tests/__init__.py +0 -0
- {evalsuite_python-0.5.1 → evalsuite_python-0.5.3}/tests/classification/__init__.py +0 -0
- {evalsuite_python-0.5.1 → evalsuite_python-0.5.3}/tests/classification/test_against_sklearn.py +0 -0
- {evalsuite_python-0.5.1 → evalsuite_python-0.5.3}/tests/clinical/__init__.py +0 -0
- {evalsuite_python-0.5.1 → evalsuite_python-0.5.3}/tests/clinical/test_outputs.py +0 -0
- {evalsuite_python-0.5.1 → evalsuite_python-0.5.3}/tests/clinical/test_v020.py +0 -0
- {evalsuite_python-0.5.1 → evalsuite_python-0.5.3}/tests/conftest.py +0 -0
- {evalsuite_python-0.5.1 → evalsuite_python-0.5.3}/tests/integration/__init__.py +0 -0
- {evalsuite_python-0.5.1 → evalsuite_python-0.5.3}/tests/integration/test_qa.py +0 -0
- {evalsuite_python-0.5.1 → evalsuite_python-0.5.3}/tests/integration/test_readme_examples.py +0 -0
- {evalsuite_python-0.5.1 → evalsuite_python-0.5.3}/tests/integration/test_repo_hygiene.py +0 -0
- {evalsuite_python-0.5.1 → evalsuite_python-0.5.3}/tests/llmsys/__init__.py +0 -0
- {evalsuite_python-0.5.1 → evalsuite_python-0.5.3}/tests/llmsys/test_code_longcontext_efficiency.py +0 -0
- {evalsuite_python-0.5.1 → evalsuite_python-0.5.3}/tests/llmsys/test_edges.py +0 -0
- {evalsuite_python-0.5.1 → evalsuite_python-0.5.3}/tests/llmsys/test_safety_robustness.py +0 -0
- {evalsuite_python-0.5.1 → evalsuite_python-0.5.3}/tests/llmsys/test_uncertainty_agents_multilingual.py +0 -0
- {evalsuite_python-0.5.1 → evalsuite_python-0.5.3}/tests/output/__init__.py +0 -0
- {evalsuite_python-0.5.1 → evalsuite_python-0.5.3}/tests/output/test_benchmarks.py +0 -0
- {evalsuite_python-0.5.1 → evalsuite_python-0.5.3}/tests/output/test_cli.py +0 -0
- {evalsuite_python-0.5.1 → evalsuite_python-0.5.3}/tests/output/test_plot.py +0 -0
- {evalsuite_python-0.5.1 → evalsuite_python-0.5.3}/tests/output/test_reporting.py +0 -0
- {evalsuite_python-0.5.1 → evalsuite_python-0.5.3}/tests/regression/__init__.py +0 -0
- {evalsuite_python-0.5.1 → evalsuite_python-0.5.3}/tests/regression/test_against_sklearn.py +0 -0
- {evalsuite_python-0.5.1 → evalsuite_python-0.5.3}/tests/stats/__init__.py +0 -0
- {evalsuite_python-0.5.1 → evalsuite_python-0.5.3}/tests/stats/test_branches.py +0 -0
- {evalsuite_python-0.5.1 → evalsuite_python-0.5.3}/tests/stats/test_compare.py +0 -0
- {evalsuite_python-0.5.1 → evalsuite_python-0.5.3}/tests/stats/test_reference.py +0 -0
- {evalsuite_python-0.5.1 → evalsuite_python-0.5.3}/tests/text/__init__.py +0 -0
- {evalsuite_python-0.5.1 → evalsuite_python-0.5.3}/tests/text/test_against_references.py +0 -0
- {evalsuite_python-0.5.1 → evalsuite_python-0.5.3}/tests/text/test_text_edges.py +0 -0
- {evalsuite_python-0.5.1 → evalsuite_python-0.5.3}/tests/text/test_v040.py +0 -0
- {evalsuite_python-0.5.1 → evalsuite_python-0.5.3}/tests/unit/__init__.py +0 -0
- {evalsuite_python-0.5.1 → evalsuite_python-0.5.3}/tests/unit/test_core.py +0 -0
- {evalsuite_python-0.5.1 → evalsuite_python-0.5.3}/tests/unit/test_edges.py +0 -0
- {evalsuite_python-0.5.1 → evalsuite_python-0.5.3}/tests/vision/__init__.py +0 -0
- {evalsuite_python-0.5.1 → evalsuite_python-0.5.3}/tests/vision/test_detection.py +0 -0
- {evalsuite_python-0.5.1 → evalsuite_python-0.5.3}/tests/vision/test_edges.py +0 -0
- {evalsuite_python-0.5.1 → evalsuite_python-0.5.3}/tests/vision/test_outputs.py +0 -0
- {evalsuite_python-0.5.1 → evalsuite_python-0.5.3}/tests/vision/test_segmentation.py +0 -0
|
@@ -6,6 +6,40 @@ All notable changes to this project are documented here. The format follows
|
|
|
6
6
|
|
|
7
7
|
## [Unreleased]
|
|
8
8
|
|
|
9
|
+
## [0.5.3] - 2026-11-09
|
|
10
|
+
|
|
11
|
+
Performance release; benchmarks rerun. No API changes.
|
|
12
|
+
|
|
13
|
+
### Changed
|
|
14
|
+
- `t_test` computes the t statistic and its p-value directly (Student-t tail via `scipy.special.stdtr`) from
|
|
15
|
+
one pass over each sample instead of calling `scipy.stats.ttest_ind` and recomputing means and variances;
|
|
16
|
+
identical to SciPy within 1e-15 and now faster than it (was 0.43×).
|
|
17
|
+
- `latency_percentiles` and every LLM-systems latency/step/token summary take min, max and all percentiles
|
|
18
|
+
from a single `np.partition` instead of separate `np.percentile` calls (identical values, ~1.4× faster).
|
|
19
|
+
- Statistical tests no longer copy inputs that are already float64.
|
|
20
|
+
- CI: Python 3.9 tests run on ubuntu-22.04 (ubuntu-latest no longer ships 3.9); GitHub Actions updated
|
|
21
|
+
(checkout 7.0.1, setup-python 7.1.0, upload-artifact 7.0.2, download-artifact 8.0.2).
|
|
22
|
+
- README and BENCHMARKS.md: all suites and the per-metric table rerun on 0.5.3.
|
|
23
|
+
|
|
24
|
+
## [0.5.2] - 2026-11-07
|
|
25
|
+
|
|
26
|
+
Security and performance hardening. No API changes.
|
|
27
|
+
|
|
28
|
+
### Security
|
|
29
|
+
- The built-in PII e-mail detector no longer backtracks quadratically: `detect_pii` / `pii_leakage_rate`
|
|
30
|
+
on 60 kB of adversarial text went from ~6 s to ~10 ms.
|
|
31
|
+
- `codebleu`, `code_complexity` and `syntax_validity_rate` handle source nested too deeply for CPython's
|
|
32
|
+
parser (MemoryError / RecursionError) instead of crashing: invalid for syntax validity, an
|
|
33
|
+
`InputValidationError` for complexity, no syntax match for CodeBLEU.
|
|
34
|
+
- Internal `assert` type checks replaced by explicit errors, so behaviour is the same under `python -O`.
|
|
35
|
+
- CI and release workflows pin every action to a commit SHA; Dependabot keeps them and the dependencies current.
|
|
36
|
+
- Documented that user-supplied regular expressions (`format_compliance`) run on a backtracking engine.
|
|
37
|
+
|
|
38
|
+
### Performance
|
|
39
|
+
- `import evalsuite` no longer imports SciPy; it is loaded on first use (import time ~0.6 s → ~0.07 s).
|
|
40
|
+
- CodeBLEU syntax match uses interned subtree ids instead of serialised strings: linear in the size of the
|
|
41
|
+
program rather than quadratic.
|
|
42
|
+
|
|
9
43
|
## [0.5.1] - 2026-10-10
|
|
10
44
|
|
|
11
45
|
### Added
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: evalsuite-python
|
|
3
|
-
Version: 0.5.
|
|
3
|
+
Version: 0.5.3
|
|
4
4
|
Summary: A unified Python framework for machine-learning, clinical, statistical, segmentation, object-detection, uncertainty, and model evaluation.
|
|
5
5
|
Project-URL: Homepage, https://evalsuite-nine.vercel.app
|
|
6
6
|
Project-URL: Documentation, https://evalsuite-nine.vercel.app/docs
|
|
@@ -83,7 +83,7 @@ Description-Content-Type: text/markdown
|
|
|
83
83
|
EvalSuite brings classification, regression, clinical, statistical, segmentation and object-detection
|
|
84
84
|
evaluation into one consistent, validated, documented framework.
|
|
85
85
|
|
|
86
|
-
> **Status: stable (0.5.
|
|
86
|
+
> **Status: stable (0.5.3).** Every item on the 0.1.0–0.5.0 roadmaps is implemented and verified, including SPICE.
|
|
87
87
|
> **LLM systems arrive in 0.5.0**: safety, robustness, calibration and uncertainty, agents and tool use,
|
|
88
88
|
> multilingual, code generation, long context and summarization, and inference efficiency and cost.
|
|
89
89
|
|
|
@@ -339,51 +339,51 @@ Input files can be CSV, TSV, Parquet or JSON. Output format follows `--format` o
|
|
|
339
339
|
|
|
340
340
|
## Performance
|
|
341
341
|
|
|
342
|
-
Benchmarked against reference implementations on the same data (fastest of 5 runs; EvalSuite 0.5.
|
|
342
|
+
Benchmarked against reference implementations on the same data (fastest of 5 runs; EvalSuite 0.5.3, Python 3.13,
|
|
343
343
|
NumPy 2.5, Linux x86_64). **Overall: 81 of 81 rows agree with the reference** (largest
|
|
344
|
-
difference 2.5e-14),
|
|
345
|
-
27 cases and three sizes is **
|
|
344
|
+
difference 2.5e-14), 58 are faster, and the geometric-mean speed-up across all
|
|
345
|
+
27 cases and three sizes is **2.06×**. At 1,000,000 samples (pixels for
|
|
346
346
|
segmentation; 1,000 images for detection and 50 for Hausdorff; 10,000 examples for the LLM cases), in
|
|
347
347
|
alphabetical order:
|
|
348
348
|
|
|
349
349
|
| Case | Reference | EvalSuite (ms) | Reference (ms) | Speed-up |
|
|
350
350
|
| --- | --- | ---: | ---: | ---: |
|
|
351
|
-
| 10 classes: macro F1 | scikit-learn |
|
|
352
|
-
| agreement: Krippendorff's alpha, interval (4 raters × 10000 items) | krippendorff | 4.
|
|
353
|
-
| binary: 8 label metrics via evaluate() | scikit-learn |
|
|
354
|
-
| binary: ROC AUC | scikit-learn |
|
|
355
|
-
| calibration: slope and intercept | statsmodels |
|
|
356
|
-
| clinical: diagnostic report (7 CIs) | statsmodels |
|
|
357
|
-
| clinical: sensitivity, specificity, LR+, LR− | scikit-learn |
|
|
358
|
-
| decision curve: 99 thresholds | NumPy loop |
|
|
359
|
-
| detection: COCO evaluation (1000 images) | pycocotools |
|
|
360
|
-
| multiple testing: Hochberg (n p-values) | statsmodels |
|
|
361
|
-
| regression: MAE, MSE, RMSE, R² via evaluate() | scikit-learn |
|
|
362
|
-
| retrieval: MRR, MAP@20, NDCG@10 (10000 queries) | ranx |
|
|
363
|
-
| segmentation: Dice and IoU per class (n = pixels) | scikit-learn |
|
|
364
|
-
| segmentation: Hausdorff distance (50 images) | SciPy |
|
|
365
|
-
| statistics: Cramér's V (5×5 table) | SciPy | 0.
|
|
366
|
-
| statistics: Mann–Whitney U | SciPy |
|
|
367
|
-
| statistics: Welch t-test | SciPy |
|
|
368
|
-
| structured: JSON Schema compliance (10000 documents) | jsonschema |
|
|
369
|
-
| systems: CodeBLEU n-gram terms (1000 programs) | codebleu |
|
|
370
|
-
| systems: confidence AUROC (n answers) | scikit-learn |
|
|
371
|
-
| systems: distribution-shift drop, Welch CI (n scores) | SciPy |
|
|
372
|
-
| systems: invalid tool calls vs JSON Schema (10000 tasks) | jsonschema |
|
|
373
|
-
| systems: latency p50 / p95 / p99 (n requests) | NumPy |
|
|
374
|
-
| systems: maintainability index (1000 programs) | radon |
|
|
375
|
-
| text: corpus BLEU and chrF (10000 sentences) | sacreBLEU |
|
|
376
|
-
| text: METEOR, exact and stem matches (10000 sentences) | NLTK |
|
|
377
|
-
| text: ROUGE-1, ROUGE-2, ROUGE-L (10000 sentences) | rouge-score |
|
|
351
|
+
| 10 classes: macro F1 | scikit-learn | 35.9 | 122.1 | **3.4×** |
|
|
352
|
+
| agreement: Krippendorff's alpha, interval (4 raters × 10000 items) | krippendorff | 4.4 | 3.4 | 0.77× |
|
|
353
|
+
| binary: 8 label metrics via evaluate() | scikit-learn | 23.3 | 866.5 | **37.2×** |
|
|
354
|
+
| binary: ROC AUC | scikit-learn | 187.9 | 305.7 | **1.6×** |
|
|
355
|
+
| calibration: slope and intercept | statsmodels | 236.6 | 1085.8 | **4.6×** |
|
|
356
|
+
| clinical: diagnostic report (7 CIs) | statsmodels | 26.2 | 5.7 | 0.22× |
|
|
357
|
+
| clinical: sensitivity, specificity, LR+, LR− | scikit-learn | 122.9 | 353.9 | **2.9×** |
|
|
358
|
+
| decision curve: 99 thresholds | NumPy loop | 167.3 | 238.1 | **1.4×** |
|
|
359
|
+
| detection: COCO evaluation (1000 images) | pycocotools | 684.7 | 660.8 | 0.97× |
|
|
360
|
+
| multiple testing: Hochberg (n p-values) | statsmodels | 71.3 | 92.4 | **1.3×** |
|
|
361
|
+
| regression: MAE, MSE, RMSE, R² via evaluate() | scikit-learn | 27.3 | 18.8 | 0.69× |
|
|
362
|
+
| retrieval: MRR, MAP@20, NDCG@10 (10000 queries) | ranx | 129.5 | 614.7 | **4.7×** |
|
|
363
|
+
| segmentation: Dice and IoU per class (n = pixels) | scikit-learn | 35.7 | 235.1 | **6.6×** |
|
|
364
|
+
| segmentation: Hausdorff distance (50 images) | SciPy | 18.8 | 13.6 | 0.72× |
|
|
365
|
+
| statistics: Cramér's V (5×5 table) | SciPy | 0.2 | 0.2 | 0.90× |
|
|
366
|
+
| statistics: Mann–Whitney U | SciPy | 342.3 | 325.8 | 0.95× |
|
|
367
|
+
| statistics: Welch t-test | SciPy | 8.2 | 11.9 | **1.4×** |
|
|
368
|
+
| structured: JSON Schema compliance (10000 documents) | jsonschema | 93.9 | 223.5 | **2.4×** |
|
|
369
|
+
| systems: CodeBLEU n-gram terms (1000 programs) | codebleu | 413.8 | 507.8 | **1.2×** |
|
|
370
|
+
| systems: confidence AUROC (n answers) | scikit-learn | 154.1 | 251.8 | **1.6×** |
|
|
371
|
+
| systems: distribution-shift drop, Welch CI (n scores) | SciPy | 10.9 | 12.9 | **1.2×** |
|
|
372
|
+
| systems: invalid tool calls vs JSON Schema (10000 tasks) | jsonschema | 78.4 | 213.2 | **2.7×** |
|
|
373
|
+
| systems: latency p50 / p95 / p99 (n requests) | NumPy | 18.0 | 15.9 | 0.88× |
|
|
374
|
+
| systems: maintainability index (1000 programs) | radon | 89.3 | 96.0 | **1.1×** |
|
|
375
|
+
| text: corpus BLEU and chrF (10000 sentences) | sacreBLEU | 1728.8 | 1993.1 | **1.2×** |
|
|
376
|
+
| text: METEOR, exact and stem matches (10000 sentences) | NLTK | 319.1 | 358.6 | **1.1×** |
|
|
377
|
+
| text: ROUGE-1, ROUGE-2, ROUGE-L (10000 sentences) | rouge-score | 716.0 | 612.5 | 0.86× |
|
|
378
378
|
|
|
379
379
|
**Every metric is benchmarked too** (`evalsuite benchmark --suite metrics`): all 225 registered metrics and
|
|
380
380
|
statistics functions at 10,000 and 100,000 samples. 86 are compared with a reference library, 118 with an
|
|
381
381
|
independent textbook formula and 21 (learned, judge-dependent or randomised) are timed alone; **all 204
|
|
382
|
-
comparisons agree**, and against the libraries the geometric-mean speed-up is **2.
|
|
382
|
+
comparisons agree**, and against the libraries the geometric-mean speed-up is **2.80×** (138 of 172
|
|
383
383
|
measurements faster). Per-metric table in BENCHMARKS.md.
|
|
384
384
|
|
|
385
385
|
`evaluate()` validates inputs once and builds the confusion matrix once for all metrics, which is where most
|
|
386
|
-
of the speed-up comes from.
|
|
386
|
+
of the speed-up comes from. The t-tests compute their statistics in one pass and beat SciPy; other hypothesis tests use SciPy underneath. Rows
|
|
387
387
|
below 1× pay for input validation and the extra intervals and effect sizes EvalSuite reports. Reproduce on
|
|
388
388
|
your machine with `evalsuite benchmark`; full table (1k, 100k and 1M samples, peak memory) and notes in
|
|
389
389
|
[BENCHMARKS.md](https://github.com/mkcs28/evalsuite-python/blob/main/BENCHMARKS.md).
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
EvalSuite brings classification, regression, clinical, statistical, segmentation and object-detection
|
|
11
11
|
evaluation into one consistent, validated, documented framework.
|
|
12
12
|
|
|
13
|
-
> **Status: stable (0.5.
|
|
13
|
+
> **Status: stable (0.5.3).** Every item on the 0.1.0–0.5.0 roadmaps is implemented and verified, including SPICE.
|
|
14
14
|
> **LLM systems arrive in 0.5.0**: safety, robustness, calibration and uncertainty, agents and tool use,
|
|
15
15
|
> multilingual, code generation, long context and summarization, and inference efficiency and cost.
|
|
16
16
|
|
|
@@ -266,51 +266,51 @@ Input files can be CSV, TSV, Parquet or JSON. Output format follows `--format` o
|
|
|
266
266
|
|
|
267
267
|
## Performance
|
|
268
268
|
|
|
269
|
-
Benchmarked against reference implementations on the same data (fastest of 5 runs; EvalSuite 0.5.
|
|
269
|
+
Benchmarked against reference implementations on the same data (fastest of 5 runs; EvalSuite 0.5.3, Python 3.13,
|
|
270
270
|
NumPy 2.5, Linux x86_64). **Overall: 81 of 81 rows agree with the reference** (largest
|
|
271
|
-
difference 2.5e-14),
|
|
272
|
-
27 cases and three sizes is **
|
|
271
|
+
difference 2.5e-14), 58 are faster, and the geometric-mean speed-up across all
|
|
272
|
+
27 cases and three sizes is **2.06×**. At 1,000,000 samples (pixels for
|
|
273
273
|
segmentation; 1,000 images for detection and 50 for Hausdorff; 10,000 examples for the LLM cases), in
|
|
274
274
|
alphabetical order:
|
|
275
275
|
|
|
276
276
|
| Case | Reference | EvalSuite (ms) | Reference (ms) | Speed-up |
|
|
277
277
|
| --- | --- | ---: | ---: | ---: |
|
|
278
|
-
| 10 classes: macro F1 | scikit-learn |
|
|
279
|
-
| agreement: Krippendorff's alpha, interval (4 raters × 10000 items) | krippendorff | 4.
|
|
280
|
-
| binary: 8 label metrics via evaluate() | scikit-learn |
|
|
281
|
-
| binary: ROC AUC | scikit-learn |
|
|
282
|
-
| calibration: slope and intercept | statsmodels |
|
|
283
|
-
| clinical: diagnostic report (7 CIs) | statsmodels |
|
|
284
|
-
| clinical: sensitivity, specificity, LR+, LR− | scikit-learn |
|
|
285
|
-
| decision curve: 99 thresholds | NumPy loop |
|
|
286
|
-
| detection: COCO evaluation (1000 images) | pycocotools |
|
|
287
|
-
| multiple testing: Hochberg (n p-values) | statsmodels |
|
|
288
|
-
| regression: MAE, MSE, RMSE, R² via evaluate() | scikit-learn |
|
|
289
|
-
| retrieval: MRR, MAP@20, NDCG@10 (10000 queries) | ranx |
|
|
290
|
-
| segmentation: Dice and IoU per class (n = pixels) | scikit-learn |
|
|
291
|
-
| segmentation: Hausdorff distance (50 images) | SciPy |
|
|
292
|
-
| statistics: Cramér's V (5×5 table) | SciPy | 0.
|
|
293
|
-
| statistics: Mann–Whitney U | SciPy |
|
|
294
|
-
| statistics: Welch t-test | SciPy |
|
|
295
|
-
| structured: JSON Schema compliance (10000 documents) | jsonschema |
|
|
296
|
-
| systems: CodeBLEU n-gram terms (1000 programs) | codebleu |
|
|
297
|
-
| systems: confidence AUROC (n answers) | scikit-learn |
|
|
298
|
-
| systems: distribution-shift drop, Welch CI (n scores) | SciPy |
|
|
299
|
-
| systems: invalid tool calls vs JSON Schema (10000 tasks) | jsonschema |
|
|
300
|
-
| systems: latency p50 / p95 / p99 (n requests) | NumPy |
|
|
301
|
-
| systems: maintainability index (1000 programs) | radon |
|
|
302
|
-
| text: corpus BLEU and chrF (10000 sentences) | sacreBLEU |
|
|
303
|
-
| text: METEOR, exact and stem matches (10000 sentences) | NLTK |
|
|
304
|
-
| text: ROUGE-1, ROUGE-2, ROUGE-L (10000 sentences) | rouge-score |
|
|
278
|
+
| 10 classes: macro F1 | scikit-learn | 35.9 | 122.1 | **3.4×** |
|
|
279
|
+
| agreement: Krippendorff's alpha, interval (4 raters × 10000 items) | krippendorff | 4.4 | 3.4 | 0.77× |
|
|
280
|
+
| binary: 8 label metrics via evaluate() | scikit-learn | 23.3 | 866.5 | **37.2×** |
|
|
281
|
+
| binary: ROC AUC | scikit-learn | 187.9 | 305.7 | **1.6×** |
|
|
282
|
+
| calibration: slope and intercept | statsmodels | 236.6 | 1085.8 | **4.6×** |
|
|
283
|
+
| clinical: diagnostic report (7 CIs) | statsmodels | 26.2 | 5.7 | 0.22× |
|
|
284
|
+
| clinical: sensitivity, specificity, LR+, LR− | scikit-learn | 122.9 | 353.9 | **2.9×** |
|
|
285
|
+
| decision curve: 99 thresholds | NumPy loop | 167.3 | 238.1 | **1.4×** |
|
|
286
|
+
| detection: COCO evaluation (1000 images) | pycocotools | 684.7 | 660.8 | 0.97× |
|
|
287
|
+
| multiple testing: Hochberg (n p-values) | statsmodels | 71.3 | 92.4 | **1.3×** |
|
|
288
|
+
| regression: MAE, MSE, RMSE, R² via evaluate() | scikit-learn | 27.3 | 18.8 | 0.69× |
|
|
289
|
+
| retrieval: MRR, MAP@20, NDCG@10 (10000 queries) | ranx | 129.5 | 614.7 | **4.7×** |
|
|
290
|
+
| segmentation: Dice and IoU per class (n = pixels) | scikit-learn | 35.7 | 235.1 | **6.6×** |
|
|
291
|
+
| segmentation: Hausdorff distance (50 images) | SciPy | 18.8 | 13.6 | 0.72× |
|
|
292
|
+
| statistics: Cramér's V (5×5 table) | SciPy | 0.2 | 0.2 | 0.90× |
|
|
293
|
+
| statistics: Mann–Whitney U | SciPy | 342.3 | 325.8 | 0.95× |
|
|
294
|
+
| statistics: Welch t-test | SciPy | 8.2 | 11.9 | **1.4×** |
|
|
295
|
+
| structured: JSON Schema compliance (10000 documents) | jsonschema | 93.9 | 223.5 | **2.4×** |
|
|
296
|
+
| systems: CodeBLEU n-gram terms (1000 programs) | codebleu | 413.8 | 507.8 | **1.2×** |
|
|
297
|
+
| systems: confidence AUROC (n answers) | scikit-learn | 154.1 | 251.8 | **1.6×** |
|
|
298
|
+
| systems: distribution-shift drop, Welch CI (n scores) | SciPy | 10.9 | 12.9 | **1.2×** |
|
|
299
|
+
| systems: invalid tool calls vs JSON Schema (10000 tasks) | jsonschema | 78.4 | 213.2 | **2.7×** |
|
|
300
|
+
| systems: latency p50 / p95 / p99 (n requests) | NumPy | 18.0 | 15.9 | 0.88× |
|
|
301
|
+
| systems: maintainability index (1000 programs) | radon | 89.3 | 96.0 | **1.1×** |
|
|
302
|
+
| text: corpus BLEU and chrF (10000 sentences) | sacreBLEU | 1728.8 | 1993.1 | **1.2×** |
|
|
303
|
+
| text: METEOR, exact and stem matches (10000 sentences) | NLTK | 319.1 | 358.6 | **1.1×** |
|
|
304
|
+
| text: ROUGE-1, ROUGE-2, ROUGE-L (10000 sentences) | rouge-score | 716.0 | 612.5 | 0.86× |
|
|
305
305
|
|
|
306
306
|
**Every metric is benchmarked too** (`evalsuite benchmark --suite metrics`): all 225 registered metrics and
|
|
307
307
|
statistics functions at 10,000 and 100,000 samples. 86 are compared with a reference library, 118 with an
|
|
308
308
|
independent textbook formula and 21 (learned, judge-dependent or randomised) are timed alone; **all 204
|
|
309
|
-
comparisons agree**, and against the libraries the geometric-mean speed-up is **2.
|
|
309
|
+
comparisons agree**, and against the libraries the geometric-mean speed-up is **2.80×** (138 of 172
|
|
310
310
|
measurements faster). Per-metric table in BENCHMARKS.md.
|
|
311
311
|
|
|
312
312
|
`evaluate()` validates inputs once and builds the confusion matrix once for all metrics, which is where most
|
|
313
|
-
of the speed-up comes from.
|
|
313
|
+
of the speed-up comes from. The t-tests compute their statistics in one pass and beat SciPy; other hypothesis tests use SciPy underneath. Rows
|
|
314
314
|
below 1× pay for input validation and the extra intervals and effect sizes EvalSuite reports. Reproduce on
|
|
315
315
|
your machine with `evalsuite benchmark`; full table (1k, 100k and 1M samples, peak memory) and notes in
|
|
316
316
|
[BENCHMARKS.md](https://github.com/mkcs28/evalsuite-python/blob/main/BENCHMARKS.md).
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"""Deferred imports for heavy optional-at-import-time dependencies (SciPy submodules).
|
|
2
|
+
|
|
3
|
+
``import evalsuite`` should not pay for SciPy until a function that needs it runs.
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
from __future__ import annotations
|
|
7
|
+
|
|
8
|
+
import importlib
|
|
9
|
+
from types import ModuleType
|
|
10
|
+
from typing import Any
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class LazyModule(ModuleType):
|
|
14
|
+
"""Module proxy that imports the real module on first attribute access."""
|
|
15
|
+
|
|
16
|
+
def __init__(self, name: str) -> None:
|
|
17
|
+
super().__init__(name)
|
|
18
|
+
self.__dict__["_mod"] = None
|
|
19
|
+
|
|
20
|
+
def _load(self) -> ModuleType:
|
|
21
|
+
mod = self.__dict__["_mod"]
|
|
22
|
+
if mod is None:
|
|
23
|
+
mod = importlib.import_module(self.__name__)
|
|
24
|
+
self.__dict__["_mod"] = mod
|
|
25
|
+
return mod # type: ignore[no-any-return]
|
|
26
|
+
|
|
27
|
+
def __getattr__(self, attr: str) -> Any:
|
|
28
|
+
return getattr(self._load(), attr)
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def lazy_module(name: str) -> Any:
|
|
32
|
+
return LazyModule(name)
|
|
@@ -63,7 +63,8 @@ def _classification_registry(
|
|
|
63
63
|
|
|
64
64
|
def _hamming(ctx: ClassificationContext) -> MetricResult:
|
|
65
65
|
if ctx.target_type == "multilabel":
|
|
66
|
-
|
|
66
|
+
if ctx.y_pred is None:
|
|
67
|
+
raise InputValidationError("y_pred is required for this metric.")
|
|
67
68
|
wrong = (ctx.y_true != ctx.y_pred).mean(axis=1)
|
|
68
69
|
else:
|
|
69
70
|
wrong = (ctx.true_idx != ctx.pred_idx).astype(float)
|
|
@@ -14,7 +14,13 @@ from typing import TYPE_CHECKING, Any, Literal, Optional, cast
|
|
|
14
14
|
|
|
15
15
|
import numpy as np
|
|
16
16
|
from numpy.typing import NDArray
|
|
17
|
-
|
|
17
|
+
|
|
18
|
+
if TYPE_CHECKING:
|
|
19
|
+
from scipy import stats
|
|
20
|
+
else:
|
|
21
|
+
from ._lazy import lazy_module
|
|
22
|
+
|
|
23
|
+
stats = lazy_module("scipy.stats")
|
|
18
24
|
|
|
19
25
|
from .classification.metrics import (
|
|
20
26
|
_binary_target,
|
|
@@ -109,7 +109,8 @@ def accuracy(y_true: ArrayLike, y_pred: ArrayLike, *, sample_weight: Optional[Ar
|
|
|
109
109
|
|
|
110
110
|
def _accuracy(ctx: ClassificationContext) -> MetricResult:
|
|
111
111
|
if ctx.target_type == "multilabel":
|
|
112
|
-
|
|
112
|
+
if ctx.y_pred is None:
|
|
113
|
+
raise InputValidationError("y_pred is required for this metric.")
|
|
113
114
|
correct = (ctx.y_true == ctx.y_pred).all(axis=1)
|
|
114
115
|
else:
|
|
115
116
|
correct = ctx.true_idx == ctx.pred_idx
|
|
@@ -491,7 +492,8 @@ def hamming_loss(
|
|
|
491
492
|
"""Hamming loss."""
|
|
492
493
|
ctx = _ctx(y_true, y_pred, sample_weight=sample_weight)
|
|
493
494
|
if ctx.target_type == "multilabel":
|
|
494
|
-
|
|
495
|
+
if ctx.y_pred is None:
|
|
496
|
+
raise InputValidationError("y_pred is required for this metric.")
|
|
495
497
|
wrong = (ctx.y_true != ctx.y_pred).mean(axis=1)
|
|
496
498
|
else:
|
|
497
499
|
wrong = (ctx.true_idx != ctx.pred_idx).astype(float)
|
|
@@ -10,7 +10,13 @@ from typing import TYPE_CHECKING, Any, Optional, cast
|
|
|
10
10
|
|
|
11
11
|
import numpy as np
|
|
12
12
|
from numpy.typing import NDArray
|
|
13
|
-
|
|
13
|
+
|
|
14
|
+
if TYPE_CHECKING:
|
|
15
|
+
from scipy import special
|
|
16
|
+
else:
|
|
17
|
+
from .._lazy import lazy_module
|
|
18
|
+
|
|
19
|
+
special = lazy_module("scipy.special")
|
|
14
20
|
|
|
15
21
|
from ..core.exceptions import InputValidationError
|
|
16
22
|
from ..core.export import PathLike, csv_text, html_document, html_table, save_as
|
|
@@ -113,19 +113,38 @@ def by_group(values: np.ndarray, groups: Optional[Sequence[Any]], name: str = "g
|
|
|
113
113
|
return out
|
|
114
114
|
|
|
115
115
|
|
|
116
|
-
def
|
|
117
|
-
"""
|
|
118
|
-
|
|
119
|
-
|
|
116
|
+
def quantiles(a: np.ndarray, qs: Sequence[float]) -> list[float]:
|
|
117
|
+
"""Percentiles ``qs`` (0-100, linear interpolation, identical to ``np.percentile``) from one partition."""
|
|
118
|
+
n = a.size
|
|
119
|
+
pos = [(n - 1) * q / 100.0 for q in qs]
|
|
120
|
+
lo = [int(np.floor(h)) for h in pos]
|
|
121
|
+
kth = sorted({k for i in lo for k in (i, min(i + 1, n - 1))})
|
|
122
|
+
part = np.partition(a, kth)
|
|
123
|
+
out = []
|
|
124
|
+
for h, i in zip(pos, lo):
|
|
125
|
+
v0, v1 = float(part[i]), float(part[min(i + 1, n - 1)])
|
|
126
|
+
out.append(v0 + (h - i) * (v1 - v0))
|
|
127
|
+
return out
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
def summary(a: np.ndarray, extra: Sequence[float] = ()) -> dict[str, float]:
|
|
131
|
+
"""Mean, standard deviation, min, max and the p50/p90/p95/p99 percentiles (linear interpolation), plus any
|
|
132
|
+
``extra`` percentiles under keys ``p<q>``; all order statistics come from one partition."""
|
|
133
|
+
qs = [0.0, 50.0, 90.0, 95.0, 99.0, 100.0, *extra]
|
|
134
|
+
v = quantiles(a, qs)
|
|
135
|
+
out = {
|
|
120
136
|
"mean": float(a.mean()),
|
|
121
137
|
"std": float(a.std(ddof=1)) if a.size > 1 else 0.0,
|
|
122
|
-
"min":
|
|
123
|
-
"max":
|
|
124
|
-
"p50":
|
|
125
|
-
"p90":
|
|
126
|
-
"p95":
|
|
127
|
-
"p99":
|
|
138
|
+
"min": v[0],
|
|
139
|
+
"max": v[5],
|
|
140
|
+
"p50": v[1],
|
|
141
|
+
"p90": v[2],
|
|
142
|
+
"p95": v[3],
|
|
143
|
+
"p99": v[4],
|
|
128
144
|
}
|
|
145
|
+
for q, val in zip(extra, v[6:]):
|
|
146
|
+
out[f"p{q:g}"] = val
|
|
147
|
+
return out
|
|
129
148
|
|
|
130
149
|
|
|
131
150
|
def lists_of(x: Any, name: str) -> list[list[Any]]:
|
|
@@ -40,6 +40,10 @@ __all__ = [
|
|
|
40
40
|
]
|
|
41
41
|
|
|
42
42
|
_C = "code"
|
|
43
|
+
|
|
44
|
+
# Errors CPython raises for source it cannot parse: syntax errors, null bytes (ValueError), and input nested
|
|
45
|
+
# too deeply for the parser (MemoryError "parser stack overflowed") or for the compiler (RecursionError).
|
|
46
|
+
_PARSE_ERRORS = (SyntaxError, ValueError, MemoryError, RecursionError)
|
|
43
47
|
_REF_HUMANEVAL = (
|
|
44
48
|
"Chen M, Tworek J, Jun H, et al. Evaluating large language models trained on code. arXiv:2107.03374. 2021."
|
|
45
49
|
)
|
|
@@ -141,7 +145,7 @@ def syntax_validity_rate(
|
|
|
141
145
|
with warnings.catch_warnings():
|
|
142
146
|
warnings.simplefilter("ignore", SyntaxWarning)
|
|
143
147
|
compile(src, "<generated>", "exec", dont_inherit=True) # parses only; nothing runs
|
|
144
|
-
except
|
|
148
|
+
except _PARSE_ERRORS:
|
|
145
149
|
return False
|
|
146
150
|
return True
|
|
147
151
|
|
|
@@ -562,12 +566,16 @@ def code_complexity(code: Any) -> MetricResult:
|
|
|
562
566
|
with warnings.catch_warnings():
|
|
563
567
|
warnings.simplefilter("ignore", SyntaxWarning)
|
|
564
568
|
tree = ast.parse(src)
|
|
569
|
+
visitor = _Complexity.run(tree)
|
|
570
|
+
v = _halstead_volume(tree)
|
|
565
571
|
except SyntaxError as exc:
|
|
566
572
|
raise InputValidationError(f"code[{i}] is not valid Python: {exc.msg} (line {exc.lineno}).") from exc
|
|
567
|
-
|
|
573
|
+
except _PARSE_ERRORS as exc:
|
|
574
|
+
raise InputValidationError(
|
|
575
|
+
f"code[{i}] is too deeply nested to analyse ({type(exc).__name__})."
|
|
576
|
+
) from exc
|
|
568
577
|
blocks = visitor.blocks
|
|
569
578
|
funcs += [c for _, c in blocks]
|
|
570
|
-
v = _halstead_volume(tree)
|
|
571
579
|
g = visitor.total
|
|
572
580
|
lloc, sloc, comments = _raw(src)
|
|
573
581
|
c_pct = comments / sloc * 100 if sloc else 0.0
|
|
@@ -720,38 +728,38 @@ def _parse(src: str) -> Optional[ast.AST]:
|
|
|
720
728
|
with warnings.catch_warnings():
|
|
721
729
|
warnings.simplefilter("ignore", SyntaxWarning)
|
|
722
730
|
return ast.parse(_strip(src))
|
|
723
|
-
except
|
|
731
|
+
except _PARSE_ERRORS:
|
|
724
732
|
return None
|
|
725
733
|
|
|
726
734
|
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
]
|
|
735
|
+
_SKIP_NODES = (ast.expr_context, ast.operator, ast.unaryop, ast.boolop, ast.cmpop)
|
|
736
|
+
|
|
737
|
+
|
|
738
|
+
def _kids(node: ast.AST) -> list[ast.AST]:
|
|
739
|
+
return [c for c in ast.iter_child_nodes(node) if not isinstance(c, _SKIP_NODES)]
|
|
740
|
+
|
|
741
|
+
|
|
742
|
+
def _subtrees(tree: ast.AST, table: dict[tuple[Any, ...], int]) -> list[int]:
|
|
743
|
+
"""Every subtree with children (and the root), as ids that are equal exactly when the subtrees are
|
|
744
|
+
structurally equal. Built bottom-up without recursion: ``table`` interns (node type, child ids), so the
|
|
745
|
+
cost is linear in the tree size (comparing serialised subtrees would be quadratic)."""
|
|
746
|
+
ids: dict[int, int] = {}
|
|
747
|
+
out: list[int] = []
|
|
748
|
+
stack: list[tuple[ast.AST, bool]] = [(tree, False)]
|
|
749
|
+
while stack:
|
|
750
|
+
node, ready = stack.pop()
|
|
751
|
+
kids = _kids(node)
|
|
752
|
+
if not ready:
|
|
753
|
+
stack.append((node, True))
|
|
754
|
+
stack.extend((k, False) for k in kids)
|
|
755
|
+
continue
|
|
756
|
+
tag = type(node).__name__
|
|
757
|
+
if isinstance(node, (ast.BinOp, ast.UnaryOp, ast.BoolOp, ast.AugAssign)):
|
|
758
|
+
tag += ":" + type(node.op).__name__
|
|
759
|
+
sid = table.setdefault((tag, tuple(ids[id(k)] for k in kids)), len(table))
|
|
760
|
+
ids[id(node)] = sid
|
|
753
761
|
if kids or node is tree:
|
|
754
|
-
out.append(
|
|
762
|
+
out.append(sid)
|
|
755
763
|
return out
|
|
756
764
|
|
|
757
765
|
|
|
@@ -878,15 +886,16 @@ def codebleu(
|
|
|
878
886
|
ngram = _corpus_bleu(t_refs, t_hyps, None)
|
|
879
887
|
weighted = _corpus_bleu(t_refs, t_hyps, kw)
|
|
880
888
|
match = total = df_match = df_total = 0
|
|
889
|
+
table: dict[tuple[Any, ...], int] = {}
|
|
881
890
|
for rs, p in zip(refs, preds):
|
|
882
891
|
cand = _parse(p)
|
|
883
|
-
cand_sub = set(_subtrees(cand)) if cand is not None else set()
|
|
892
|
+
cand_sub = set(_subtrees(cand, table)) if cand is not None else set()
|
|
884
893
|
cand_flow = _normalize_flow(_dataflow(cand)) if cand is not None else []
|
|
885
894
|
for r in rs:
|
|
886
895
|
ref = _parse(r)
|
|
887
896
|
if ref is None:
|
|
888
897
|
continue
|
|
889
|
-
ref_sub = _subtrees(ref)
|
|
898
|
+
ref_sub = _subtrees(ref, table)
|
|
890
899
|
match += sum(s in cand_sub for s in ref_sub)
|
|
891
900
|
total += len(ref_sub)
|
|
892
901
|
ref_flow = _normalize_flow(_dataflow(ref))
|
|
@@ -119,10 +119,9 @@ def latency_percentiles(latencies: Any, *, unit: str = "s", percentile: float =
|
|
|
119
119
|
x = floats(latencies, "latencies", lo=0)
|
|
120
120
|
if not 0 <= percentile <= 100:
|
|
121
121
|
raise InputValidationError("percentile must be in [0, 100].")
|
|
122
|
-
s = summary(x)
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
)
|
|
122
|
+
s = summary(x, extra=(percentile,))
|
|
123
|
+
value = s[f"p{percentile:g}"]
|
|
124
|
+
return MetricResult("latency_percentiles", f"p{percentile:g} latency", value, {"unit": unit, **s})
|
|
126
125
|
|
|
127
126
|
|
|
128
127
|
@register(
|
|
@@ -362,7 +362,7 @@ def _luhn(digits: str) -> bool:
|
|
|
362
362
|
|
|
363
363
|
|
|
364
364
|
PII_PATTERNS: dict[str, str] = {
|
|
365
|
-
"email": r"[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}",
|
|
365
|
+
"email": r"(?<![A-Za-z0-9._%+-])[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}",
|
|
366
366
|
"phone": r"(?<!\d[\s.-])(?<!\w)(?:\+?\d{1,3}[\s.-]?)?(?:\(\d{2,4}\)[\s.-]?)?\d{3,4}[\s.-]\d{3,4}"
|
|
367
367
|
r"(?:[\s.-]\d{2,4})?(?![\s.-]?\d)(?!\w)",
|
|
368
368
|
"credit_card": r"(?<!\d)\d(?:[ -]?\d){12,18}(?!\d)",
|
|
@@ -2,11 +2,17 @@
|
|
|
2
2
|
|
|
3
3
|
from __future__ import annotations
|
|
4
4
|
|
|
5
|
-
from typing import Literal
|
|
5
|
+
from typing import TYPE_CHECKING, Literal
|
|
6
6
|
|
|
7
7
|
import numpy as np
|
|
8
8
|
from numpy.typing import NDArray
|
|
9
|
-
|
|
9
|
+
|
|
10
|
+
if TYPE_CHECKING:
|
|
11
|
+
from scipy import special
|
|
12
|
+
else:
|
|
13
|
+
from .._lazy import lazy_module
|
|
14
|
+
|
|
15
|
+
special = lazy_module("scipy.special")
|
|
10
16
|
|
|
11
17
|
from ..core.exceptions import InputValidationError, StatisticalTestError
|
|
12
18
|
from ..core.types import ArrayLike
|
|
@@ -8,11 +8,18 @@ implementations are the reference; EvalSuite adds input validation, effect sizes
|
|
|
8
8
|
from __future__ import annotations
|
|
9
9
|
|
|
10
10
|
import math
|
|
11
|
-
from typing import Literal
|
|
11
|
+
from typing import TYPE_CHECKING, Literal
|
|
12
12
|
|
|
13
13
|
import numpy as np
|
|
14
14
|
from numpy.typing import NDArray
|
|
15
|
-
|
|
15
|
+
|
|
16
|
+
if TYPE_CHECKING:
|
|
17
|
+
from scipy import special, stats
|
|
18
|
+
else:
|
|
19
|
+
from .._lazy import lazy_module
|
|
20
|
+
|
|
21
|
+
special = lazy_module("scipy.special")
|
|
22
|
+
stats = lazy_module("scipy.stats")
|
|
16
23
|
|
|
17
24
|
from ..core.exceptions import InputValidationError, StatisticalTestError
|
|
18
25
|
from ..core.types import ArrayLike
|
|
@@ -37,7 +44,7 @@ _ALTS = ("two-sided", "greater", "less")
|
|
|
37
44
|
|
|
38
45
|
|
|
39
46
|
def _vec(x: ArrayLike, name: str, min_n: int = 2) -> NDArray[np.float64]:
|
|
40
|
-
a = to_numpy(x, name).astype(np.float64)
|
|
47
|
+
a = to_numpy(x, name).astype(np.float64, copy=False)
|
|
41
48
|
check_finite(a, name)
|
|
42
49
|
if a.ndim != 1:
|
|
43
50
|
raise InputValidationError(f"{name} must be one-dimensional.")
|
|
@@ -80,12 +87,15 @@ def t_test(
|
|
|
80
87
|
References: Welch BL. Biometrika. 1947;34(1-2):28-35. Student. Biometrika. 1908;6(1):1-25.
|
|
81
88
|
"""
|
|
82
89
|
level = _check_level(level)
|
|
90
|
+
_alt(alternative)
|
|
83
91
|
x, y = _vec(a, "a"), _vec(b, "b")
|
|
84
|
-
if x.var() == 0 and y.var() == 0:
|
|
85
|
-
raise StatisticalTestError("The t-test is undefined: both samples have zero variance.")
|
|
86
|
-
res = stats.ttest_ind(x, y, equal_var=equal_var, alternative=_alt(alternative))
|
|
87
92
|
n1, n2 = x.shape[0], y.shape[0]
|
|
88
|
-
|
|
93
|
+
m1, m2 = float(x.mean()), float(y.mean())
|
|
94
|
+
# Two-pass variances (as NumPy/SciPy compute them), each sample read once more.
|
|
95
|
+
v1 = float(np.dot(x - m1, x - m1)) / (n1 - 1)
|
|
96
|
+
v2 = float(np.dot(y - m2, y - m2)) / (n2 - 1)
|
|
97
|
+
if v1 == 0 and v2 == 0:
|
|
98
|
+
raise StatisticalTestError("The t-test is undefined: both samples have zero variance.")
|
|
89
99
|
if equal_var:
|
|
90
100
|
df = n1 + n2 - 2
|
|
91
101
|
sp2 = ((n1 - 1) * v1 + (n2 - 1) * v2) / df
|
|
@@ -93,12 +103,21 @@ def t_test(
|
|
|
93
103
|
else:
|
|
94
104
|
se = math.sqrt(v1 / n1 + v2 / n2)
|
|
95
105
|
df = (v1 / n1 + v2 / n2) ** 2 / ((v1 / n1) ** 2 / (n1 - 1) + (v2 / n2) ** 2 / (n2 - 1)) if se else math.nan
|
|
96
|
-
|
|
106
|
+
t = (m1 - m2) / se
|
|
107
|
+
# Student-t tail probabilities directly (what scipy.stats.ttest_ind returns), without re-reading the data.
|
|
108
|
+
if alternative == "two-sided":
|
|
109
|
+
p = 2.0 * float(special.stdtr(df, -abs(t)))
|
|
110
|
+
elif alternative == "less":
|
|
111
|
+
p = float(special.stdtr(df, t))
|
|
112
|
+
else:
|
|
113
|
+
p = float(special.stdtr(df, -t))
|
|
114
|
+
p = min(p, 1.0)
|
|
115
|
+
diff = m1 - m2
|
|
97
116
|
pooled = math.sqrt(((n1 - 1) * v1 + (n2 - 1) * v2) / (n1 + n2 - 2))
|
|
98
117
|
return TestResult(
|
|
99
118
|
"welch-t" if not equal_var else "student-t",
|
|
100
|
-
float(
|
|
101
|
-
|
|
119
|
+
float(t),
|
|
120
|
+
p,
|
|
102
121
|
alternative=alternative,
|
|
103
122
|
estimate=diff,
|
|
104
123
|
ci=_mean_diff_ci(diff, se, df, level, alternative, "mean_difference"),
|
|
@@ -3,11 +3,18 @@
|
|
|
3
3
|
from __future__ import annotations
|
|
4
4
|
|
|
5
5
|
import warnings
|
|
6
|
-
from typing import Any, Literal, Optional
|
|
6
|
+
from typing import TYPE_CHECKING, Any, Literal, Optional
|
|
7
7
|
|
|
8
8
|
import numpy as np
|
|
9
9
|
from numpy.typing import NDArray
|
|
10
|
-
|
|
10
|
+
|
|
11
|
+
if TYPE_CHECKING:
|
|
12
|
+
from scipy import special, stats
|
|
13
|
+
else:
|
|
14
|
+
from .._lazy import lazy_module
|
|
15
|
+
|
|
16
|
+
special = lazy_module("scipy.special")
|
|
17
|
+
stats = lazy_module("scipy.stats")
|
|
11
18
|
|
|
12
19
|
from ..core.exceptions import EvalSuiteError, InputValidationError, StatisticalTestError
|
|
13
20
|
from ..core.types import ArrayLike
|
|
@@ -2,10 +2,17 @@
|
|
|
2
2
|
|
|
3
3
|
from __future__ import annotations
|
|
4
4
|
|
|
5
|
-
from typing import Any, Literal, Optional
|
|
5
|
+
from typing import TYPE_CHECKING, Any, Literal, Optional
|
|
6
6
|
|
|
7
7
|
import numpy as np
|
|
8
|
-
|
|
8
|
+
|
|
9
|
+
if TYPE_CHECKING:
|
|
10
|
+
from scipy import special, stats
|
|
11
|
+
else:
|
|
12
|
+
from .._lazy import lazy_module
|
|
13
|
+
|
|
14
|
+
special = lazy_module("scipy.special")
|
|
15
|
+
stats = lazy_module("scipy.stats")
|
|
9
16
|
|
|
10
17
|
from ..core.exceptions import InputValidationError
|
|
11
18
|
from ..core.types import ArrayLike
|
|
@@ -9,10 +9,16 @@ from __future__ import annotations
|
|
|
9
9
|
|
|
10
10
|
import math
|
|
11
11
|
from collections.abc import Sequence
|
|
12
|
-
from typing import Any, Optional
|
|
12
|
+
from typing import TYPE_CHECKING, Any, Optional
|
|
13
13
|
|
|
14
14
|
import numpy as np
|
|
15
|
-
|
|
15
|
+
|
|
16
|
+
if TYPE_CHECKING:
|
|
17
|
+
from scipy import stats
|
|
18
|
+
else:
|
|
19
|
+
from .._lazy import lazy_module
|
|
20
|
+
|
|
21
|
+
stats = lazy_module("scipy.stats")
|
|
16
22
|
|
|
17
23
|
from ..core.exceptions import InputValidationError
|
|
18
24
|
from ..core.registry import register
|
|
@@ -712,7 +712,11 @@ def constraint_satisfaction_rate(checks: Any) -> MetricResult:
|
|
|
712
712
|
def format_compliance(
|
|
713
713
|
outputs: Any, pattern: str, *, flags: int = re.S, average: Optional[str] = "mean"
|
|
714
714
|
) -> MetricResult:
|
|
715
|
-
"""``re.fullmatch(pattern, output.strip())`` per output.
|
|
715
|
+
"""``re.fullmatch(pattern, output.strip())`` per output.
|
|
716
|
+
|
|
717
|
+
The pattern is compiled with Python's backtracking ``re`` engine; patterns with nested quantifiers such as
|
|
718
|
+
``(a+)+$`` can take exponential time on some outputs, so only pass patterns you trust.
|
|
719
|
+
"""
|
|
716
720
|
outs = _outputs(outputs)
|
|
717
721
|
try:
|
|
718
722
|
rx = re.compile(pattern, flags)
|
|
@@ -27,7 +27,13 @@ from typing import TYPE_CHECKING, Any, Literal, Optional, Union, cast
|
|
|
27
27
|
|
|
28
28
|
import numpy as np
|
|
29
29
|
from numpy.typing import NDArray
|
|
30
|
-
|
|
30
|
+
|
|
31
|
+
if TYPE_CHECKING:
|
|
32
|
+
from scipy import ndimage
|
|
33
|
+
else:
|
|
34
|
+
from .._lazy import lazy_module
|
|
35
|
+
|
|
36
|
+
ndimage = lazy_module("scipy.ndimage")
|
|
31
37
|
|
|
32
38
|
from ..core.exceptions import InputValidationError, UndefinedMetricWarning
|
|
33
39
|
from ..core.export import PathLike, csv_text, html_document, html_table, save_as
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"""Regression tests for adversarial inputs (parser exhaustion, regex backtracking) and lazy imports."""
|
|
2
|
+
|
|
3
|
+
import subprocess
|
|
4
|
+
import sys
|
|
5
|
+
import time
|
|
6
|
+
|
|
7
|
+
import pytest
|
|
8
|
+
|
|
9
|
+
import evalsuite as es
|
|
10
|
+
from evalsuite.core.exceptions import InputValidationError
|
|
11
|
+
|
|
12
|
+
DEEP = "x=" + "-" * 100_000 + "1"
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def test_syntax_validity_survives_parser_stack_overflow():
|
|
16
|
+
assert float(es.syntax_validity_rate([DEEP, "x = 1"])) == 0.5
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
@pytest.mark.parametrize("src", [DEEP, "x=" + "-" * 900 + "1"])
|
|
20
|
+
def test_code_complexity_rejects_too_deep_code_cleanly(src):
|
|
21
|
+
with pytest.raises(InputValidationError, match=r"too deeply nested|not valid Python"):
|
|
22
|
+
es.code_complexity([src])
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def test_codebleu_deep_input_does_not_crash():
|
|
26
|
+
r = es.codebleu([DEEP], [DEEP])
|
|
27
|
+
assert 0.0 <= float(r) <= 1.0
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def test_codebleu_large_program_is_fast():
|
|
31
|
+
src = "\n".join(f"def f{i}(a, b):\n return [x * b for x in range(a + {i})]\n" for i in range(2000))
|
|
32
|
+
start = time.perf_counter()
|
|
33
|
+
es.codebleu([src], [src])
|
|
34
|
+
assert time.perf_counter() - start < 5
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
@pytest.mark.parametrize("text", ["1-" * 30_000, "a" * 30_000 + "@" + "b." * 10_000, "a." * 30_000, "a@" * 30_000])
|
|
38
|
+
def test_detect_pii_is_linear_on_adversarial_text(text):
|
|
39
|
+
start = time.perf_counter()
|
|
40
|
+
es.detect_pii(text)
|
|
41
|
+
assert time.perf_counter() - start < 1
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def test_detect_pii_still_finds_emails():
|
|
45
|
+
found = es.detect_pii("write to a.b@x.org or c@d.co.uk")
|
|
46
|
+
assert found["email"] == ["a.b@x.org", "c@d.co.uk"]
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def test_import_does_not_load_scipy():
|
|
50
|
+
code = "import sys, evalsuite; print('scipy' in sys.modules)"
|
|
51
|
+
out = subprocess.run([sys.executable, "-c", code], capture_output=True, text=True, check=True) # noqa: S603
|
|
52
|
+
assert out.stdout.strip() == "False"
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"""The one-pass t-test and single-partition percentiles must equal SciPy / NumPy exactly."""
|
|
2
|
+
|
|
3
|
+
import numpy as np
|
|
4
|
+
import pytest
|
|
5
|
+
from scipy import stats
|
|
6
|
+
|
|
7
|
+
import evalsuite as es
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
@pytest.mark.parametrize("equal_var", [False, True])
|
|
11
|
+
@pytest.mark.parametrize("alternative", ["two-sided", "less", "greater"])
|
|
12
|
+
@pytest.mark.parametrize(("n1", "n2", "shift"), [(2, 2, 0.0), (3, 30, 0.4), (500, 400, -0.1), (50, 60, 30.0)])
|
|
13
|
+
def test_t_test_matches_scipy(equal_var, alternative, n1, n2, shift):
|
|
14
|
+
rng = np.random.default_rng(n1 + n2)
|
|
15
|
+
a, b = rng.normal(0, 1, n1), rng.normal(shift, 2.0, n2)
|
|
16
|
+
got = es.t_test(a, b, equal_var=equal_var, alternative=alternative)
|
|
17
|
+
ref = stats.ttest_ind(a, b, equal_var=equal_var, alternative=alternative)
|
|
18
|
+
assert got.statistic == pytest.approx(ref.statistic, rel=1e-12)
|
|
19
|
+
assert got.p_value == pytest.approx(ref.pvalue, rel=1e-9, abs=1e-15)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
@pytest.mark.parametrize("n", [1, 2, 3, 10, 1001])
|
|
23
|
+
@pytest.mark.parametrize("q", [0, 12.5, 50, 95, 99.9, 100])
|
|
24
|
+
def test_latency_percentiles_match_numpy(n, q):
|
|
25
|
+
x = np.random.default_rng(n).lognormal(0, 0.5, n)
|
|
26
|
+
r = es.latency_percentiles(x, percentile=q)
|
|
27
|
+
assert float(r) == pytest.approx(np.percentile(x, q), rel=1e-12)
|
|
28
|
+
for key, p in (("p50", 50), ("p90", 90), ("p95", 95), ("p99", 99)):
|
|
29
|
+
assert r.params[key] == pytest.approx(np.percentile(x, p), rel=1e-12)
|
|
30
|
+
assert r.params["min"] == x.min() and r.params["max"] == x.max()
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{evalsuite_python-0.5.1 → evalsuite_python-0.5.3}/tests/classification/test_against_sklearn.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{evalsuite_python-0.5.1 → evalsuite_python-0.5.3}/tests/llmsys/test_code_longcontext_efficiency.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|