evalsuite-python 0.5.4__tar.gz → 0.5.5__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.
Files changed (113) hide show
  1. {evalsuite_python-0.5.4 → evalsuite_python-0.5.5}/CHANGELOG.md +22 -0
  2. {evalsuite_python-0.5.4 → evalsuite_python-0.5.5}/PKG-INFO +39 -38
  3. {evalsuite_python-0.5.4 → evalsuite_python-0.5.5}/README.md +38 -37
  4. {evalsuite_python-0.5.4 → evalsuite_python-0.5.5}/src/evalsuite/llmsys/_common.py +54 -7
  5. {evalsuite_python-0.5.4 → evalsuite_python-0.5.5}/src/evalsuite/stats/hypothesis.py +89 -4
  6. {evalsuite_python-0.5.4 → evalsuite_python-0.5.5}/src/evalsuite/text/generation.py +10 -2
  7. {evalsuite_python-0.5.4 → evalsuite_python-0.5.5}/src/evalsuite/text/judge.py +4 -4
  8. {evalsuite_python-0.5.4 → evalsuite_python-0.5.5}/src/evalsuite/text/semantic.py +19 -5
  9. {evalsuite_python-0.5.4 → evalsuite_python-0.5.5}/src/evalsuite/version.py +1 -1
  10. {evalsuite_python-0.5.4 → evalsuite_python-0.5.5}/src/evalsuite/vision/detection.py +60 -35
  11. {evalsuite_python-0.5.4 → evalsuite_python-0.5.5}/src/evalsuite/vision/segmentation.py +39 -10
  12. {evalsuite_python-0.5.4 → evalsuite_python-0.5.5}/tests/llmsys/test_fast_text.py +39 -0
  13. {evalsuite_python-0.5.4 → evalsuite_python-0.5.5}/tests/stats/test_fast_paths.py +40 -0
  14. {evalsuite_python-0.5.4 → evalsuite_python-0.5.5}/.gitignore +0 -0
  15. {evalsuite_python-0.5.4 → evalsuite_python-0.5.5}/CONTRIBUTING.md +0 -0
  16. {evalsuite_python-0.5.4 → evalsuite_python-0.5.5}/LICENSE +0 -0
  17. {evalsuite_python-0.5.4 → evalsuite_python-0.5.5}/LICENSE-APACHE +0 -0
  18. {evalsuite_python-0.5.4 → evalsuite_python-0.5.5}/pyproject.toml +0 -0
  19. {evalsuite_python-0.5.4 → evalsuite_python-0.5.5}/src/evalsuite/__init__.py +0 -0
  20. {evalsuite_python-0.5.4 → evalsuite_python-0.5.5}/src/evalsuite/__main__.py +0 -0
  21. {evalsuite_python-0.5.4 → evalsuite_python-0.5.5}/src/evalsuite/_bench_metrics.py +0 -0
  22. {evalsuite_python-0.5.4 → evalsuite_python-0.5.5}/src/evalsuite/_lazy.py +0 -0
  23. {evalsuite_python-0.5.4 → evalsuite_python-0.5.5}/src/evalsuite/api.py +0 -0
  24. {evalsuite_python-0.5.4 → evalsuite_python-0.5.5}/src/evalsuite/benchmarks.py +0 -0
  25. {evalsuite_python-0.5.4 → evalsuite_python-0.5.5}/src/evalsuite/calibration.py +0 -0
  26. {evalsuite_python-0.5.4 → evalsuite_python-0.5.5}/src/evalsuite/classification/__init__.py +0 -0
  27. {evalsuite_python-0.5.4 → evalsuite_python-0.5.5}/src/evalsuite/classification/_common.py +0 -0
  28. {evalsuite_python-0.5.4 → evalsuite_python-0.5.5}/src/evalsuite/classification/metrics.py +0 -0
  29. {evalsuite_python-0.5.4 → evalsuite_python-0.5.5}/src/evalsuite/cli/__init__.py +0 -0
  30. {evalsuite_python-0.5.4 → evalsuite_python-0.5.5}/src/evalsuite/cli/main.py +0 -0
  31. {evalsuite_python-0.5.4 → evalsuite_python-0.5.5}/src/evalsuite/clinical/__init__.py +0 -0
  32. {evalsuite_python-0.5.4 → evalsuite_python-0.5.5}/src/evalsuite/clinical/metrics.py +0 -0
  33. {evalsuite_python-0.5.4 → evalsuite_python-0.5.5}/src/evalsuite/clinical/report.py +0 -0
  34. {evalsuite_python-0.5.4 → evalsuite_python-0.5.5}/src/evalsuite/core/__init__.py +0 -0
  35. {evalsuite_python-0.5.4 → evalsuite_python-0.5.5}/src/evalsuite/core/context.py +0 -0
  36. {evalsuite_python-0.5.4 → evalsuite_python-0.5.5}/src/evalsuite/core/exceptions.py +0 -0
  37. {evalsuite_python-0.5.4 → evalsuite_python-0.5.5}/src/evalsuite/core/export.py +0 -0
  38. {evalsuite_python-0.5.4 → evalsuite_python-0.5.5}/src/evalsuite/core/registry.py +0 -0
  39. {evalsuite_python-0.5.4 → evalsuite_python-0.5.5}/src/evalsuite/core/result.py +0 -0
  40. {evalsuite_python-0.5.4 → evalsuite_python-0.5.5}/src/evalsuite/core/types.py +0 -0
  41. {evalsuite_python-0.5.4 → evalsuite_python-0.5.5}/src/evalsuite/core/validation.py +0 -0
  42. {evalsuite_python-0.5.4 → evalsuite_python-0.5.5}/src/evalsuite/llmsys/__init__.py +0 -0
  43. {evalsuite_python-0.5.4 → evalsuite_python-0.5.5}/src/evalsuite/llmsys/agents.py +0 -0
  44. {evalsuite_python-0.5.4 → evalsuite_python-0.5.5}/src/evalsuite/llmsys/code.py +0 -0
  45. {evalsuite_python-0.5.4 → evalsuite_python-0.5.5}/src/evalsuite/llmsys/efficiency.py +0 -0
  46. {evalsuite_python-0.5.4 → evalsuite_python-0.5.5}/src/evalsuite/llmsys/longcontext.py +0 -0
  47. {evalsuite_python-0.5.4 → evalsuite_python-0.5.5}/src/evalsuite/llmsys/multilingual.py +0 -0
  48. {evalsuite_python-0.5.4 → evalsuite_python-0.5.5}/src/evalsuite/llmsys/robustness.py +0 -0
  49. {evalsuite_python-0.5.4 → evalsuite_python-0.5.5}/src/evalsuite/llmsys/safety.py +0 -0
  50. {evalsuite_python-0.5.4 → evalsuite_python-0.5.5}/src/evalsuite/llmsys/uncertainty.py +0 -0
  51. {evalsuite_python-0.5.4 → evalsuite_python-0.5.5}/src/evalsuite/plot.py +0 -0
  52. {evalsuite_python-0.5.4 → evalsuite_python-0.5.5}/src/evalsuite/py.typed +0 -0
  53. {evalsuite_python-0.5.4 → evalsuite_python-0.5.5}/src/evalsuite/regression/__init__.py +0 -0
  54. {evalsuite_python-0.5.4 → evalsuite_python-0.5.5}/src/evalsuite/regression/metrics.py +0 -0
  55. {evalsuite_python-0.5.4 → evalsuite_python-0.5.5}/src/evalsuite/reporting.py +0 -0
  56. {evalsuite_python-0.5.4 → evalsuite_python-0.5.5}/src/evalsuite/stats/__init__.py +0 -0
  57. {evalsuite_python-0.5.4 → evalsuite_python-0.5.5}/src/evalsuite/stats/_resolve.py +0 -0
  58. {evalsuite_python-0.5.4 → evalsuite_python-0.5.5}/src/evalsuite/stats/compare.py +0 -0
  59. {evalsuite_python-0.5.4 → evalsuite_python-0.5.5}/src/evalsuite/stats/effect.py +0 -0
  60. {evalsuite_python-0.5.4 → evalsuite_python-0.5.5}/src/evalsuite/stats/intervals.py +0 -0
  61. {evalsuite_python-0.5.4 → evalsuite_python-0.5.5}/src/evalsuite/stats/paired.py +0 -0
  62. {evalsuite_python-0.5.4 → evalsuite_python-0.5.5}/src/evalsuite/stats/results.py +0 -0
  63. {evalsuite_python-0.5.4 → evalsuite_python-0.5.5}/src/evalsuite/text/__init__.py +0 -0
  64. {evalsuite_python-0.5.4 → evalsuite_python-0.5.5}/src/evalsuite/text/_common.py +0 -0
  65. {evalsuite_python-0.5.4 → evalsuite_python-0.5.5}/src/evalsuite/text/factuality.py +0 -0
  66. {evalsuite_python-0.5.4 → evalsuite_python-0.5.5}/src/evalsuite/text/qa.py +0 -0
  67. {evalsuite_python-0.5.4 → evalsuite_python-0.5.5}/src/evalsuite/text/rag.py +0 -0
  68. {evalsuite_python-0.5.4 → evalsuite_python-0.5.5}/src/evalsuite/text/reasoning.py +0 -0
  69. {evalsuite_python-0.5.4 → evalsuite_python-0.5.5}/src/evalsuite/text/report.py +0 -0
  70. {evalsuite_python-0.5.4 → evalsuite_python-0.5.5}/src/evalsuite/text/retrieval.py +0 -0
  71. {evalsuite_python-0.5.4 → evalsuite_python-0.5.5}/src/evalsuite/text/spice.py +0 -0
  72. {evalsuite_python-0.5.4 → evalsuite_python-0.5.5}/src/evalsuite/text/structured.py +0 -0
  73. {evalsuite_python-0.5.4 → evalsuite_python-0.5.5}/src/evalsuite/vision/__init__.py +0 -0
  74. {evalsuite_python-0.5.4 → evalsuite_python-0.5.5}/tests/__init__.py +0 -0
  75. {evalsuite_python-0.5.4 → evalsuite_python-0.5.5}/tests/classification/__init__.py +0 -0
  76. {evalsuite_python-0.5.4 → evalsuite_python-0.5.5}/tests/classification/test_against_sklearn.py +0 -0
  77. {evalsuite_python-0.5.4 → evalsuite_python-0.5.5}/tests/clinical/__init__.py +0 -0
  78. {evalsuite_python-0.5.4 → evalsuite_python-0.5.5}/tests/clinical/test_outputs.py +0 -0
  79. {evalsuite_python-0.5.4 → evalsuite_python-0.5.5}/tests/clinical/test_v020.py +0 -0
  80. {evalsuite_python-0.5.4 → evalsuite_python-0.5.5}/tests/conftest.py +0 -0
  81. {evalsuite_python-0.5.4 → evalsuite_python-0.5.5}/tests/integration/__init__.py +0 -0
  82. {evalsuite_python-0.5.4 → evalsuite_python-0.5.5}/tests/integration/test_qa.py +0 -0
  83. {evalsuite_python-0.5.4 → evalsuite_python-0.5.5}/tests/integration/test_readme_examples.py +0 -0
  84. {evalsuite_python-0.5.4 → evalsuite_python-0.5.5}/tests/integration/test_repo_hygiene.py +0 -0
  85. {evalsuite_python-0.5.4 → evalsuite_python-0.5.5}/tests/llmsys/__init__.py +0 -0
  86. {evalsuite_python-0.5.4 → evalsuite_python-0.5.5}/tests/llmsys/test_code_longcontext_efficiency.py +0 -0
  87. {evalsuite_python-0.5.4 → evalsuite_python-0.5.5}/tests/llmsys/test_edges.py +0 -0
  88. {evalsuite_python-0.5.4 → evalsuite_python-0.5.5}/tests/llmsys/test_hardening.py +0 -0
  89. {evalsuite_python-0.5.4 → evalsuite_python-0.5.5}/tests/llmsys/test_safety_robustness.py +0 -0
  90. {evalsuite_python-0.5.4 → evalsuite_python-0.5.5}/tests/llmsys/test_uncertainty_agents_multilingual.py +0 -0
  91. {evalsuite_python-0.5.4 → evalsuite_python-0.5.5}/tests/output/__init__.py +0 -0
  92. {evalsuite_python-0.5.4 → evalsuite_python-0.5.5}/tests/output/test_benchmarks.py +0 -0
  93. {evalsuite_python-0.5.4 → evalsuite_python-0.5.5}/tests/output/test_cli.py +0 -0
  94. {evalsuite_python-0.5.4 → evalsuite_python-0.5.5}/tests/output/test_plot.py +0 -0
  95. {evalsuite_python-0.5.4 → evalsuite_python-0.5.5}/tests/output/test_reporting.py +0 -0
  96. {evalsuite_python-0.5.4 → evalsuite_python-0.5.5}/tests/regression/__init__.py +0 -0
  97. {evalsuite_python-0.5.4 → evalsuite_python-0.5.5}/tests/regression/test_against_sklearn.py +0 -0
  98. {evalsuite_python-0.5.4 → evalsuite_python-0.5.5}/tests/stats/__init__.py +0 -0
  99. {evalsuite_python-0.5.4 → evalsuite_python-0.5.5}/tests/stats/test_branches.py +0 -0
  100. {evalsuite_python-0.5.4 → evalsuite_python-0.5.5}/tests/stats/test_compare.py +0 -0
  101. {evalsuite_python-0.5.4 → evalsuite_python-0.5.5}/tests/stats/test_reference.py +0 -0
  102. {evalsuite_python-0.5.4 → evalsuite_python-0.5.5}/tests/text/__init__.py +0 -0
  103. {evalsuite_python-0.5.4 → evalsuite_python-0.5.5}/tests/text/test_against_references.py +0 -0
  104. {evalsuite_python-0.5.4 → evalsuite_python-0.5.5}/tests/text/test_text_edges.py +0 -0
  105. {evalsuite_python-0.5.4 → evalsuite_python-0.5.5}/tests/text/test_v040.py +0 -0
  106. {evalsuite_python-0.5.4 → evalsuite_python-0.5.5}/tests/unit/__init__.py +0 -0
  107. {evalsuite_python-0.5.4 → evalsuite_python-0.5.5}/tests/unit/test_core.py +0 -0
  108. {evalsuite_python-0.5.4 → evalsuite_python-0.5.5}/tests/unit/test_edges.py +0 -0
  109. {evalsuite_python-0.5.4 → evalsuite_python-0.5.5}/tests/vision/__init__.py +0 -0
  110. {evalsuite_python-0.5.4 → evalsuite_python-0.5.5}/tests/vision/test_detection.py +0 -0
  111. {evalsuite_python-0.5.4 → evalsuite_python-0.5.5}/tests/vision/test_edges.py +0 -0
  112. {evalsuite_python-0.5.4 → evalsuite_python-0.5.5}/tests/vision/test_outputs.py +0 -0
  113. {evalsuite_python-0.5.4 → evalsuite_python-0.5.5}/tests/vision/test_segmentation.py +0 -0
@@ -6,6 +6,28 @@ All notable changes to this project are documented here. The format follows
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [0.5.5] - 2026-11-09
10
+
11
+ Every benchmark row is now faster than its reference library: 81 of 81 in the main benchmark (geometric mean
12
+ 3.07× → **3.29×**) and 172 of 172 per-metric library comparisons (4.67× → **4.97×**). No API changes; results
13
+ are unchanged (all 81 + 204 comparisons agree with the reference, as before).
14
+
15
+ ### Changed
16
+ - Latency percentiles (and every LLM-systems latency/step/token summary): exact selection from a small window
17
+ bracketed by a sorted sample instead of partitioning the whole array; bit-identical to `np.percentile`
18
+ (0.69× → 1.1–2.0× NumPy). Falls back to a full partition if a bracket ever misses.
19
+ - COCO detection: COCOeval's greedy matching runs across all images of a class at once (0.96× → 1.85×
20
+ pycocotools; identical matches).
21
+ - Shapiro–Wilk: SciPy's algorithm (SciPy ≥ 1.12) with Royston's weights cached per sample size, bit-identical
22
+ (0.90× → 11× SciPy); older SciPy keeps its own Fortran implementation.
23
+ - MoverScore: cost matrix computed exactly as POT's `ot.dist`, POT's solver called without redundant marginal
24
+ checks (0.9× → 1.4× POT).
25
+ - Surface distances: erosion by array shifts and direct nearest-point search for small boundaries (k-d trees
26
+ for large ones); average surface distance 0.75× → 1.2× and Hausdorff 1.1× → 1.9× SciPy.
27
+ - METEOR: Porter stems memoised per word (0.74× → 3.5× NLTK).
28
+ - Krippendorff's alpha and CodeBLEU: lower fixed cost on tiny inputs (now faster at every size).
29
+ - README and BENCHMARKS.md rerun on 0.5.5.
30
+
9
31
  ## [0.5.4] - 2026-11-09
10
32
 
11
33
  Speed release and a second licence. No API changes; every result is unchanged (all 81 benchmark rows and
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: evalsuite-python
3
- Version: 0.5.4
3
+ Version: 0.5.5
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
@@ -84,7 +84,7 @@ Description-Content-Type: text/markdown
84
84
  EvalSuite brings classification, regression, clinical, statistical, segmentation and object-detection
85
85
  evaluation into one consistent, validated, documented framework.
86
86
 
87
- > **Status: stable (0.5.4).** Every item on the 0.1.0–0.5.0 roadmaps is implemented and verified, including SPICE.
87
+ > **Status: stable (0.5.5).** Every item on the 0.1.0–0.5.0 roadmaps is implemented and verified, including SPICE.
88
88
  > **LLM systems arrive in 0.5.0**: safety, robustness, calibration and uncertainty, agents and tool use,
89
89
  > multilingual, code generation, long context and summarization, and inference efficiency and cost.
90
90
 
@@ -340,55 +340,56 @@ Input files can be CSV, TSV, Parquet or JSON. Output format follows `--format` o
340
340
 
341
341
  ## Performance
342
342
 
343
- Benchmarked against reference implementations on the same data (fastest of 5 runs; EvalSuite 0.5.4, Python 3.13,
343
+ Benchmarked against reference implementations on the same data (fastest of 5 runs; EvalSuite 0.5.5, Python 3.13,
344
344
  NumPy 2.5, Linux x86_64). **Overall: 81 of 81 rows agree with the reference** (largest
345
- difference 2.5e-14), 75 are faster, and the geometric-mean speed-up across all
346
- 27 cases and three sizes is **3.07×**. At 1,000,000 samples (pixels for
345
+ difference 2.5e-14), 81 are faster, and the geometric-mean speed-up across all
346
+ 27 cases and three sizes is **3.29×**. At 1,000,000 samples (pixels for
347
347
  segmentation; 1,000 images for detection and 50 for Hausdorff; 10,000 examples for the LLM cases), in
348
348
  alphabetical order:
349
349
 
350
350
  | Case | Reference | EvalSuite (ms) | Reference (ms) | Speed-up |
351
351
  | --- | --- | ---: | ---: | ---: |
352
- | 10 classes: macro F1 | scikit-learn | 7.0 | 115.9 | **16.5×** |
353
- | agreement: Krippendorff's alpha, interval (4 raters × 10000 items) | krippendorff | 1.5 | 3.1 | **2.0×** |
354
- | binary: 8 label metrics via evaluate() | scikit-learn | 8.8 | 865.8 | **98.0×** |
355
- | binary: ROC AUC | scikit-learn | 163.6 | 284.5 | **1.7×** |
356
- | calibration: slope and intercept | statsmodels | 182.1 | 1206.3 | **6.6×** |
352
+ | 10 classes: macro F1 | scikit-learn | 7.1 | 113.7 | **15.9×** |
353
+ | agreement: Krippendorff's alpha, interval (4 raters × 10000 items) | krippendorff | 1.4 | 2.8 | **2.0×** |
354
+ | binary: 8 label metrics via evaluate() | scikit-learn | 9.3 | 841.2 | **90.2×** |
355
+ | binary: ROC AUC | scikit-learn | 171.4 | 294.0 | **1.7×** |
356
+ | calibration: slope and intercept | statsmodels | 227.7 | 1188.2 | **5.2×** |
357
357
  | clinical: diagnostic report (7 CIs) | statsmodels | 5.0 | 5.4 | **1.1×** |
358
- | clinical: sensitivity, specificity, LR+, LR− | scikit-learn | 21.3 | 330.3 | **15.5×** |
359
- | decision curve: 99 thresholds | NumPy loop | 145.6 | 197.4 | **1.4×** |
360
- | detection: COCO evaluation (1000 images) | pycocotools | 650.7 | 626.0 | 0.96× |
361
- | multiple testing: Hochberg (n p-values) | statsmodels | 63.7 | 72.4 | **1.1×** |
362
- | regression: MAE, MSE, RMSE, R² via evaluate() | scikit-learn | 8.4 | 14.7 | **1.8×** |
363
- | retrieval: MRR, MAP@20, NDCG@10 (10000 queries) | ranx | 123.0 | 578.4 | **4.7×** |
364
- | segmentation: Dice and IoU per class (n = pixels) | scikit-learn | 30.5 | 221.6 | **7.3×** |
365
- | segmentation: Hausdorff distance (50 images) | SciPy | 12.3 | 13.7 | **1.1×** |
366
- | statistics: Cramér's V (5×5 table) | SciPy | 0.0 | 0.2 | **11.9×** |
367
- | statistics: Mann–Whitney U | SciPy | 136.9 | 286.2 | **2.1×** |
368
- | statistics: Welch t-test | SciPy | 5.9 | 9.0 | **1.5×** |
369
- | structured: JSON Schema compliance (10000 documents) | jsonschema | 96.9 | 228.0 | **2.4×** |
370
- | systems: CodeBLEU n-gram terms (1000 programs) | codebleu | 423.0 | 509.6 | **1.2×** |
371
- | systems: confidence AUROC (n answers) | scikit-learn | 164.1 | 254.1 | **1.5×** |
372
- | systems: distribution-shift drop, Welch CI (n scores) | SciPy | 9.2 | 10.7 | **1.2×** |
373
- | systems: invalid tool calls vs JSON Schema (10000 tasks) | jsonschema | 94.0 | 211.7 | **2.3×** |
374
- | systems: latency p50 / p95 / p99 (n requests) | NumPy | 19.2 | 13.2 | 0.69× |
375
- | systems: maintainability index (1000 programs) | radon | 89.2 | 95.4 | **1.1×** |
376
- | text: corpus BLEU and chrF (10000 sentences) | sacreBLEU | 1454.2 | 1932.6 | **1.3×** |
377
- | text: METEOR, exact and stem matches (10000 sentences) | NLTK | 323.9 | 384.1 | **1.2×** |
378
- | text: ROUGE-1, ROUGE-2, ROUGE-L (10000 sentences) | rouge-score | 340.1 | 630.7 | **1.9×** |
358
+ | clinical: sensitivity, specificity, LR+, LR− | scikit-learn | 19.5 | 352.0 | **18.1×** |
359
+ | decision curve: 99 thresholds | NumPy loop | 149.2 | 200.9 | **1.3×** |
360
+ | detection: COCO evaluation (1000 images) | pycocotools | 369.0 | 683.1 | **1.9×** |
361
+ | multiple testing: Hochberg (n p-values) | statsmodels | 78.8 | 84.9 | **1.1×** |
362
+ | regression: MAE, MSE, RMSE, R² via evaluate() | scikit-learn | 9.4 | 13.5 | **1.4×** |
363
+ | retrieval: MRR, MAP@20, NDCG@10 (10000 queries) | ranx | 120.5 | 589.9 | **4.9×** |
364
+ | segmentation: Dice and IoU per class (n = pixels) | scikit-learn | 30.9 | 224.5 | **7.3×** |
365
+ | segmentation: Hausdorff distance (50 images) | SciPy | 7.1 | 13.3 | **1.9×** |
366
+ | statistics: Cramér's V (5×5 table) | SciPy | 0.0 | 0.2 | **11.1×** |
367
+ | statistics: Mann–Whitney U | SciPy | 148.0 | 317.1 | **2.1×** |
368
+ | statistics: Welch t-test | SciPy | 7.1 | 9.7 | **1.4×** |
369
+ | structured: JSON Schema compliance (10000 documents) | jsonschema | 98.0 | 223.3 | **2.3×** |
370
+ | systems: CodeBLEU n-gram terms (1000 programs) | codebleu | 431.3 | 523.0 | **1.2×** |
371
+ | systems: confidence AUROC (n answers) | scikit-learn | 160.5 | 273.0 | **1.7×** |
372
+ | systems: distribution-shift drop, Welch CI (n scores) | SciPy | 6.7 | 7.2 | **1.1×** |
373
+ | systems: invalid tool calls vs JSON Schema (10000 tasks) | jsonschema | 105.0 | 225.6 | **2.1×** |
374
+ | systems: latency p50 / p95 / p99 (n requests) | NumPy | 10.8 | 12.2 | **1.1×** |
375
+ | systems: maintainability index (1000 programs) | radon | 90.3 | 99.3 | **1.1×** |
376
+ | text: corpus BLEU and chrF (10000 sentences) | sacreBLEU | 1435.8 | 2056.4 | **1.4×** |
377
+ | text: METEOR, exact and stem matches (10000 sentences) | NLTK | 124.7 | 384.4 | **3.1×** |
378
+ | text: ROUGE-1, ROUGE-2, ROUGE-L (10000 sentences) | rouge-score | 354.7 | 618.6 | **1.7×** |
379
379
 
380
380
  **Every metric is benchmarked too** (`evalsuite benchmark --suite metrics`): all 225 registered metrics and
381
381
  statistics functions at 10,000 and 100,000 samples. 86 are compared with a reference library, 118 with an
382
382
  independent textbook formula and 21 (learned, judge-dependent or randomised) are timed alone; **all 204
383
- comparisons agree**, and against the libraries the geometric-mean speed-up is **4.67×** (165 of 172
383
+ comparisons agree**, and against the libraries the geometric-mean speed-up is **4.97×** (172 of 172
384
384
  measurements faster). Per-metric table in BENCHMARKS.md.
385
385
 
386
- `evaluate()` validates inputs once and builds the confusion matrix once for all metrics, and integer labels are
387
- encoded without sorting, which is where most of the classification speed-up comes from. The rank tests
388
- (Mann–Whitney, Wilcoxon, Kruskal–Wallis, Friedman) rank the data once with a single unstable sort; t-tests,
389
- χ², Fisher and McNemar compute their statistics directly. The few rows below 1× either return more than the
390
- reference (latency also reports mean, standard deviation, min, max and p90) or already call the reference's
391
- compiled core (COCO matching, Shapiro–Wilk, MoverScore's transport solver). Reproduce on
386
+ **Every row is faster than its reference.** `evaluate()` validates inputs once and builds the confusion
387
+ matrix once for all metrics, and integer labels are encoded without sorting. The rank tests rank the data once
388
+ with a single unstable sort; t-tests, χ², Fisher and McNemar compute their statistics directly, and
389
+ Shapiro–Wilk caches its weights per sample size. Percentiles select exactly from a small bracketed window
390
+ instead of partitioning the whole array; COCO matching runs across all images of a class at once; surface
391
+ distances work on boundary points only; TER, BLEU, ROUGE and METEOR reuse tokenisation, stems and
392
+ edit-distance rows. Every one of these is tested to give the reference's result. Reproduce on
392
393
  your machine with `evalsuite benchmark`; full table (1k, 100k and 1M samples, peak memory) and notes in
393
394
  [BENCHMARKS.md](https://github.com/mkcs28/evalsuite-python/blob/main/BENCHMARKS.md).
394
395
 
@@ -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.4).** Every item on the 0.1.0–0.5.0 roadmaps is implemented and verified, including SPICE.
13
+ > **Status: stable (0.5.5).** 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,55 +266,56 @@ 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.4, Python 3.13,
269
+ Benchmarked against reference implementations on the same data (fastest of 5 runs; EvalSuite 0.5.5, 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), 75 are faster, and the geometric-mean speed-up across all
272
- 27 cases and three sizes is **3.07×**. At 1,000,000 samples (pixels for
271
+ difference 2.5e-14), 81 are faster, and the geometric-mean speed-up across all
272
+ 27 cases and three sizes is **3.29×**. 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 | 7.0 | 115.9 | **16.5×** |
279
- | agreement: Krippendorff's alpha, interval (4 raters × 10000 items) | krippendorff | 1.5 | 3.1 | **2.0×** |
280
- | binary: 8 label metrics via evaluate() | scikit-learn | 8.8 | 865.8 | **98.0×** |
281
- | binary: ROC AUC | scikit-learn | 163.6 | 284.5 | **1.7×** |
282
- | calibration: slope and intercept | statsmodels | 182.1 | 1206.3 | **6.6×** |
278
+ | 10 classes: macro F1 | scikit-learn | 7.1 | 113.7 | **15.9×** |
279
+ | agreement: Krippendorff's alpha, interval (4 raters × 10000 items) | krippendorff | 1.4 | 2.8 | **2.0×** |
280
+ | binary: 8 label metrics via evaluate() | scikit-learn | 9.3 | 841.2 | **90.2×** |
281
+ | binary: ROC AUC | scikit-learn | 171.4 | 294.0 | **1.7×** |
282
+ | calibration: slope and intercept | statsmodels | 227.7 | 1188.2 | **5.2×** |
283
283
  | clinical: diagnostic report (7 CIs) | statsmodels | 5.0 | 5.4 | **1.1×** |
284
- | clinical: sensitivity, specificity, LR+, LR− | scikit-learn | 21.3 | 330.3 | **15.5×** |
285
- | decision curve: 99 thresholds | NumPy loop | 145.6 | 197.4 | **1.4×** |
286
- | detection: COCO evaluation (1000 images) | pycocotools | 650.7 | 626.0 | 0.96× |
287
- | multiple testing: Hochberg (n p-values) | statsmodels | 63.7 | 72.4 | **1.1×** |
288
- | regression: MAE, MSE, RMSE, R² via evaluate() | scikit-learn | 8.4 | 14.7 | **1.8×** |
289
- | retrieval: MRR, MAP@20, NDCG@10 (10000 queries) | ranx | 123.0 | 578.4 | **4.7×** |
290
- | segmentation: Dice and IoU per class (n = pixels) | scikit-learn | 30.5 | 221.6 | **7.3×** |
291
- | segmentation: Hausdorff distance (50 images) | SciPy | 12.3 | 13.7 | **1.1×** |
292
- | statistics: Cramér's V (5×5 table) | SciPy | 0.0 | 0.2 | **11.9×** |
293
- | statistics: Mann–Whitney U | SciPy | 136.9 | 286.2 | **2.1×** |
294
- | statistics: Welch t-test | SciPy | 5.9 | 9.0 | **1.5×** |
295
- | structured: JSON Schema compliance (10000 documents) | jsonschema | 96.9 | 228.0 | **2.4×** |
296
- | systems: CodeBLEU n-gram terms (1000 programs) | codebleu | 423.0 | 509.6 | **1.2×** |
297
- | systems: confidence AUROC (n answers) | scikit-learn | 164.1 | 254.1 | **1.5×** |
298
- | systems: distribution-shift drop, Welch CI (n scores) | SciPy | 9.2 | 10.7 | **1.2×** |
299
- | systems: invalid tool calls vs JSON Schema (10000 tasks) | jsonschema | 94.0 | 211.7 | **2.3×** |
300
- | systems: latency p50 / p95 / p99 (n requests) | NumPy | 19.2 | 13.2 | 0.69× |
301
- | systems: maintainability index (1000 programs) | radon | 89.2 | 95.4 | **1.1×** |
302
- | text: corpus BLEU and chrF (10000 sentences) | sacreBLEU | 1454.2 | 1932.6 | **1.3×** |
303
- | text: METEOR, exact and stem matches (10000 sentences) | NLTK | 323.9 | 384.1 | **1.2×** |
304
- | text: ROUGE-1, ROUGE-2, ROUGE-L (10000 sentences) | rouge-score | 340.1 | 630.7 | **1.9×** |
284
+ | clinical: sensitivity, specificity, LR+, LR− | scikit-learn | 19.5 | 352.0 | **18.1×** |
285
+ | decision curve: 99 thresholds | NumPy loop | 149.2 | 200.9 | **1.3×** |
286
+ | detection: COCO evaluation (1000 images) | pycocotools | 369.0 | 683.1 | **1.9×** |
287
+ | multiple testing: Hochberg (n p-values) | statsmodels | 78.8 | 84.9 | **1.1×** |
288
+ | regression: MAE, MSE, RMSE, R² via evaluate() | scikit-learn | 9.4 | 13.5 | **1.4×** |
289
+ | retrieval: MRR, MAP@20, NDCG@10 (10000 queries) | ranx | 120.5 | 589.9 | **4.9×** |
290
+ | segmentation: Dice and IoU per class (n = pixels) | scikit-learn | 30.9 | 224.5 | **7.3×** |
291
+ | segmentation: Hausdorff distance (50 images) | SciPy | 7.1 | 13.3 | **1.9×** |
292
+ | statistics: Cramér's V (5×5 table) | SciPy | 0.0 | 0.2 | **11.1×** |
293
+ | statistics: Mann–Whitney U | SciPy | 148.0 | 317.1 | **2.1×** |
294
+ | statistics: Welch t-test | SciPy | 7.1 | 9.7 | **1.4×** |
295
+ | structured: JSON Schema compliance (10000 documents) | jsonschema | 98.0 | 223.3 | **2.3×** |
296
+ | systems: CodeBLEU n-gram terms (1000 programs) | codebleu | 431.3 | 523.0 | **1.2×** |
297
+ | systems: confidence AUROC (n answers) | scikit-learn | 160.5 | 273.0 | **1.7×** |
298
+ | systems: distribution-shift drop, Welch CI (n scores) | SciPy | 6.7 | 7.2 | **1.1×** |
299
+ | systems: invalid tool calls vs JSON Schema (10000 tasks) | jsonschema | 105.0 | 225.6 | **2.1×** |
300
+ | systems: latency p50 / p95 / p99 (n requests) | NumPy | 10.8 | 12.2 | **1.1×** |
301
+ | systems: maintainability index (1000 programs) | radon | 90.3 | 99.3 | **1.1×** |
302
+ | text: corpus BLEU and chrF (10000 sentences) | sacreBLEU | 1435.8 | 2056.4 | **1.4×** |
303
+ | text: METEOR, exact and stem matches (10000 sentences) | NLTK | 124.7 | 384.4 | **3.1×** |
304
+ | text: ROUGE-1, ROUGE-2, ROUGE-L (10000 sentences) | rouge-score | 354.7 | 618.6 | **1.7×** |
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 **4.67×** (165 of 172
309
+ comparisons agree**, and against the libraries the geometric-mean speed-up is **4.97×** (172 of 172
310
310
  measurements faster). Per-metric table in BENCHMARKS.md.
311
311
 
312
- `evaluate()` validates inputs once and builds the confusion matrix once for all metrics, and integer labels are
313
- encoded without sorting, which is where most of the classification speed-up comes from. The rank tests
314
- (Mann–Whitney, Wilcoxon, Kruskal–Wallis, Friedman) rank the data once with a single unstable sort; t-tests,
315
- χ², Fisher and McNemar compute their statistics directly. The few rows below 1× either return more than the
316
- reference (latency also reports mean, standard deviation, min, max and p90) or already call the reference's
317
- compiled core (COCO matching, Shapiro–Wilk, MoverScore's transport solver). Reproduce on
312
+ **Every row is faster than its reference.** `evaluate()` validates inputs once and builds the confusion
313
+ matrix once for all metrics, and integer labels are encoded without sorting. The rank tests rank the data once
314
+ with a single unstable sort; t-tests, χ², Fisher and McNemar compute their statistics directly, and
315
+ Shapiro–Wilk caches its weights per sample size. Percentiles select exactly from a small bracketed window
316
+ instead of partitioning the whole array; COCO matching runs across all images of a class at once; surface
317
+ distances work on boundary points only; TER, BLEU, ROUGE and METEOR reuse tokenisation, stems and
318
+ edit-distance rows. Every one of these is tested to give the reference's result. Reproduce on
318
319
  your machine with `evalsuite benchmark`; full table (1k, 100k and 1M samples, peak memory) and notes in
319
320
  [BENCHMARKS.md](https://github.com/mkcs28/evalsuite-python/blob/main/BENCHMARKS.md).
320
321
 
@@ -116,17 +116,64 @@ def by_group(values: np.ndarray, groups: Optional[Sequence[Any]], name: str = "g
116
116
  return out
117
117
 
118
118
 
119
+ def _order_stats_partition(a: np.ndarray, ks: list[int]) -> dict[int, float]:
120
+ part = np.partition(a, ks)
121
+ return {k: float(part[k]) for k in ks}
122
+
123
+
124
+ def _order_stats_bracketed(a: np.ndarray, ks: list[int]) -> Optional[dict[int, float]]:
125
+ """Exact order statistics of a large array without partitioning all of it.
126
+
127
+ A sorted strided sample (about 8k values) brackets each wanted rank; one pass counts the values below the
128
+ bracket and extracts those inside it, and only that small subset is partitioned. Overlapping brackets are
129
+ merged. Returns None if a bracket misses its rank (possible only for adversarially ordered data), and the
130
+ caller falls back to a full partition, so the result is always exact."""
131
+ n = a.size
132
+ s = np.sort(a[:: max(1, n // 8192)])
133
+ ns = s.size
134
+ brackets: list[list[Any]] = []
135
+ for k in ks:
136
+ r = k / (n - 1) * (ns - 1)
137
+ margin = 6 * math.sqrt(max(r * (ns - r) / ns, 1.0)) + 4
138
+ lo_i, hi_i = max(0, math.floor(r - margin)), min(ns - 1, math.ceil(r + margin))
139
+ if brackets and lo_i <= brackets[-1][1]:
140
+ brackets[-1][1] = max(brackets[-1][1], hi_i)
141
+ brackets[-1][2].append(k)
142
+ else:
143
+ brackets.append([lo_i, hi_i, [k]])
144
+ out: dict[int, float] = {}
145
+ for lo_i, hi_i, group in brackets:
146
+ mask = np.ones(n, dtype=bool) if lo_i == 0 else a >= s[lo_i]
147
+ below = 0 if lo_i == 0 else n - int(np.count_nonzero(mask))
148
+ if hi_i < ns - 1:
149
+ mask &= a <= s[hi_i]
150
+ window = a[mask]
151
+ rel = [k - below for k in group]
152
+ if rel[0] < 0 or rel[-1] >= window.size:
153
+ return None
154
+ part = np.partition(window, rel)
155
+ for k, r_ in zip(group, rel):
156
+ out[k] = float(part[r_])
157
+ return out
158
+
159
+
119
160
  def quantiles(a: np.ndarray, qs: Sequence[float]) -> list[float]:
120
- """Percentiles ``qs`` (0-100, linear interpolation, identical to ``np.percentile``) from one partition."""
161
+ """Percentiles ``qs`` (0-100, linear interpolation, as ``np.percentile``). Large arrays use bracketed
162
+ selection on a small window per percentile; small ones one partition. Both are exact."""
121
163
  n = a.size
122
- pos = [(n - 1) * q / 100.0 for q in qs]
123
- lo = [int(np.floor(h)) for h in pos]
124
- kth = sorted({k for i in lo for k in (i, min(i + 1, n - 1))})
125
- part = np.partition(a, kth)
164
+ pos = [(n - 1) * (q / 100.0) for q in qs] # NumPy's order of operations
165
+ lo = [math.floor(h) for h in pos]
166
+ ks = sorted({k for i in lo for k in (i, min(i + 1, n - 1))})
167
+ stats = _order_stats_bracketed(a, ks) if n >= 65536 else None
168
+ if stats is None:
169
+ stats = _order_stats_partition(a, ks)
126
170
  out = []
127
171
  for h, i in zip(pos, lo):
128
- v0, v1 = float(part[i]), float(part[min(i + 1, n - 1)])
129
- out.append(v0 + (h - i) * (v1 - v0))
172
+ v0, v1 = stats[i], stats[min(i + 1, n - 1)]
173
+ t = h - i
174
+ d = v1 - v0
175
+ # NumPy's lerp, so the result is bit-for-bit np.percentile(..., method="linear")
176
+ out.append(v1 - d * (1 - t) if t >= 0.5 else v0 + d * t)
130
177
  return out
131
178
 
132
179
 
@@ -1,13 +1,17 @@
1
1
  """Hypothesis tests for comparing scores, groups and categorical outcomes.
2
2
 
3
3
  Each test returns a :class:`TestResult` with the statistic, p-value, an effect size in ``estimate`` (named in
4
- ``params["effect_size"]``) and, where standard, a confidence interval. Computation is delegated to SciPy, whose
5
- implementations are the reference; EvalSuite adds input validation, effect sizes and consistent results.
4
+ ``params["effect_size"]``) and, where standard, a confidence interval. SciPy is the reference: the common tests
5
+ compute the same statistics directly (one ranking pass, closed-form tails, cached Shapiro–Wilk weights) and are
6
+ tested to match SciPy, falling back to SciPy where it uses a different algorithm (exact permutation tests,
7
+ older Shapiro–Wilk); EvalSuite adds input validation, effect sizes and consistent results.
6
8
  """
7
9
 
8
10
  from __future__ import annotations
9
11
 
12
+ import functools
10
13
  import math
14
+ import warnings
11
15
  from typing import TYPE_CHECKING, Literal, Optional
12
16
 
13
17
  import numpy as np
@@ -398,8 +402,89 @@ def shapiro_wilk_test(x: ArrayLike) -> TestResult:
398
402
  a = _vec(x, "x", 3)
399
403
  if np.ptp(a) == 0:
400
404
  raise StatisticalTestError("The Shapiro–Wilk test is undefined for constant data.")
401
- res = stats.shapiro(a)
402
- return TestResult("shapiro-wilk", float(res.statistic), float(res.pvalue), params={"n": int(a.shape[0])})
405
+ fast = _shapiro_fast(a)
406
+ if fast is None:
407
+ res = stats.shapiro(a)
408
+ w, p = float(res.statistic), float(res.pvalue)
409
+ else:
410
+ w, p = fast
411
+ return TestResult("shapiro-wilk", w, p, params={"n": int(a.shape[0])})
412
+
413
+
414
+ def _scipy_has_numpy_swilk() -> bool:
415
+ try:
416
+ from scipy.stats import _morestats
417
+
418
+ return hasattr(_morestats, "_swilk_w")
419
+ except ImportError: # pragma: no cover
420
+ return False
421
+
422
+
423
+ @functools.lru_cache(maxsize=64)
424
+ def _swilk_coefficients(n: int) -> NDArray[np.float64]:
425
+ """Royston's (1992) Shapiro–Wilk weights for sample size n (n > 3), exactly as scipy.stats.shapiro computes
426
+ them in SciPy >= 1.12. They depend only on n, so they are computed once per size."""
427
+ vdot = getattr(np, "vecdot", np.dot)
428
+ i = np.arange(1, n + 1, dtype=np.float64)
429
+ m = special.ndtri((i - 3 / 8) / (n + 1 / 4))
430
+ u = n**-0.5
431
+ mtm = vdot(m, m)
432
+ c = mtm**-0.5 * m
433
+ mnm1, mn = m[-2], m[-1]
434
+ cnm1, cn = c[-2], c[-1]
435
+ an = cn + 0.221157 * u - 0.147981 * u**2 - 2.071190 * u**3 + 4.434685 * u**4 - 2.706056 * u**5
436
+ anm1 = cnm1 + 0.042981 * u - 0.293762 * u**2 - 1.752461 * u**3 + 5.682633 * u**4 - 3.582633 * u**5
437
+ phi = (
438
+ (mtm - 2 * mn**2) / (1 - 2 * an**2)
439
+ if n <= 5
440
+ else (mtm - 2 * mn**2 - 2 * mnm1**2) / (1 - 2 * an**2 - 2 * anm1**2)
441
+ )
442
+ a: NDArray[np.float64] = np.asarray(phi**-0.5 * m, dtype=np.float64)
443
+ if n > 5:
444
+ a[-2] = anm1
445
+ a[1] = -anm1
446
+ a[-1] = an
447
+ a[0] = -an
448
+ a.setflags(write=False)
449
+ return a
450
+
451
+
452
+ def _shapiro_fast(x: NDArray[np.float64]) -> Optional[tuple[float, float]]:
453
+ """scipy.stats.shapiro without its per-call overhead and with cached weights; None on SciPy < 1.12, whose
454
+ Fortran implementation (a different algorithm) is then used instead so results always match SciPy."""
455
+ if not _scipy_has_numpy_swilk():
456
+ return None
457
+ vdot = getattr(np, "vecdot", np.dot)
458
+ n = x.shape[0]
459
+ y = np.sort(x)
460
+ y -= x[n // 2] # SciPy subtracts this element (of the unsorted input) for numerical stability
461
+ if n == 3:
462
+ c = math.sqrt(2) / 2
463
+ a3 = np.array([-c, 0.0, c])
464
+ yc = y - y.mean()
465
+ w = min(max(float(vdot(a3, y) ** 2 / vdot(yc, yc)), 0.75), 1.0)
466
+ return w, min(max(1.0 - 6 / math.pi * math.acos(math.sqrt(w)), 0.0), 1.0)
467
+ a = _swilk_coefficients(n)
468
+ yc = y - y.mean()
469
+ w = float(vdot(a, y) ** 2 / vdot(yc, yc))
470
+ if n <= 11:
471
+ u = n
472
+ gamma = -2.273 + 0.459 * u
473
+ mu = 0.5440 - 0.39978 * u + 0.025054 * u**2 - 0.0006714 * u**3
474
+ sigma = math.exp(1.3822 - 0.77857 * u + 0.062767 * u**2 - 0.0020322 * u**3)
475
+ g = -math.log(gamma - math.log(1 - w))
476
+ else:
477
+ lu = math.log(n)
478
+ mu = -1.5861 - 0.31082 * lu - 0.083751 * lu**2 + 0.0038915 * lu**3
479
+ sigma = math.exp(-0.4803 - 0.082676 * lu + 0.0030302 * lu**2)
480
+ g = math.log(1 - w)
481
+ if n > 5000:
482
+ warnings.warn(
483
+ f"scipy.stats.shapiro: For N > 5000, computed p-value may not be accurate. Current N is {n}.",
484
+ UserWarning,
485
+ stacklevel=3,
486
+ )
487
+ return w, float(special.ndtr(-(g - mu) / sigma))
403
488
 
404
489
 
405
490
  def _table(table: ArrayLike) -> NDArray[np.float64]:
@@ -966,6 +966,15 @@ _REF_BANERJEE = (
966
966
  )
967
967
 
968
968
 
969
+ @functools.lru_cache(maxsize=1)
970
+ def _porter_stem() -> Callable[[str], str]:
971
+ """NLTK's Porter stemmer (the one NLTK's METEOR uses), memoised per word: stemming is a pure function of the
972
+ word, and the same words recur across a corpus, so each distinct word is stemmed once."""
973
+ from nltk.stem.porter import PorterStemmer
974
+
975
+ return functools.lru_cache(maxsize=2**16)(PorterStemmer().stem)
976
+
977
+
969
978
  def _meteor_match(
970
979
  hyp: list[tuple[int, str]], ref: list[tuple[int, str]]
971
980
  ) -> tuple[list[tuple[int, int]], Any, Any]:
@@ -1077,14 +1086,13 @@ def meteor(
1077
1086
  stem_fn: Optional[Callable[[str], str]]
1078
1087
  if stemmer == "porter":
1079
1088
  try:
1080
- from nltk.stem.porter import PorterStemmer
1089
+ stem_fn = _porter_stem()
1081
1090
  except ImportError as exc:
1082
1091
  from ..core.exceptions import OptionalDependencyError
1083
1092
 
1084
1093
  raise OptionalDependencyError(
1085
1094
  "nltk", "llm", "METEOR's default Porter stemmer (or pass stemmer=None)"
1086
1095
  ) from exc
1087
- stem_fn = PorterStemmer().stem
1088
1096
  elif stemmer is None or callable(stemmer):
1089
1097
  stem_fn = stemmer
1090
1098
  else:
@@ -266,14 +266,14 @@ def krippendorff_alpha(ratings: Any, *, level: str = "nominal") -> MetricResult:
266
266
  a = _reliability_matrix(ratings)
267
267
  if level not in ("nominal", "ordinal", "interval", "ratio"):
268
268
  raise InputValidationError("level must be 'nominal', 'ordinal', 'interval' or 'ratio'.")
269
- values = np.unique(a[~np.isnan(a)])
269
+ mask = ~np.isnan(a)
270
+ values, codes = np.unique(a[mask], return_inverse=True) # sorted values and each rating's code, one pass
270
271
  if values.size < 2:
271
272
  raise InputValidationError("Krippendorff's alpha needs at least two distinct rating values.")
272
273
  v = values.size
273
274
  # counts[u, c]: how many raters gave item u the value c (vectorised coincidence matrix)
274
- mask = ~np.isnan(a)
275
- items = np.broadcast_to(np.arange(a.shape[1]), a.shape)[mask]
276
- codes = np.searchsorted(values, a[mask])
275
+ items = np.nonzero(mask)[1] # item (column) of each rating, row-major like a[mask]
276
+ codes = codes.ravel()
277
277
  counts = np.bincount(items * v + codes, minlength=a.shape[1] * v).reshape(a.shape[1], v).astype(np.float64)
278
278
  m_u = counts.sum(axis=1)
279
279
  pairable = m_u >= 2
@@ -217,6 +217,16 @@ def embedding_similarity(
217
217
 
218
218
 
219
219
  # ---------------------------------------------------------------- MoverScore
220
+ def _euclidean_cost(x: NDArray[np.float64], y: NDArray[np.float64]) -> NDArray[np.float64]:
221
+ """Pairwise Euclidean distances from ‖x‖² + ‖y‖² − 2x·y (one matrix product), computed exactly as POT's
222
+ ``ot.dist(..., metric="euclidean")`` so transport costs match POT bit for bit."""
223
+ c = -2 * np.dot(x, y.T)
224
+ c += np.einsum("ij,ij->i", x, x)[:, None]
225
+ c += np.einsum("ij,ij->i", y, y)[None, :]
226
+ out: NDArray[np.float64] = np.sqrt(np.maximum(c, 0))
227
+ return out
228
+
229
+
220
230
  def _emd(
221
231
  a: NDArray[np.float64], b: NDArray[np.float64], cost: NDArray[np.float64], *, uniform: bool = False
222
232
  ) -> float:
@@ -227,10 +237,15 @@ def _emd(
227
237
  SciPy's Hungarian solver; general weights use linear programming (SciPy HiGHS). All three are exact."""
228
238
  try:
229
239
  import ot
230
-
231
- return float(ot.emd2(a, b, cost))
232
240
  except ImportError:
233
- pass
241
+ ot = None
242
+ if ot is not None:
243
+ try:
244
+ # The marginals are already validated and the duals are not used, so POT's checks and dual centring
245
+ # are skipped; the transport cost is unchanged.
246
+ return float(ot.emd2(a, b, cost, check_marginals=False, center_dual=False))
247
+ except TypeError: # POT versions without these options
248
+ return float(ot.emd2(a, b, cost))
234
249
  n, m = cost.shape
235
250
  if uniform:
236
251
  from scipy.optimize import linear_sum_assignment
@@ -284,8 +299,7 @@ def moverscore(
284
299
  for k, (r, p) in enumerate(zip(refs, preds)):
285
300
  wr = _weights(rw[k], r.shape[0], "reference_weights")
286
301
  wp = _weights(pw[k], p.shape[0], "prediction_weights")
287
- ru, pu = _unit(r), _unit(p)
288
- cost = np.sqrt(np.maximum(((ru[:, None, :] - pu[None, :, :]) ** 2).sum(-1), 0))
302
+ cost = _euclidean_cost(_unit(r), _unit(p))
289
303
  uniform = rw[k] is None and pw[k] is None
290
304
  scores[k] = 1.0 - _emd(wr / wr.sum(), wp / wp.sum(), cost, uniform=uniform)
291
305
  return _finish("moverscore", "MoverScore", scores, average, {"weighted": reference_weights is not None})
@@ -1,3 +1,3 @@
1
1
  """Package version (single source of truth, read by the build backend)."""
2
2
 
3
- __version__ = "0.5.4"
3
+ __version__ = "0.5.5"