Evaluators
Modules:
| Name | Description |
|---|---|
bertscore |
|
bleu |
|
g_eval |
|
qags |
|
rouge |
|
Classes:
| Name | Description |
|---|---|
BertScoreCalculator |
Compute BERTScore without silently discarding tokens from either text. |
BertScoreLengthError |
Input length cannot be scored within the model's declared context. |
BleuPrecisionScoreCalculator |
Legacy modified unigram precision calculator, without a brevity penalty. |
BleuScoreCalculator |
Unsmoothed sentence BLEU-4 for one complete prediction/reference pair. |
GEvalScoreCalculator |
G-Eval with complete, in-range integer responses. |
GEvalScorerFactory |
Scorer factory for G-Eval. |
QagsConfig |
Configuration for EvalSense's QAGS QA agreement metric. |
QagsScoreCalculator |
QAGS score calculator with strict answer validation. |
QagsScorerFactory |
Scorer factory for the QAGS QA agreement metric. |
QagsValidationError |
Generated questions or answers cannot support a valid score. |
RougeScoreCalculator |
Calculator for computing ROUGE scores. |
Functions:
| Name | Description |
|---|---|
bleu_metric |
Base metric for BLEU scores. |
get_bertscore_evaluator |
Returns a BERTScore evaluator. |
get_bleu_evaluator |
Return sentence BLEU-4 scores with a separately labelled corpus BLEU metric. |
get_g_eval_evaluator |
Constructs a G-Eval evaluator that can be used in EvalSense evaluation pipeline. |
get_qags_evaluator |
Constructs a QAGS evaluator for EvalSense. |
get_rouge_evaluator |
Returns an evaluator for ROUGE scores. |
BertScoreCalculator
Bases: ScoreCalculator
Compute BERTScore without silently discarding tokens from either text.
Prediction and reference lengths are checked separately, including special tokens, before embedding computation. Counting follows BERTScore's tokenizer, surrounding-whitespace and prefix-space handling with truncation disabled. The smallest finite tokenizer/configuration limit applies. Overlength inputs raise BertScoreLengthError with counts, never the input text or a partial score.
XLNet explicitly declares no fixed positional limit. When its tokenizer also has no finite bound, the complete inputs are passed to BERTScore without an arbitrary cap. A finite tokenizer limit still applies. Missing declarations in other configurations remain errors; a large tokenizer sentinel alone is not evidence that the model supports arbitrary lengths.
Use the default slow tokenizer for unbounded XLNet with BERTScore 0.3.13: that backend passes the large length sentinel to fast tokenizers, which can overflow. Tokenizer/backend errors propagate without producing a score. No fixed positional limit does not guarantee enough memory or reliable long-document scores; validate the chosen model on the intended task.
Within-limit scores and hash metadata are unchanged. The validation context is loaded lazily, keeps only the current model/tokenizer setting, and is reset on cleanup. This calculator does not truncate, segment documents or average chunk scores. Increasing batch_size does not extend the context limit.
This per-sample implementation rejects IDF weighting because corpus weights cannot be estimated from a single reference. Only idf=False is supported.
Methods:
| Name | Description |
|---|---|
__init__ |
Initializes the BERTScore calculator. |
calculate |
Calculates BERTScore for the supplied model prediction and reference input. |
calculate_async |
Calculates BERTScore for the supplied model prediction and reference input. |
Source code in evalsense/evaluation/evaluators/bertscore.py
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 | |
__init__
__init__(
model_type: str = "microsoft/deberta-xlarge-mnli",
lang: str = "en",
num_layers: int | None = None,
idf: bool = False,
)
Initializes the BERTScore calculator.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_type
|
str
|
The model type to use for computing BERTScore. Defaults to "microsoft/deberta-xlarge-mnli", the currently best-performing model according to BERTScore authors. |
'microsoft/deberta-xlarge-mnli'
|
lang
|
str
|
The language of the text. Defaults to "en". |
'en'
|
num_layers
|
int
|
The layer of representations to use. |
None
|
idf
|
bool
|
Must be False. Estimating IDF from a single reference is invalid, and the Evaluate backend does not use supplied IDF dictionaries as fixed weights. Defaults to False. |
False
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If idf is not False. No metric or model is loaded in that case. |
Source code in evalsense/evaluation/evaluators/bertscore.py
calculate
calculate(
*,
prediction: str,
input: str | None = None,
reference: str | None = None,
metadata: dict[str, Any] | None = None,
verbose=False,
device=None,
batch_size=64,
nthreads=1,
rescale_with_baseline=False,
baseline_path=None,
use_fast_tokenizer=False,
**kwargs,
) -> Score
Calculates BERTScore for the supplied model prediction and reference input.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prediction
|
str
|
The text of the prediction from the model. |
required |
input
|
str
|
The text of the model input. Ignored for BERTScore. |
None
|
reference
|
str
|
The text of the reference input to compare against. |
None
|
metadata
|
dict[str, Any]
|
Metadata for the evaluation. Ignored for BERTScore. |
None
|
verbose
|
bool
|
Whether to turn on verbose mode. |
False
|
device
|
str
|
The device to use for computing the contextual embeddings. |
None
|
batch_size
|
int
|
The batch size to use for computing the contextual embeddings. |
64
|
nthreads
|
int
|
The number of threads to use for computing the contextual embeddings. |
1
|
rescale_with_baseline
|
bool
|
Whether to rescale the BERTScore with pre-computed baseline. |
False
|
baseline_path
|
str
|
Customized baseline file. |
None
|
use_fast_tokenizer
|
bool
|
The |
False
|
Raises:
| Type | Description |
|---|---|
BertScoreLengthError
|
If either input exceeds the declared context or its length capability is unknown. XLNet's explicit no-fixed-limit declaration is supported. No partial score is returned. |
Returns:
| Name | Type | Description |
|---|---|---|
Score |
Score
|
Inspect AI Score with the calculated evaluation results. |
Source code in evalsense/evaluation/evaluators/bertscore.py
186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 | |
calculate_async
async
calculate_async(
*,
prediction: str,
input: str | None = None,
reference: str | None = None,
metadata: dict[str, Any] | None = None,
verbose=False,
device=None,
batch_size=64,
nthreads=1,
rescale_with_baseline=False,
baseline_path=None,
use_fast_tokenizer=False,
**kwargs,
) -> Score
Calculates BERTScore for the supplied model prediction and reference input.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prediction
|
str
|
The text of the prediction from the model. |
required |
input
|
str | None
|
The text of the model input. Ignored for BERTScore. |
None
|
reference
|
str
|
The text of the reference input to compare against. |
None
|
metadata
|
dict[str, Any] | None
|
Metadata for the evaluation. Ignored for BERTScore. |
None
|
verbose
|
bool
|
Whether to turn on verbose mode. |
False
|
device
|
str | None
|
The device to use for computing the contextual embeddings. |
None
|
batch_size
|
int
|
The batch size to use for computing the contextual embeddings. |
64
|
nthreads
|
int
|
The number of threads to use for computing the contextual embeddings. |
1
|
rescale_with_baseline
|
bool
|
Whether to rescale the BERTScore with pre-computed baseline. |
False
|
baseline_path
|
str | None
|
Customized baseline file. |
None
|
use_fast_tokenizer
|
bool
|
The |
False
|
Raises:
| Type | Description |
|---|---|
BertScoreLengthError
|
If either input exceeds the declared context or its length capability is unknown. XLNet's explicit no-fixed-limit declaration is supported. No partial score is returned. |
Returns:
| Name | Type | Description |
|---|---|---|
Score |
Score
|
Inspect AI Score with the calculated evaluation results. |
Source code in evalsense/evaluation/evaluators/bertscore.py
BertScoreLengthError
BleuPrecisionScoreCalculator
Bases: ScoreCalculator
Legacy modified unigram precision calculator, without a brevity penalty.
Retained for direct callers. The BLEU evaluator uses BleuScoreCalculator; unigram precision must not be interpreted as sentence or corpus BLEU.
Methods:
| Name | Description |
|---|---|
calculate |
Calculates modified unigram precision, not BLEU, for one text pair. |
calculate_async |
Asynchronously call this calculator's calculate method with the same inputs. |
Source code in evalsense/evaluation/evaluators/bleu.py
calculate
calculate(
*,
prediction: str,
input: str | None = None,
reference: str | None = None,
metadata: dict[str, Any] | None = None,
**kwargs,
) -> Score
Calculates modified unigram precision, not BLEU, for one text pair.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prediction
|
str
|
The text of the prediction from the model. |
required |
input
|
str
|
The text of the input to the model. Ignored for BLEU. |
None
|
reference
|
str
|
The text of the reference input to compare against. |
None
|
metadata
|
dict[str, Any]
|
Additional metadata for the score. Ignored for BLEU. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
Score |
Score
|
Inspect AI Score with the calculated evaluation results. |
Source code in evalsense/evaluation/evaluators/bleu.py
calculate_async
async
calculate_async(
*,
prediction: str,
input: str | None = None,
reference: str | None = None,
metadata: dict[str, Any] | None = None,
**kwargs,
) -> Score
Asynchronously call this calculator's calculate method with the same inputs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prediction
|
str
|
The text of the prediction from the model. |
required |
input
|
str
|
The text of the input to the model. Ignored for BLEU. |
None
|
reference
|
str
|
The text of the reference input to compare against. |
None
|
metadata
|
dict[str, Any]
|
Additional metadata for the score. Ignored for BLEU. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
Score |
Score
|
Inspect AI Score with the calculated evaluation results. |
Source code in evalsense/evaluation/evaluators/bleu.py
BleuScoreCalculator
Bases: BleuPrecisionScoreCalculator
Unsmoothed sentence BLEU-4 for one complete prediction/reference pair.
Uses Evaluate's BLEU backend and its default case-sensitive 13a tokenizer,
uniform weights over n-gram orders 1 through 4, and the brevity penalty.
Score.value is result["bleu"], not unigram precision. Scores are in
[0, 1]. No smoothing or effective-order adjustment is applied: missing any
n-gram order, including predictions shorter than four tokens, gives zero.
Such short samples provide little information for correlation analyses.
Corpus BLEU recomputes pooled n-gram counts and the corpus brevity penalty; it is not the mean of these sentence scores. Original texts are retained in score metadata for that calculation. Sync and async calls use the same policy.
Methods:
| Name | Description |
|---|---|
calculate |
Compute the backend's BLEU-4 value for a single text pair. |
calculate_async |
Asynchronously call this calculator's calculate method with the same inputs. |
Source code in evalsense/evaluation/evaluators/bleu.py
calculate
calculate(
*,
prediction: str,
input: str | None = None,
reference: str | None = None,
metadata: dict[str, Any] | None = None,
**kwargs,
) -> Score
Compute the backend's BLEU-4 value for a single text pair.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prediction
|
str
|
Complete generated text. |
required |
input
|
str | None
|
Unused source text. |
None
|
reference
|
str | None
|
Required reference text. |
None
|
metadata
|
dict[str, Any] | None
|
Unused sample metadata. |
None
|
**kwargs
|
Any
|
Unused arguments accepted by ScoreCalculator. |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
Score |
Score
|
Sentence BLEU with input texts and the score definition recorded. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If a reference is missing or either text is blank. Backend errors propagate; no fallback score is returned. |
Source code in evalsense/evaluation/evaluators/bleu.py
calculate_async
async
calculate_async(
*,
prediction: str,
input: str | None = None,
reference: str | None = None,
metadata: dict[str, Any] | None = None,
**kwargs,
) -> Score
Asynchronously call this calculator's calculate method with the same inputs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prediction
|
str
|
The text of the prediction from the model. |
required |
input
|
str
|
The text of the input to the model. Ignored for BLEU. |
None
|
reference
|
str
|
The text of the reference input to compare against. |
None
|
metadata
|
dict[str, Any]
|
Additional metadata for the score. Ignored for BLEU. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
Score |
Score
|
Inspect AI Score with the calculated evaluation results. |
Source code in evalsense/evaluation/evaluators/bleu.py
GEvalScoreCalculator
Bases: ScoreCalculator
G-Eval with complete, in-range integer responses.
Weighted mode requires one output token and complete rating evidence in the returned alternatives. Failures never fall back to a sampled rating. Syntax validation does not establish judge accuracy or injection resistance.
Methods:
| Name | Description |
|---|---|
__init__ |
Initializes the G-Eval score calculator. |
calculate |
This method is not supported for G-Eval and will raise an error when called. |
calculate_async |
Calculates the G-Eval score asynchronously. |
Source code in evalsense/evaluation/evaluators/g_eval.py
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 | |
__init__
__init__(
model: Model,
prompt_template: str,
logprobs: bool = True,
top_logprobs: int = 20,
min_score: int = 1,
max_score: int = 10,
normalise: bool = True,
debug: bool = False,
)
Initializes the G-Eval score calculator.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
Model
|
The model to use for evaluation. |
required |
prompt_template
|
str
|
The prompt template with the scoring instructions. |
required |
logprobs
|
bool
|
Use a one-token conditional mean over reported valid rating alternatives. Every allowed rating must be present; missing or inconsistent evidence raises ValueError. False uses the sampled integer without a one-token limit. |
True
|
top_logprobs
|
int
|
Positive integer alternative count, at least the number of allowed ratings in weighted mode. Providers may impose their own limit or omit low-probability ratings. |
20
|
min_score
|
int
|
The minimum valid score. |
1
|
max_score
|
int
|
The maximum valid score. |
10
|
normalise
|
bool
|
Whether to normalise the scores between 0 and 1. |
True
|
debug
|
bool
|
Retained for compatibility. Weighting failures always raise. |
False
|
Source code in evalsense/evaluation/evaluators/g_eval.py
calculate
calculate(
*,
prediction: str,
input: str | None = None,
reference: str | None = None,
metadata: dict[str, Any] | None = None,
**kwargs,
) -> Score
This method is not supported for G-Eval and will raise an error when called.
Use calculate_async instead.
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
When called, as synchronous evaluation is not supported for G-Eval. |
Source code in evalsense/evaluation/evaluators/g_eval.py
calculate_async
async
calculate_async(
*,
prediction: str,
input: str | None = None,
reference: str | None = None,
metadata: dict[str, Any] | None = None,
**kwargs,
) -> Score
Calculates the G-Eval score asynchronously.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prediction
|
str
|
The predicted output to evaluate. |
required |
input
|
str | None
|
The input text for the model. Defaults to |
None
|
reference
|
str | None
|
The reference text for the model. Defaults to |
None
|
metadata
|
dict[str, Any] | None
|
Additional metadata for the evaluation.
Defaults to |
None
|
**kwargs
|
Additional keyword arguments. |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
Score |
Score
|
The calculated score. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If settings, the complete integer response or weighted token evidence are invalid. Failed weighting never returns a sampled score, and malformed responses are never repaired. |
Source code in evalsense/evaluation/evaluators/g_eval.py
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 | |
GEvalScorerFactory
Bases: ScorerFactory
Scorer factory for G-Eval.
Methods:
| Name | Description |
|---|---|
__init__ |
Initialize the G-Eval scorer factory. |
create_scorer |
Creates a G-Eval scorer. |
Source code in evalsense/evaluation/evaluators/g_eval.py
206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 | |
__init__
__init__(
name: str,
prompt_template: str,
metrics: list[Metric | dict[str, list[Metric]]]
| dict[str, list[Metric]]
| None = None,
logprobs: bool = True,
top_logprobs: int = 20,
min_score: int = 1,
max_score: int = 10,
normalise: bool = True,
debug: bool = False,
)
Initialize the G-Eval scorer factory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name of the scorer. |
required |
prompt_template
|
str
|
The prompt template with the scoring instructions. |
required |
metrics
|
list[Metric | dict[str, list[Metric]]] | dict[str, list[Metric]] | None
|
The metrics to use for the evaluation. If |
None
|
logprobs
|
bool
|
Use a one-token conditional mean over reported valid rating alternatives. Every allowed rating must be present; missing or inconsistent evidence raises ValueError. False uses the sampled integer without a one-token limit. |
True
|
top_logprobs
|
int
|
Positive integer alternative count, at least the number of allowed ratings in weighted mode. Providers may impose their own limit or omit low-probability ratings. |
20
|
min_score
|
int
|
The minimum valid score. |
1
|
max_score
|
int
|
The maximum valid score. |
10
|
normalise
|
bool
|
Whether to normalise the scores between 0 and 1. |
True
|
debug
|
bool
|
Retained for compatibility. Weighting failures always raise. |
False
|
Source code in evalsense/evaluation/evaluators/g_eval.py
create_scorer
Creates a G-Eval scorer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
Model
|
The model to create a scorer for. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Scorer |
Scorer
|
The created G-Eval scorer. |
Source code in evalsense/evaluation/evaluators/g_eval.py
QagsConfig
Bases: Protocol
Configuration for EvalSense's QAGS QA agreement metric.
EvalSense adapts Wang et al. (2020) by generating questions from both texts and supporting ternary, exact-match and LLM-judge comparisons. It does not use the original answer-conditioned question filtering. The EvalSense paper reports a clinical-note case study and meta-evaluation of the ternary and judge variants. Suitability still depends on the task, prompts and judge.
Prompts choose whether the comparison uses a reference note or source text; agreement with a reference note does not independently check its source.
Methods:
| Name | Description |
|---|---|
__init__ |
Initializes the QAGS configuration. |
enforce_not_none |
Helper method to enforce that a parameter is not None. |
get_answer_comparison_prompt |
Constructs the prompt for comparing answers to the generated questions. |
get_answer_generation_prompt |
Constructs the prompt for generating the answer to a single question. |
get_question_generation_prompt |
Constructs the prompt for generating the questions for the model output. |
Source code in evalsense/evaluation/evaluators/qags.py
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 | |
__init__
__init__(
answer_comparison_mode: Literal[
"ternary", "exact", "judge"
],
logprobs: bool = True,
top_logprobs: int = 20,
ci: float = 0.1,
debug: bool = False,
)
Initializes the QAGS configuration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
answer_comparison_mode
|
Literal['ternary', 'exact', 'judge']
|
The mode for comparing answers. Either "ternary", "exact", or "judge". In "ternary" mode, the model is expected to answer the generated questions with "yes", "no", or "unknown". In other modes, the model may give arbitrary answers, which are either compared in terms of exact match or compared by the model itself. |
required |
logprobs
|
bool
|
Whether to use logprobs to compute weighted answers. Can only
be used when |
True
|
top_logprobs
|
int
|
The number of top log probabilities to consider when computing weighted answers. |
20
|
ci
|
float
|
The range near the extreme values (0.0 or 1.0) in which
to consider the model answer as confident when comparing answers.
This only affects the score explanation when |
0.1
|
debug
|
bool
|
Whether to report repeated errors in the log. |
False
|
Source code in evalsense/evaluation/evaluators/qags.py
enforce_not_none
Helper method to enforce that a parameter is not None.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
param_name
|
str
|
The name of the parameter. |
required |
param_value
|
T | None
|
The value of the parameter. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the parameter value is None. |
Returns:
| Name | Type | Description |
|---|---|---|
T |
T
|
The parameter value if it is not None. |
Source code in evalsense/evaluation/evaluators/qags.py
get_answer_comparison_prompt
get_answer_comparison_prompt(
*,
question: str,
prediction_answer: str,
reference_answer: str,
input: str | None = None,
prediction: str | None = None,
reference: str | None = None,
metadata: dict[str, Any] | None = None,
) -> str
Constructs the prompt for comparing answers to the generated questions.
This method is only used when answer_comparison_mode is set to "judge".
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
question
|
str
|
The question to compare answers for. |
required |
prediction_answer
|
str
|
The answer generated from the model output. |
required |
reference_answer
|
str
|
The answer generated from the reference output. |
required |
input
|
str | None
|
The input to the model. Optional. |
None
|
prediction
|
str | None
|
The model output to evaluate. Optional. |
None
|
reference
|
str | None
|
The reference output to compare against. Optional. |
None
|
metadata
|
dict[str, Any] | None
|
Additional Inspect AI sample/task state metadata. Optional. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The generated prompt. |
Source code in evalsense/evaluation/evaluators/qags.py
get_answer_generation_prompt
abstractmethod
get_answer_generation_prompt(
*,
source: Literal["prediction", "reference"],
question: str,
prediction: str | None = None,
input: str | None = None,
reference: str | None = None,
metadata: dict[str, Any] | None = None,
) -> str
Constructs the prompt for generating the answer to a single question.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
Literal['prediction', 'reference']
|
The source to use for
generating the answer. Either "prediction" or "reference".
According to the source, the generated prompt should either use
the model output or the reference output/input when asking
the model to answer the question. When |
required |
prediction
|
str
|
The model output to evaluate. |
None
|
input
|
str
|
The input to the model. Optional. |
None
|
reference
|
str
|
The reference output to compare against. Optional. |
None
|
metadata
|
dict[str, Any]
|
Additional Inspect AI sample/task state metadata. Optional. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The generated prompt. |
Source code in evalsense/evaluation/evaluators/qags.py
get_question_generation_prompt
abstractmethod
get_question_generation_prompt(
*,
source: Literal["prediction", "reference"],
prediction: str,
input: str | None = None,
reference: str | None = None,
metadata: dict[str, Any] | None = None,
) -> str
Constructs the prompt for generating the questions for the model output.
The prompt should instruct the model to generate one question per line,
ending in exactly one question mark and containing a letter or digit.
Recognised list prefixes are removed using strip_list_prefix;
Unicode is normalised to NFC and surrounding whitespace is trimmed.
Text-identical questions are scored once across both sources in their
first-occurrence order. Case, internal whitespace, decimals and signed
numerical values are preserved. Filtering checks syntax, not relevance.
An empty retained set raises QagsValidationError before any QA calls.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
Literal['prediction', 'reference']
|
The source to use for
generating the questions. Either "prediction" or "reference".
According to the source, the generated prompt should either use
the model output or the reference output/input. When
|
required |
prediction
|
str
|
The model output to evaluate. |
required |
input
|
str
|
The input to the model. Optional. |
None
|
reference
|
str
|
The reference output to compare against. Optional. |
None
|
metadata
|
dict[str, Any]
|
Additional Inspect AI sample/task state metadata. Optional. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The generated prompt. |
Source code in evalsense/evaluation/evaluators/qags.py
QagsScoreCalculator
Bases: ScoreCalculator
QAGS score calculator with strict answer validation.
Each unique question has equal weight within a document. Both texts must supply exactly one nonempty answer per question in every comparison mode. Raw question outputs, retained questions and their source(s), answer outputs, and counts of candidate, invalid, duplicate and retained question lines are recorded in score metadata. Deduplication is textual, not semantic.
Ternary and judge-comparison labels use parse_ternary_answer from
evalsense.utils.text. It validates the whole response, allowing one
balanced formatting wrapper and optional terminal punctuation. Explicit
unknown remains distinct from malformed text; judge comparisons must be
binary. Errors are translated to QagsValidationError without echoing text.
Ternary Accuracy is the fraction of equal labels, including unknown/unknown. Such agreement is not factual evidence. Coverage and Groundedness are the number of yes/yes matches divided by reference yes answers and prediction yes answers, respectively, or zero when the corresponding denominator is empty. These positive-answer ratios depend on question polarity and do not measure all correctly preserved negative facts (see issue #57).
Exact mode averages case-insensitive, whitespace-trimmed text matches; formatting wrappers are not stripped from free-text answers. Judge mode averages binary comparisons or the existing probability-weighted values. Weighting failures retain the existing logged binary fallback. Judge calibration and log-probability handling are unchanged.
Invalid or incomplete answers raise QagsValidationError. They are neither counted as unknown nor dropped from the question denominator. There are no automatic format retries. In the current pipeline, a scoring exception marks the affected evaluation as failed; other evaluations may continue. Report failures alongside completed scores.
Successful scores include evaluation_protocol="evalsense.qags-derived.v2",
comparison mode, question-weighting policy and invalid-answer policy. The
factory defaults to mean aggregation across document scores. Changing the
validation or question set changes the evaluated protocol; regression tests
check implementation behavior, not clinical validity.
Methods:
| Name | Description |
|---|---|
__init__ |
Initializes the QAGS score calculator. |
calculate |
This method is not supported for QAGS and will raise an error when called. |
calculate_async |
Asynchronously computes evaluation scores for QAGS. |
Attributes:
| Name | Type | Description |
|---|---|---|
generate_config |
GenerateConfig
|
Generation configuration for the model. |
Source code in evalsense/evaluation/evaluators/qags.py
277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 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 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 | |
__init__
Initializes the QAGS score calculator.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
Model
|
The model to use for evaluation. |
required |
config
|
QagsConfig
|
The configuration for the QAGS score calculator. |
required |
name
|
str
|
The name of the score calculator. Defaults to "QAGS". |
'QAGS'
|
debug
|
bool
|
Whether to report repeated errors in the log. |
False
|
Source code in evalsense/evaluation/evaluators/qags.py
calculate
calculate(
*,
prediction: str,
input: str | None = None,
reference: str | None = None,
metadata: dict[str, Any] | None = None,
**kwargs: dict,
) -> Score
This method is not supported for QAGS and will raise an error when called.
Use calculate_async instead.
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
When called, as synchronous evaluation is not supported for QAGS. |
Source code in evalsense/evaluation/evaluators/qags.py
calculate_async
async
calculate_async(
*,
prediction: str,
input: str | None = None,
reference: str | None = None,
metadata: dict[str, Any] | None = None,
**kwargs: dict,
) -> Score
Asynchronously computes evaluation scores for QAGS.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prediction
|
str
|
The model output to evaluate. |
required |
input
|
str
|
The input to the model. Optional. |
None
|
reference
|
str
|
The reference output to compare against. Optional. |
None
|
metadata
|
dict[str, Any]
|
Additional Inspect AI sample/task state metadata. Optional. |
None
|
**kwargs
|
dict
|
Additional keyword arguments specific to the given evaluation method. |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
Score |
Score
|
The Inspect AI Score object with the calculated result. |
Source code in evalsense/evaluation/evaluators/qags.py
858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 | |
QagsScorerFactory
Bases: ScorerFactory
Scorer factory for the QAGS QA agreement metric.
Methods:
| Name | Description |
|---|---|
__init__ |
Initialize the QAGS scorer factory. |
create_scorer |
Creates a QAGS scorer. |
Source code in evalsense/evaluation/evaluators/qags.py
__init__
__init__(
name: str,
config: QagsConfig,
metrics: list[Metric | dict[str, list[Metric]]]
| dict[str, list[Metric]]
| None = None,
)
Initialize the QAGS scorer factory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
QagsConfig
|
The configuration for the QAGS scorer. |
required |
metrics
|
list[Metric | dict[str, list[Metric]]] | dict[str, list[Metric]] | None
|
The metrics to use for the evaluation. If |
None
|
Source code in evalsense/evaluation/evaluators/qags.py
create_scorer
Creates a QAGS scorer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
Model
|
The model to create a scorer for. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Scorer |
Scorer
|
The created QAGS scorer. |
Source code in evalsense/evaluation/evaluators/qags.py
QagsValidationError
RougeScoreCalculator
Bases: ScoreCalculator
Calculator for computing ROUGE scores.
Methods:
| Name | Description |
|---|---|
calculate |
Calculates ROUGE scores for the supplied model prediction and reference input. |
calculate_async |
Calculates ROUGE scores for the supplied model prediction and reference input. |
Source code in evalsense/evaluation/evaluators/rouge.py
calculate
calculate(
*,
prediction: str,
input: str | None = None,
reference: str | None = None,
metadata: dict[str, Any] | None = None,
**kwargs: dict,
) -> Score
Calculates ROUGE scores for the supplied model prediction and reference input.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prediction
|
str
|
The text of the prediction from the model. |
required |
input
|
str
|
The text of the input to the model. Ignored for ROUGE. |
None
|
reference
|
str
|
The text of the reference input to compare against. |
None
|
metadata
|
dict[str, Any]
|
Additional metadata for the score. Ignored for ROUGE. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
Score |
Score
|
Inspect AI Score with the calculated evaluation results. |
Source code in evalsense/evaluation/evaluators/rouge.py
calculate_async
async
calculate_async(
*,
prediction: str,
input: str | None = None,
reference: str | None = None,
metadata: dict[str, Any] | None = None,
**kwargs: dict,
) -> Score
Calculates ROUGE scores for the supplied model prediction and reference input.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prediction
|
str
|
The text of the prediction from the model. |
required |
input
|
str
|
The text of the input to the model. Ignored for ROUGE. |
None
|
reference
|
str
|
The text of the reference input to compare against. |
None
|
metadata
|
dict[str, Any]
|
Additional metadata for the score. Ignored for ROUGE. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
Score |
Score
|
Inspect AI Score with the calculated evaluation results. |
Source code in evalsense/evaluation/evaluators/rouge.py
bleu_metric
Base metric for BLEU scores.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
implementation
|
MetricImplementation | None
|
Pinned implementation shared with the sample scorer. Defaults to the supported BLEU implementation. |
None
|
Rejects input scores with absent or different implementation provenance. Historical scores must be rescored before recomputing this corpus metric.
Returns:
| Name | Type | Description |
|---|---|---|
MetricProtocol |
MetricProtocol
|
A function that computes BLEU scores. |
Source code in evalsense/evaluation/evaluators/bleu.py
get_bertscore_evaluator
get_bertscore_evaluator(
*,
name: str = "BERTScore",
metrics: list[Metric | dict[str, list[Metric]]]
| dict[str, list[Metric]]
| None = None,
model_type: str = "microsoft/deberta-xlarge-mnli",
lang: str = "en",
num_layers: int | None = None,
verbose: bool = False,
idf: bool = False,
device: str | None = None,
batch_size: int = 64,
nthreads: int = 1,
rescale_with_baseline: bool = False,
baseline_path: str | None = None,
use_fast_tokenizer: bool = False,
version: str | None = None,
) -> Evaluator
Returns a BERTScore evaluator.
Both texts are checked against any finite tokenizer/model limit, including special tokens. XLNet's explicit no-fixed-limit declaration is supported; unknown configurations still fail. See BertScoreCalculator for the length policy and backend constraints. No automatic truncation is performed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name of the evaluator and scorer. Defaults to "BERTScore". |
'BERTScore'
|
metrics
|
list[Metric | dict[str, list[Metric]]] | dict[str, list[Metric]] | None
|
The metrics to use for the evaluation. If |
None
|
model_type
|
str
|
The model type to use for computing BERTScore. Defaults to "microsoft/deberta-xlarge-mnli", the currently best-performing model according to BERTScore authors. |
'microsoft/deberta-xlarge-mnli'
|
lang
|
str
|
The language of the text. Defaults to "en". |
'en'
|
num_layers
|
int | None
|
The layer of representations to use. The
default is the number of layers tuned on WMT16 correlation data, which
depends on the |
None
|
verbose
|
bool
|
Whether to turn on verbose mode. Defaults to |
False
|
idf
|
bool
|
Must be False because this evaluator scores one sample at a time. Automatic IDF and precomputed IDF dictionaries are unsupported. Defaults to False (no IDF weighting). |
False
|
device
|
str | None
|
The device to use for computing the contextual
embeddings. If this argument is not set or |
None
|
nthreads
|
int
|
The number of threads to use for computing the
contextual embeddings. Defaults to |
1
|
batch_size
|
int
|
The batch size to use for computing the
contextual embeddings. Defaults to |
64
|
rescale_with_baseline
|
bool
|
Whether to rescale the BERTScore with
pre-computed baseline. The default value is |
False
|
baseline_path
|
str | None
|
Customized baseline file. |
None
|
use_fast_tokenizer
|
bool
|
The |
False
|
version
|
str | None
|
Cache version for custom code or external resources. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
Evaluator |
Evaluator
|
The BERTScore evaluator. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If idf is not False. Use a corpus-aware BERTScore scorer when IDF weighting is required. |
Source code in evalsense/evaluation/evaluators/bertscore.py
323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 | |
get_bleu_evaluator
get_bleu_evaluator(
name: str = "BLEU",
scorer_name: str = "Sentence BLEU",
metrics: list[Metric | dict[str, list[Metric]]]
| dict[str, list[Metric]]
| None = None,
*,
version: str | None = None,
) -> Evaluator
Return sentence BLEU-4 scores with a separately labelled corpus BLEU metric.
Correlation and meta-evaluation consume unsmoothed sentence BLEU-4. The default
aggregate is <name> (corpus), recomputed from the input texts; it is not a
mean sentence score. Supply metrics=[mean()] to request the latter instead.
See BleuScoreCalculator for tokenization and short-input behavior.
Re-score under a fresh evaluator name or project when migrating from legacy unigram scores. Existing cached logs are not converted or invalidated here.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The evaluator name and prefix for the corpus metric. Defaults to "BLEU". |
'BLEU'
|
scorer_name
|
str
|
The name of the internal scorer. Defaults to "Sentence BLEU". |
'Sentence BLEU'
|
metrics
|
list[Metric | dict[str, list[Metric]]] | dict[str, list[Metric]] | None
|
The metrics to use for the evaluation. If |
None
|
version
|
str | None
|
Cache version for custom code or external resources. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
Evaluator |
Evaluator
|
An evaluator for BLEU scores. |
Source code in evalsense/evaluation/evaluators/bleu.py
get_g_eval_evaluator
get_g_eval_evaluator(
*,
name: str = "G-Eval",
quality_name: str = "Unknown",
model_name: str | None = None,
metrics: list[Metric | dict[str, list[Metric]]]
| dict[str, list[Metric]]
| None = None,
prompt_template: str,
model_config: ModelConfig,
logprobs: bool = True,
top_logprobs: int = 20,
min_score: int = 1,
max_score: int = 10,
normalise: bool = True,
debug: bool = False,
version: str | None = None,
) -> Evaluator
Constructs a G-Eval evaluator that can be used in EvalSense evaluation pipeline.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name of the evaluator. Defaults to "G-Eval". |
'G-Eval'
|
quality_name
|
str
|
The name of the quality to be evaluated by G-Eval. |
'Unknown'
|
model_name
|
str | None
|
The name of the model to be used for evaluation.
If |
None
|
metrics
|
list[Metric | dict[str, list[Metric]]] | dict[str, list[Metric]] | None
|
The metrics to use for the evaluation. If |
None
|
prompt_template
|
str
|
The prompt template to use. The supplied template should be a format string with {prediction} and (optionally) {reference} as placeholders, as well as any additional placeholders for entries in Inspect AI sample/task state metadata. The template should instruct the judge model to return only one non-negative integer between min_score and max_score. Fractions, decimals, signs and explanatory text fail validation. Outer whitespace is accepted. Leading zeroes are accepted only when logprobs=False; weighted mode requires canonical labels. |
required |
model_config
|
ModelConfig
|
The model configuration. |
required |
logprobs
|
bool
|
Use a one-token conditional mean over reported valid rating alternatives, requiring evidence for every allowed rating. Missing evidence raises ValueError without a sampled-score fallback. False explicitly uses the sampled integer. |
True
|
top_logprobs
|
int
|
Positive integer alternative count, at least the number of allowed ratings in weighted mode. This budget does not guarantee the provider returns every rating. |
20
|
min_score
|
int
|
The minimum valid score. |
1
|
max_score
|
int
|
The maximum valid score. |
10
|
normalise
|
bool
|
Whether to normalise the scores between 0 and 1. |
True
|
debug
|
bool
|
Retained for compatibility. Weighting failures always raise. |
False
|
version
|
str | None
|
Cache version for custom code or external resources. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
Evaluator |
Evaluator
|
The constructed G-Eval evaluator. Cache identity includes the estimator format and, for weighted mode, the weighting policy. |
Source code in evalsense/evaluation/evaluators/g_eval.py
296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 | |
get_qags_evaluator
get_qags_evaluator(
*,
config: QagsConfig,
name: str = "QAGS",
model_name: str | None = None,
metrics: list[Metric | dict[str, list[Metric]]]
| dict[str, list[Metric]]
| None = None,
model_config: ModelConfig,
version: str | None = None,
) -> Evaluator
Constructs a QAGS evaluator for EvalSense.
The configured prompts select the two comparison texts and question types. See QagsConfig for the method and QagsScoreCalculator for score definitions, accepted formats and failure behavior. The protocol is recorded in score metadata. Migration requirements are in the changelog.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
QagsConfig
|
The configuration for the QAGS evaluator. |
required |
name
|
str
|
The name of the QAGS evaluator. |
'QAGS'
|
model_name
|
str | None
|
The name of the model to use for evaluation.
If |
None
|
metrics
|
list[Metric | dict[str, list[Metric]]] | dict[str, list[Metric]] | None
|
The metrics to use for the evaluation. If |
None
|
model_config
|
ModelConfig
|
The configuration of the model to be used for evaluation. |
required |
version
|
str | None
|
Cache version for custom code or external resources. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
Evaluator |
Evaluator
|
The constructed QAGS evaluator. |
Source code in evalsense/evaluation/evaluators/qags.py
get_rouge_evaluator
get_rouge_evaluator(
name: str = "ROUGE",
metrics: list[Metric | dict[str, list[Metric]]]
| dict[str, list[Metric]]
| None = None,
*,
version: str | None = None,
) -> Evaluator
Returns an evaluator for ROUGE scores.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name of the evaluator. Defaults to "ROUGE". |
'ROUGE'
|
metrics
|
list[Metric | dict[str, list[Metric]]] | dict[str, list[Metric]] | None
|
The metrics to use for evaluation. If None, defaults to ROUGE-1, ROUGE-2, and ROUGE-L with mean aggregation. |
None
|
version
|
str | None
|
Cache version for custom code or external resources. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
Evaluator |
Evaluator
|
An evaluator for ROUGE scores. |
Source code in evalsense/evaluation/evaluators/rouge.py
G-Eval rating responses
EvalSense requires one complete non-negative decimal integer in the configured
rating range. Outer whitespace is allowed. Sampled ratings also accept leading
zeroes; weighted ratings require canonical labels such as 8, without zero
padding. Fractions, decimals, signs, JSON or Markdown wrappers, and explanatory
text are rejected.
For a 1–10 scale, 8 is valid; 0/10, -3, 8.5 and
Rating scale 1 to 10. Final rating 9 all raise ValueError.
The endpoints must be non-negative integers with min_score <= max_score.
Normalisation also requires min_score < max_score. For sampled ratings,
normalisation uses (rating - min_score) / (max_score - min_score); on a 1–10
scale, 1 becomes 0, 10 becomes 1, and 8 becomes 7/9. With normalise=False, the
validated integer is returned unchanged.
For example, configure a sampled-rating evaluator as follows. The mock model name is an offline placeholder; select the intended judge provider for a real run.
from evalsense.evaluation.evaluators import get_g_eval_evaluator
from evalsense.generation import ModelConfig
evaluator = get_g_eval_evaluator(
prompt_template=(
"Rate the candidate from 1 to 10. Return only the integer, "
"without a denominator, sign or explanation. Candidate: {prediction}"
),
model_config=ModelConfig("mockllm/judge"),
min_score=1,
max_score=10,
logprobs=False,
)
The complete response is checked before optional log-probability weighting.
Direct scorer calls raise ValueError for invalid responses; the pipeline records
an evaluation error. No automatic format-repair retry is added.
Probability-weighted ratings
With logprobs=True (the default), EvalSense requests one output token and one
completion, overriding any larger limits in the model configuration. Each allowed
rating must appear as a complete canonical integer token in that token's returned
top_logprobs. The sampled token must match the complete response and its reported
probability. Token whitespace and one leading ▁ marker are supported; leading
zeroes, repeated identical tokens and invalid probability mass are rejected.
top_logprobs must be a positive integer at least as large as the number of ratings
on the scale. For 1–10, request at least 10 alternatives. This is a necessary
budget, not a guarantee: non-rating tokens may occupy the returned slots, and the
provider may return fewer alternatives or impose its own limit.
Missing ratings, missing log probabilities and multi-token responses fail clearly.
Where supported, increase top_logprobs to include omitted low-probability ratings.
Choose a smaller scale with suitable token labels, or explicitly set
logprobs=False to use sampled integer ratings. EvalSense never silently switches
from weighted scoring to a sampled rating. Providers that cannot produce this
one-token evidence cannot use the weighted mode.
For each allowed rating, EvalSense adds the probabilities of its valid reported token spellings and normalises by their combined mass. The score is the conditional mean over those reported valid rating tokens. Top-k truncation can omit other token spellings, so this remains an approximation. It does not estimate probabilities of arbitrary complete responses or multiply probabilities along multi-token labels.
For example, suppose a 1–10 scale has the following complete token evidence:
| Rating | Reported probability |
|---|---|
| 1 through 8, each explicitly present | 0 |
| 9 | 0.30 |
| 10 | 0.70 |
The raw weighted score is 9 × 0.30 + 10 × 0.70 = 9.7. Normalisation gives
(9.7 - 1) / 9, approximately 0.9667. If the judge instead represents 10 as
"1", "0", its first-token probability is not evidence for the complete rating
10. The missing complete token causes an error; EvalSense does not report the
incorrect prefix calculation 9 × 0.30 + 1 × 0.70 = 3.4.
Successful scores retain raw_score, output_text, prompt and score_format,
plus the following estimator metadata in the saved Inspect log:
| Field | Meaning |
|---|---|
estimator |
weighted_rating_tokens or sampled_rating, according to the mode actually used. |
estimator_format |
evalsense.g-eval.estimator.v1 for both scoring modes. |
weighting_policy |
evalsense.g-eval.single-token.v1 for weighted scores. |
rating_probabilities |
Normalised probabilities keyed by rating strings, for weighted scores. |
rating_probability_mass |
The total reported valid-token probability mass before normalisation, for weighted scores. |
This evidence survives reopening JSON and .eval logs. Failed weighted attempts
remain evaluation errors and do not become successful point scores. Valid response
syntax and valid probability evidence do not establish the accuracy of the judge.
Existing scores
get_g_eval_evaluator includes the evalsense.g-eval.integer.v1 format marker
in its evaluation-cache identity and successful score metadata. Both scoring modes
also include the evalsense.g-eval.estimator.v1 estimator-format marker, so earlier
scores without estimator evidence are re-scored. Weighted evaluators additionally
include the evalsense.g-eval.single-token.v1 weighting policy in their cache
identity. Matching generated outputs remain reusable, and historical logs remain
readable.
Stored logs are not edited or revalidated. Re-score affected evaluations and keep
the historical logs separately when comparing results. Code that constructs a
custom Evaluator around a scorer factory must update its explicit evaluator
version when changing its policy.
BERTScore IDF weighting
BertScoreCalculator and get_bertscore_evaluator score one prediction/reference
pair at a time. They support only idf=False, which is already the default.
Requests for automatic IDF or precomputed IDF dictionaries raise ValueError
before loading the metric. Changing a calculator's idf attribute is also
validated before scoring; weighting is never silently disabled.
BERTScore estimates inverse document frequency from a reference corpus. With one
reference, every token in it appears in every document, so its smoothed IDF is
zero. These weights cannot be normalised into a valid weighted score. Increasing
batch_size only changes embedding batches, not the one-reference corpus passed
by this evaluator.
The Hugging Face Evaluate BERTScore wrapper also treats a non-empty idf
dictionary as an instruction to fit weights from the supplied references rather
than using it as fixed token weights. Accepting a dictionary through this wrapper
would therefore retain the same problem. Empty dictionaries are rejected too;
they must not silently select unweighted scoring.
For corpus-weighted scoring, use the native bert_score.BERTScorer with
idf=True and an explicitly chosen idf_sents reference corpus, or the native
bert_score.score function with a precomputed dictionary. Keep the corpus and
weights fixed across comparisons, and use token IDs from the matching tokenizer.
A corpus-aware EvalSense integration is not implemented by this change.
The default unweighted scores, component names and hash metadata are unchanged.
Previously stored weighted results are not repaired or revalidated; retain their
provenance and do not compare them as though they were corpus-weighted BERTScore.
To rerun without IDF, construct a new evaluator with idf=False and a new name
so that old name-based evaluation caches are not reused.
References: