Evaluators
Modules:
Name | Description |
---|---|
bertscore |
|
bleu |
|
g_eval |
|
qags |
|
rouge |
|
Classes:
Name | Description |
---|---|
BertScoreCalculator |
Calculator for computing BERTScores. |
BleuPrecisionScoreCalculator |
Calculator for computing BLEU scores. |
GEvalScoreCalculator |
G-Eval score calculator. |
GEvalScorerFactory |
Scorer factory for G-Eval. |
QagsConfig |
A protocol for configuring QAGS evaluation. |
QagsScoreCalculator |
QAGS score calculator. |
QagsScorerFactory |
Scorer factory for QAGS. |
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 |
Returns an evaluator for BLEU scores. |
get_g_eval_evaluator |
Constructs a G-Eval evaluator that can be used in EvalSense evaluation pipeline. |
get_qags_evaluator |
Constructs a QAGS evaluator that can be used in EvalSense evaluation pipeline. |
get_rouge_evaluator |
Returns an evaluator for ROUGE scores. |
BertScoreCalculator
Bases: ScoreCalculator
Calculator for computing BERTScores.
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
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 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 |
|
__init__
__init__(
model_type: str = "microsoft/deberta-xlarge-mnli",
lang: str = "en",
num_layers: int | None = None,
idf: bool | dict[str, float] = 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 | dict[str, float]
|
Use IDF weighting — can be a precomputed IDF dictionary. |
False
|
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: dict,
) -> 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
|
Returns:
Name | Type | Description |
---|---|---|
Score |
Score
|
Inspect AI Score with the calculated evaluation results. |
Source code in evalsense/evaluation/evaluators/bertscore.py
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: dict,
) -> 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
|
Returns:
Name | Type | Description |
---|---|---|
Score |
Score
|
Inspect AI Score with the calculated evaluation results. |
Source code in evalsense/evaluation/evaluators/bertscore.py
BleuPrecisionScoreCalculator
Bases: ScoreCalculator
Calculator for computing BLEU scores.
Methods:
Name | Description |
---|---|
calculate |
Calculates BLEU precision scores for the supplied model prediction and reference input. |
calculate_async |
Calculates BLEU precision scores for the supplied model prediction and reference input. |
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: dict,
) -> Score
Calculates BLEU precision 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 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: dict,
) -> Score
Calculates BLEU precision 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 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 score calculator.
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
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 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 |
|
__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
|
Whether to use model log probabilities to compute weighted evaluation score instead of a standard score. |
True
|
top_logprobs
|
int
|
The number of top log probabilities to consider. |
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
|
Whether to report repeated errors in the log. |
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: dict,
) -> 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: dict,
) -> 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
|
dict
|
Additional keyword arguments. |
{}
|
Returns:
Name | Type | Description |
---|---|---|
Score |
Score
|
The calculated score. |
Source code in evalsense/evaluation/evaluators/g_eval.py
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
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 |
|
__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
|
Whether to use model log probabilities to compute weighted evaluation score instead of a standard score. |
True
|
top_logprobs
|
int
|
The number of top log probabilities to consider. |
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
|
Whether to report repeated errors in the log. |
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
A protocol for configuring QAGS evaluation.
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
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 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 |
|
__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 each question on a separate line.
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.
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
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 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 |
|
__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
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 |
|
QagsScorerFactory
Bases: ScorerFactory
Scorer factory for QAGS.
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
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.
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 | dict[str, float] = 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,
) -> Evaluator
Returns a BERTScore evaluator.
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 | dict
|
Use IDF weighting — can be a precomputed IDF dictionary.
Defaults to |
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
|
Returns:
Name | Type | Description |
---|---|---|
Evaluator |
Evaluator
|
The BERTScore evaluator. |
Source code in evalsense/evaluation/evaluators/bertscore.py
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 |
|
get_bleu_evaluator
get_bleu_evaluator(
name: str = "BLEU",
scorer_name: str = "BLEU Precision",
metrics: list[Metric | dict[str, list[Metric]]]
| dict[str, list[Metric]]
| None = None,
) -> Evaluator
Returns an evaluator for BLEU scores.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
The name of the metric and evaluator. Defaults to "BLEU". |
'BLEU'
|
scorer_name
|
str
|
The name of the internal scorer. Defaults to "BLEU Precision". |
'BLEU Precision'
|
metrics
|
list[Metric | dict[str, list[Metric]]] | dict[str, list[Metric]] | None
|
The metrics to use for the evaluation. If |
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,
) -> 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 respond with a numerical score between the specified min_score and max_score. |
required |
model_config
|
ModelConfig
|
The model configuration. |
required |
logprobs
|
bool
|
Whether to use model log probabilities to compute weighted evaluation score instead of a standard score. |
True
|
top_logprobs
|
int
|
The number of top log probabilities to consider. |
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
|
Whether to report repeated errors in the log. |
False
|
Returns:
Name | Type | Description |
---|---|---|
Evaluator |
Evaluator
|
The constructed G-Eval evaluator. |
Source code in evalsense/evaluation/evaluators/g_eval.py
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,
) -> Evaluator
Constructs a QAGS evaluator that can be used in EvalSense evaluation pipeline.
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 |
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,
) -> 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
|
Returns:
Name | Type | Description |
---|---|---|
Evaluator |
Evaluator
|
An evaluator for ROUGE scores. |