evalsuite-python 0.6.0__cp39-abi3-win_amd64.whl
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/__init__.py +268 -0
- evalsuite/__main__.py +5 -0
- evalsuite/_bench_metrics.py +2080 -0
- evalsuite/_core.pyd +0 -0
- evalsuite/_lazy.py +32 -0
- evalsuite/_native.py +60 -0
- evalsuite/api.py +275 -0
- evalsuite/benchmarks.py +946 -0
- evalsuite/calibration.py +392 -0
- evalsuite/classification/__init__.py +51 -0
- evalsuite/classification/_common.py +111 -0
- evalsuite/classification/metrics.py +945 -0
- evalsuite/cli/__init__.py +5 -0
- evalsuite/cli/main.py +606 -0
- evalsuite/clinical/__init__.py +18 -0
- evalsuite/clinical/metrics.py +342 -0
- evalsuite/clinical/report.py +366 -0
- evalsuite/core/__init__.py +1 -0
- evalsuite/core/context.py +199 -0
- evalsuite/core/exceptions.py +52 -0
- evalsuite/core/export.py +100 -0
- evalsuite/core/registry.py +90 -0
- evalsuite/core/result.py +379 -0
- evalsuite/core/types.py +23 -0
- evalsuite/core/validation.py +256 -0
- evalsuite/llmsys/__init__.py +189 -0
- evalsuite/llmsys/_common.py +215 -0
- evalsuite/llmsys/agents.py +384 -0
- evalsuite/llmsys/code.py +923 -0
- evalsuite/llmsys/efficiency.py +346 -0
- evalsuite/llmsys/longcontext.py +361 -0
- evalsuite/llmsys/multilingual.py +339 -0
- evalsuite/llmsys/robustness.py +504 -0
- evalsuite/llmsys/safety.py +509 -0
- evalsuite/llmsys/uncertainty.py +229 -0
- evalsuite/plot.py +651 -0
- evalsuite/py.typed +0 -0
- evalsuite/regression/__init__.py +41 -0
- evalsuite/regression/metrics.py +629 -0
- evalsuite/reporting.py +241 -0
- evalsuite/stats/__init__.py +46 -0
- evalsuite/stats/_resolve.py +229 -0
- evalsuite/stats/compare.py +420 -0
- evalsuite/stats/effect.py +159 -0
- evalsuite/stats/hypothesis.py +593 -0
- evalsuite/stats/intervals.py +338 -0
- evalsuite/stats/paired.py +214 -0
- evalsuite/stats/results.py +129 -0
- evalsuite/text/__init__.py +154 -0
- evalsuite/text/_common.py +97 -0
- evalsuite/text/factuality.py +469 -0
- evalsuite/text/generation.py +1346 -0
- evalsuite/text/judge.py +556 -0
- evalsuite/text/qa.py +108 -0
- evalsuite/text/rag.py +235 -0
- evalsuite/text/reasoning.py +215 -0
- evalsuite/text/report.py +158 -0
- evalsuite/text/retrieval.py +238 -0
- evalsuite/text/semantic.py +499 -0
- evalsuite/text/spice.py +162 -0
- evalsuite/text/structured.py +793 -0
- evalsuite/version.py +3 -0
- evalsuite/vision/__init__.py +47 -0
- evalsuite/vision/detection.py +696 -0
- evalsuite/vision/segmentation.py +1028 -0
- evalsuite_python-0.6.0.dist-info/METADATA +509 -0
- evalsuite_python-0.6.0.dist-info/RECORD +72 -0
- evalsuite_python-0.6.0.dist-info/WHEEL +4 -0
- evalsuite_python-0.6.0.dist-info/entry_points.txt +2 -0
- evalsuite_python-0.6.0.dist-info/licenses/LICENSE +21 -0
- evalsuite_python-0.6.0.dist-info/licenses/LICENSE-APACHE +191 -0
- evalsuite_python-0.6.0.dist-info/sboms/evalsuite-py.cyclonedx.json +576 -0
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
"""Language-model evaluation (v0.4.0): text generation, semantic similarity, factuality and hallucination,
|
|
2
|
+
LLM-as-a-judge and preferences, reasoning benchmarks, retrieval-augmented generation, and instruction following
|
|
3
|
+
and structured output."""
|
|
4
|
+
|
|
5
|
+
from .factuality import (
|
|
6
|
+
abstention_accuracy,
|
|
7
|
+
answer_correctness,
|
|
8
|
+
answer_relevance,
|
|
9
|
+
citation_precision,
|
|
10
|
+
citation_recall,
|
|
11
|
+
claim_verification_accuracy,
|
|
12
|
+
faithfulness,
|
|
13
|
+
groundedness,
|
|
14
|
+
hallucination_rate,
|
|
15
|
+
knowledge_consistency,
|
|
16
|
+
)
|
|
17
|
+
from .generation import (
|
|
18
|
+
bleu,
|
|
19
|
+
chrf,
|
|
20
|
+
cider,
|
|
21
|
+
cross_entropy,
|
|
22
|
+
distinct_n,
|
|
23
|
+
meteor,
|
|
24
|
+
perplexity,
|
|
25
|
+
rouge_1,
|
|
26
|
+
rouge_2,
|
|
27
|
+
rouge_l,
|
|
28
|
+
rouge_lsum,
|
|
29
|
+
self_bleu,
|
|
30
|
+
sentence_bleu,
|
|
31
|
+
ter,
|
|
32
|
+
)
|
|
33
|
+
from .judge import (
|
|
34
|
+
bradley_terry,
|
|
35
|
+
elo_ratings,
|
|
36
|
+
fleiss_kappa,
|
|
37
|
+
judge_agreement,
|
|
38
|
+
krippendorff_alpha,
|
|
39
|
+
position_consistency,
|
|
40
|
+
rubric_score,
|
|
41
|
+
self_preference_bias,
|
|
42
|
+
verbosity_bias,
|
|
43
|
+
win_rate,
|
|
44
|
+
)
|
|
45
|
+
from .qa import exact_match, normalize_answer, token_f1
|
|
46
|
+
from .rag import (
|
|
47
|
+
context_precision,
|
|
48
|
+
context_recall,
|
|
49
|
+
context_relevance,
|
|
50
|
+
failure_attribution,
|
|
51
|
+
latency_summary,
|
|
52
|
+
task_success_rate,
|
|
53
|
+
)
|
|
54
|
+
from .reasoning import benchmark_accuracy, extract_answer, majority_vote_accuracy, pass_at_k
|
|
55
|
+
from .report import TextReport, text_report
|
|
56
|
+
from .retrieval import hit_rate_at_k, mean_average_precision_at_k, mrr, ndcg_at_k, precision_at_k, recall_at_k
|
|
57
|
+
from .semantic import bertscore, embedding_similarity, mauve, model_score, moverscore
|
|
58
|
+
from .spice import spice
|
|
59
|
+
from .structured import (
|
|
60
|
+
api_call_success_rate,
|
|
61
|
+
constraint_satisfaction_rate,
|
|
62
|
+
extra_content_rate,
|
|
63
|
+
extract_json,
|
|
64
|
+
format_compliance,
|
|
65
|
+
instruction_compliance_rate,
|
|
66
|
+
instruction_retention,
|
|
67
|
+
json_schema_compliance,
|
|
68
|
+
json_validity,
|
|
69
|
+
required_field_accuracy,
|
|
70
|
+
tool_argument_accuracy,
|
|
71
|
+
tool_call_f1,
|
|
72
|
+
tool_selection_accuracy,
|
|
73
|
+
validate_json_schema,
|
|
74
|
+
xml_validity,
|
|
75
|
+
)
|
|
76
|
+
|
|
77
|
+
__all__ = [
|
|
78
|
+
"TextReport",
|
|
79
|
+
"text_report",
|
|
80
|
+
"abstention_accuracy",
|
|
81
|
+
"answer_correctness",
|
|
82
|
+
"answer_relevance",
|
|
83
|
+
"api_call_success_rate",
|
|
84
|
+
"benchmark_accuracy",
|
|
85
|
+
"bertscore",
|
|
86
|
+
"bleu",
|
|
87
|
+
"bradley_terry",
|
|
88
|
+
"chrf",
|
|
89
|
+
"cider",
|
|
90
|
+
"citation_precision",
|
|
91
|
+
"citation_recall",
|
|
92
|
+
"claim_verification_accuracy",
|
|
93
|
+
"constraint_satisfaction_rate",
|
|
94
|
+
"context_precision",
|
|
95
|
+
"context_recall",
|
|
96
|
+
"context_relevance",
|
|
97
|
+
"cross_entropy",
|
|
98
|
+
"distinct_n",
|
|
99
|
+
"elo_ratings",
|
|
100
|
+
"embedding_similarity",
|
|
101
|
+
"exact_match",
|
|
102
|
+
"extra_content_rate",
|
|
103
|
+
"extract_answer",
|
|
104
|
+
"extract_json",
|
|
105
|
+
"failure_attribution",
|
|
106
|
+
"faithfulness",
|
|
107
|
+
"fleiss_kappa",
|
|
108
|
+
"format_compliance",
|
|
109
|
+
"groundedness",
|
|
110
|
+
"hallucination_rate",
|
|
111
|
+
"hit_rate_at_k",
|
|
112
|
+
"instruction_compliance_rate",
|
|
113
|
+
"instruction_retention",
|
|
114
|
+
"json_schema_compliance",
|
|
115
|
+
"json_validity",
|
|
116
|
+
"judge_agreement",
|
|
117
|
+
"knowledge_consistency",
|
|
118
|
+
"krippendorff_alpha",
|
|
119
|
+
"latency_summary",
|
|
120
|
+
"majority_vote_accuracy",
|
|
121
|
+
"mauve",
|
|
122
|
+
"mean_average_precision_at_k",
|
|
123
|
+
"meteor",
|
|
124
|
+
"model_score",
|
|
125
|
+
"moverscore",
|
|
126
|
+
"mrr",
|
|
127
|
+
"ndcg_at_k",
|
|
128
|
+
"normalize_answer",
|
|
129
|
+
"pass_at_k",
|
|
130
|
+
"perplexity",
|
|
131
|
+
"position_consistency",
|
|
132
|
+
"precision_at_k",
|
|
133
|
+
"recall_at_k",
|
|
134
|
+
"required_field_accuracy",
|
|
135
|
+
"rouge_1",
|
|
136
|
+
"rouge_2",
|
|
137
|
+
"rouge_l",
|
|
138
|
+
"rouge_lsum",
|
|
139
|
+
"rubric_score",
|
|
140
|
+
"self_bleu",
|
|
141
|
+
"self_preference_bias",
|
|
142
|
+
"sentence_bleu",
|
|
143
|
+
"spice",
|
|
144
|
+
"task_success_rate",
|
|
145
|
+
"ter",
|
|
146
|
+
"token_f1",
|
|
147
|
+
"tool_argument_accuracy",
|
|
148
|
+
"tool_call_f1",
|
|
149
|
+
"tool_selection_accuracy",
|
|
150
|
+
"validate_json_schema",
|
|
151
|
+
"verbosity_bias",
|
|
152
|
+
"win_rate",
|
|
153
|
+
"xml_validity",
|
|
154
|
+
]
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
"""Shared input handling for text, question-answering, retrieval and reasoning metrics."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from collections import Counter
|
|
6
|
+
from collections.abc import Mapping, Sequence
|
|
7
|
+
from typing import Any, Callable, TypeVar, Union
|
|
8
|
+
|
|
9
|
+
import numpy as np
|
|
10
|
+
|
|
11
|
+
from ..core.exceptions import InputValidationError
|
|
12
|
+
|
|
13
|
+
F = TypeVar("F", bound=Callable[..., Any])
|
|
14
|
+
|
|
15
|
+
Texts = Sequence[str]
|
|
16
|
+
References = Union[Sequence[str], Sequence[Sequence[str]]]
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def per_item(fn: F) -> F:
|
|
20
|
+
"""Mark a metric whose observations are whole items (texts, ranked lists, sample sets).
|
|
21
|
+
|
|
22
|
+
``bootstrap_ci``, ``compare`` and the paired tests then resample items as Python objects and never stratify
|
|
23
|
+
by value, so a corpus metric such as BLEU is recomputed on each resampled corpus."""
|
|
24
|
+
fn.__evalsuite_items__ = True # type: ignore[attr-defined]
|
|
25
|
+
return fn
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def _seq(x: Any, name: str) -> list[Any]:
|
|
29
|
+
if x is None:
|
|
30
|
+
raise InputValidationError(f"{name} is required but was None.")
|
|
31
|
+
if isinstance(x, (str, bytes)):
|
|
32
|
+
raise InputValidationError(f"{name} must be a list (one entry per example), not a single string.")
|
|
33
|
+
if isinstance(x, np.ndarray):
|
|
34
|
+
x = x.tolist()
|
|
35
|
+
items = list(x)
|
|
36
|
+
if not items:
|
|
37
|
+
raise InputValidationError(f"{name} is empty. Provide at least one example.")
|
|
38
|
+
return items
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def as_texts(x: Any, name: str) -> list[str]:
|
|
42
|
+
"""A list of strings, one per example."""
|
|
43
|
+
items = _seq(x, name)
|
|
44
|
+
for i, t in enumerate(items):
|
|
45
|
+
if not isinstance(t, str):
|
|
46
|
+
raise InputValidationError(f"{name}[{i}] must be a string; got {type(t).__name__}.")
|
|
47
|
+
return items
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def as_references(x: Any, n: int, name: str = "references") -> list[list[str]]:
|
|
51
|
+
"""References as one list of strings per example. Accepts one string per example or a list of strings per
|
|
52
|
+
example (multiple references)."""
|
|
53
|
+
items = _seq(x, name)
|
|
54
|
+
if len(items) != n:
|
|
55
|
+
raise InputValidationError(
|
|
56
|
+
f"{name} and predictions must contain the same number of examples. Received {len(items)} and {n}."
|
|
57
|
+
)
|
|
58
|
+
out: list[list[str]] = []
|
|
59
|
+
for i, r in enumerate(items):
|
|
60
|
+
refs = [r] if isinstance(r, str) else list(r) if isinstance(r, (list, tuple, np.ndarray)) else None
|
|
61
|
+
if refs is None or not refs or not all(isinstance(s, str) for s in refs):
|
|
62
|
+
raise InputValidationError(
|
|
63
|
+
f"{name}[{i}] must be a string or a non-empty list of strings (several references)."
|
|
64
|
+
)
|
|
65
|
+
out.append(refs)
|
|
66
|
+
return out
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
def word_ngrams(tokens: Sequence[str], n: int) -> Counter[tuple[str, ...]]:
|
|
70
|
+
"""Counts of the word n-grams of ``tokens`` (tuples built by ``zip`` over shifted slices, in C)."""
|
|
71
|
+
if n == 1:
|
|
72
|
+
return Counter(zip(tokens))
|
|
73
|
+
return Counter(zip(*(tokens[i:] for i in range(n))))
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
def check_positive_int(value: Any, name: str) -> int:
|
|
77
|
+
if isinstance(value, bool) or not isinstance(value, (int, np.integer)) or value < 1:
|
|
78
|
+
raise InputValidationError(f"{name} must be a positive integer; got {value!r}.")
|
|
79
|
+
return int(value)
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
def as_mapping_or_set(x: Any, name: str) -> Mapping[Any, float]:
|
|
83
|
+
"""Relevance judgements for one query: a set/list of relevant ids (all grade 1) or a mapping id -> grade."""
|
|
84
|
+
if isinstance(x, Mapping):
|
|
85
|
+
out = {}
|
|
86
|
+
for k, v in x.items():
|
|
87
|
+
g = float(v)
|
|
88
|
+
if not np.isfinite(g) or g < 0:
|
|
89
|
+
raise InputValidationError(
|
|
90
|
+
f"{name}: relevance grades must be finite and >= 0; got {v!r} for {k!r}."
|
|
91
|
+
)
|
|
92
|
+
if g > 0:
|
|
93
|
+
out[k] = g
|
|
94
|
+
return out
|
|
95
|
+
if isinstance(x, (str, bytes)):
|
|
96
|
+
raise InputValidationError(f"{name} must be a set, list or mapping of relevant ids, not a string.")
|
|
97
|
+
return {k: 1.0 for k in x}
|