( metric_name: str higher_is_better: bool category: SamplingMethod sample_level_fn: lighteval.metrics.metrics_sample.SampleLevelComputation | lighteval.metrics.sample_preparator.Preparator corpus_level_fn: typing.Union[lighteval.metrics.metrics_corpus.CorpusLevelComputation, typing.Callable] batched_compute: bool = False )
( metric_name: str higher_is_better: bool category: SamplingMethod sample_level_fn: lighteval.metrics.metrics_sample.SampleLevelComputation | lighteval.metrics.sample_preparator.Preparator corpus_level_fn: typing.Union[lighteval.metrics.metrics_corpus.CorpusLevelComputation, typing.Callable] batched_compute: bool = False )
Metric computed over the whole corpora, with computations happening at the aggregation phase
( metric_name: str higher_is_better: bool category: SamplingMethod sample_level_fn: lighteval.metrics.metrics_sample.SampleLevelComputation | lighteval.metrics.sample_preparator.Preparator corpus_level_fn: typing.Union[lighteval.metrics.metrics_corpus.CorpusLevelComputation, typing.Callable] batched_compute: bool = False )
Metric computed per sample, then aggregated over the corpus
( metric_name: list higher_is_better: dict category: SamplingMethod sample_level_fn: lighteval.metrics.metrics_sample.SampleLevelComputation | lighteval.metrics.sample_preparator.Preparator corpus_level_fn: dict batched_compute: bool = False )
Some metrics are more advantageous to compute together at once. For example, if a costly preprocessing is the same for all metrics, it makes more sense to compute it once.
( metric_name: list higher_is_better: dict category: SamplingMethod sample_level_fn: lighteval.metrics.metrics_sample.SampleLevelComputation | lighteval.metrics.sample_preparator.Preparator corpus_level_fn: dict batched_compute: bool = False )
MetricGrouping computed over the whole corpora, with computations happening at the aggregation phase
( metric_name: list higher_is_better: dict category: SamplingMethod sample_level_fn: lighteval.metrics.metrics_sample.SampleLevelComputation | lighteval.metrics.sample_preparator.Preparator corpus_level_fn: dict batched_compute: bool = False )
MetricGrouping are computed per sample, then aggregated over the corpus
( average: str num_classes: int = 2 )
Computes the metric score over all the corpus generated items, by using the scikit learn implementation.
Computes the metric score over all the corpus generated items.
( metric_type: str lang: typing.Literal['zh', 'ja', 'ko', ''] = '' )
Computes the metric score over all the corpus generated items, by using the sacrebleu implementation.
( items: list ) → float
Computes the Matthews Correlation Coefficient, using scikit learn (doc).
( aggregation_function: typing.Callable[[list[float]], float] = <built-in function max> normalize_gold: typing.Optional[typing.Callable[[str], str]] = None normalize_pred: typing.Optional[typing.Callable[[str], str]] = None strip_strings: bool = False type_exact_match: str = 'full' )
( doc: Doc model_response: ModelResponse **kwargs ) → float
Computes the metric over a list of golds and predictions for one single sample.
( gold: str pred: str ) → float
Compares two strings only.
( aggregation_function: typing.Callable[[list[float]], float] = <built-in function max> normalize_gold: typing.Optional[typing.Callable[[str], str]] = None normalize_pred: typing.Optional[typing.Callable[[str], str]] = None strip_strings: bool = False )
( doc: Doc model_response: ModelResponse **kwargs ) → float
Computes the metric over a list of golds and predictions for one single sample.
( gold: str pred: str ) → float
Compares two strings only.
( logprob_normalization: lighteval.metrics.normalizations.LogProbCharNorm | lighteval.metrics.normalizations.LogProbTokenNorm | lighteval.metrics.normalizations.LogProbPMINorm | None = None )
( doc: Doc model_response: ModelResponse **kwargs ) → int
Computes the log likelihood accuracy: is the choice with the highest logprob in choices_logprob present
in the gold_ixs?
( log_prob_normalization: lighteval.metrics.normalizations.LogProbCharNorm | lighteval.metrics.normalizations.LogProbTokenNorm | lighteval.metrics.normalizations.LogProbPMINorm | None = None aggregation_function: typing.Callable[[numpy.ndarray], float] = <function max at 0x7f71c41fc1b0> )
( doc: Doc model_response: ModelResponse **kwargs ) → float
Computes the log likelihood probability: chance of choosing the best choice.
( normalization: lighteval.metrics.normalizations.LogProbTokenNorm | None = None aggregation_function: typing.Callable[[numpy.ndarray], float] = <function max at 0x7f71c41fc1b0> )
( doc: Doc model_response: ModelResponse **kwargs ) → float
Computes the log likelihood probability: chance of choosing the best choice.
( doc: Doc model_response: ModelResponse **kwargs ) → int
Computes the recall at the requested depth level: looks at the n best predicted choices (with the
highest log probabilities) and see if there is an actual gold among them.
( doc: Doc model_response: ModelResponse **kwargs ) → float
Mean reciprocal rank. Measures the quality of a ranking of choices (ordered by correctness).
( methods: str | list[str] multiple_golds: bool = False bootstrap: bool = False normalize_gold: typing.Optional[typing.Callable] = None normalize_pred: typing.Optional[typing.Callable] = None aggregation_function: typing.Optional[typing.Callable] = None tokenizer: object = None )
( doc: Doc model_response: ModelResponse **kwargs ) → float or dict
Parameters
Returns
float or dict
Aggregated score over the current sample’s items. If several rouge functions have been selected, returns a dict which maps name and scores.
Computes the metric(s) over a list of golds and predictions for one single sample.
( normalize_gold: typing.Optional[typing.Callable] = None normalize_pred: typing.Optional[typing.Callable] = None )
( doc: Doc model_response: ModelResponse **kwargs ) → dict
Computes the prediction, recall and f1 score using the bert scorer.
( normalize_input: <built-in function callable> = <function remove_braces at 0x7f7080a57f40> normalize_pred: <built-in function callable> = <function remove_braces_and_strip at 0x7f7080a74040> input_column: str = 'text' language: typing.Literal['en', 'de', 'fr', 'it'] = 'en' )
( doc: Doc model_response: ModelResponse **kwargs ) → dict[str, float]
Compute the extractiveness of the predictions.
This method calculates coverage, density, and compression scores for a single prediction against the input text.
( normalize_input: typing.Callable = <function remove_braces at 0x7f7080a57f40> normalize_pred: typing.Callable = <function remove_braces_and_strip at 0x7f7080a74040> input_column: str = 'text' )
( doc: Doc model_response: ModelResponse **kwargs ) → dict[str, float]
Compute the faithfulness of the predictions.
The SummaCZS (Summary Content Zero-Shot) model is used with configurable granularity and model variation.
( doc: Doc model_response: ModelResponse **kwargs ) → float
Uses the stored BLEURT scorer to compute the score on the current sample.
( doc: Doc model_response: ModelResponse **kwargs ) → float
Computes the sentence level BLEU between the golds and each prediction, then takes the average.
( metric_types: list[str] | str strip_prediction: bool = True )
( doc: Doc model_response: ModelResponse **kwargs ) → dict
Computes all the requested metrics on the golds and prediction.
Compute the edit similarity between two lists of strings.
Edit similarity is also used in the paper Lee, Katherine, et al. “Deduplicating training data makes language models better.” arXiv preprint arXiv:2107.06499 (2021).
Compute the length of the longest common prefix.
( k: int | None = None n: int | None = None **kwargs )
( doc: Doc model_response: ModelResponse **kwargs ) → float
Computes the metric over a list of golds and predictions for one single item with possibly many samples. It applies normalisation (if needed) to model prediction and gold, computes their per prediction score, then aggregates the scores over the samples using a pass@k.
Algo from https://arxiv.org/pdf/2107.03374
( doc: Doc model_response: ModelResponse **kwargs ) → float
Computes the metric over a list of golds and predictions for one single sample. It applies normalisation (if needed) to model prediction and gold, and takes the most frequent answer of all the available ones, then compares it to the gold.
( doc: Doc model_response: ModelResponse **kwargs ) → float
Computes the metric over a list of golds and predictions for one single sample. It applies normalisation (if needed) to model prediction and gold, and takes the most frequent answer of all the available ones, then compares it to the gold.
( model: str templates: typing.Callable process_judge_response: typing.Callable judge_backend: typing.Literal['litellm', 'openai', 'transformers', 'tgi', 'vllm', 'inference-providers'] url: str | None = None api_key: str | None = None max_tokens: int | None = None response_format: BaseModel = None hf_provider: typing.Optional[typing.Literal['black-forest-labs', 'cerebras', 'cohere', 'fal-ai', 'fireworks-ai', 'inference-providers', 'hyperbolic', 'nebius', 'novita', 'openai', 'replicate', 'sambanova', 'together']] = None backend_options: dict | None = None )
Parameters
A class representing a judge for evaluating answers using either the chosen backend.
Methods: evaluate_answer: Evaluates an answer using the OpenAI API or Transformers library. lazy_load_client: Lazy loads the OpenAI client or Transformers pipeline. call_api: Calls the API to get the judge’s response. call_transformers: Calls the Transformers pipeline to get the judge’s response. call_vllm: Calls the VLLM pipeline to get the judge’s response.
( dict_of_lists )
Transform a dictionary of lists into a list of dictionaries.
Each dictionary in the output list will contain one element from each list in the input dictionary, with the same keys as the input dictionary.
Example:
dict_of_lists_to_list_of_dicts({‘k’: [1, 2, 3], ‘k2’: [‘a’, ‘b’, ‘c’]}) [{‘k’: 1, ‘k2’: ‘a’}, {‘k’: 2, ‘k2’: ‘b’}, {‘k’: 3, ‘k2’: ‘c’}]
( question: str answer: str options: list[str] | None = None gold: str | None = None )
Evaluates an answer using either Transformers or OpenAI API.
( judge_model_name: str template: typing.Callable process_judge_response: typing.Callable judge_backend: typing.Literal['litellm', 'openai', 'transformers', 'vllm', 'tgi', 'inference-providers'] short_judge_name: str | None = None response_format: pydantic.main.BaseModel | None = None url: str | None = None hf_provider: str | None = None max_tokens: int | None = None backend_options: dict | None = None )
( judge_model_name: str template: typing.Callable process_judge_response: typing.Callable judge_backend: typing.Literal['litellm', 'openai', 'transformers', 'vllm', 'tgi', 'inference-providers'] short_judge_name: str | None = None response_format: pydantic.main.BaseModel | None = None url: str | None = None hf_provider: str | None = None max_tokens: int | None = None backend_options: dict | None = None )
Compute the score of a generative task using a llm as a judge. The generative task can be multiturn with 2 turns max, in that case, we return scores for turn 1 and 2. Also returns user_prompt and judgement which are ignored later by the aggregator.
( judge_model_name: str template: typing.Callable process_judge_response: typing.Callable judge_backend: typing.Literal['litellm', 'openai', 'transformers', 'vllm', 'tgi', 'inference-providers'] short_judge_name: str | None = None response_format: pydantic.main.BaseModel | None = None url: str | None = None hf_provider: str | None = None max_tokens: int | None = None backend_options: dict | None = None )
Compute the score of a generative task using a llm as a judge. The generative task can be multiturn with 2 turns max, in that case, we return scores for turn 1 and 2. Also returns user_prompt and judgement which are ignored later by the aggregator.