builtin
Concrete implementations of built-in metrics
Submodules
| MODULE | DESCRIPTION |
|---|---|
counts |
|
json_format |
|
| CLASS | DESCRIPTION |
|---|---|
CountsConfig |
The configuration schema for the |
CountsMetric |
Metric for counting segments in an input text. |
JsonFormatConfig |
The configuration schema for the |
JsonFormatMetric |
Metric for evaluating whether text matches a given JSON format. |
Classes
CountsConfig
pydantic-model
The configuration schema for the CountsMetric.
| PARAMETER | DESCRIPTION |
|---|---|
segments |
(default
=
TYPE:
|
segmentation |
How to split the input text into segments. If If
If |
hf_token |
User access token for HuggingFace.
This is only required when specifying a
gated model to use for
encoding. Note that you can also set the
TYPE:
|
Example configuration
characters: CountsMetric = CountsMetric() # (1)!
tokens_ws: CountsMetric = CountsMetric.from_config(
{
"segments": "tokens" # (2)!
}
)
tokens_wordpunct: CountsMetric = CountsMetric.from_config(
**{
"segments": "tokens",
"segmentation": "wordpunct", # (3)!
}
)
encs_bart: CountsMetric = CountsMetric.from_config(
{
"segments": "encodings", # (4)!
"segmentation": "facebook/bart-base",
}
)
encs_bert_amharic: CountsMetric = CountsMetric.from_config(
**{
"segments": "encodings",
"segmentation": "rasyosef/bert-amharic-tokenizer", # (5)!
}
)
encs_llama: CountsMetric = CountsMetric.from_config(
**{
"segments": "encodings",
"segmentation": "meta-llama/Llama-3.3-70B-Instruct",
"hf_token": "hf_...", # (6)!
}
)
- By default, the
CountsMetricsimply counts the number of characters. - To count tokens instead of characters, set
segments="tokens". This will split the text into tokens separated by one or more whitespace characters by default. - Use a slightly more sophisticated tokenization scheme.
- To count model-specific encodings, set
segments="encodings"and specify the model to use for encoding in thesegmentationfield. - Maybe you're working with non-English texts? No problem, just specify a model that provides a tokenizer pretrained on the relevant language.
- If you want to use a gated model for encoding, make sure to provide a valid
HuggingFace user access token with the necessary permissions to access the
model. You can also set the
HF_TOKENenvironment variable instead if you prefer not to pass the token in directly.
Fields:
-
segments(Literal['characters', 'tokens', 'encodings']) -
segmentation(str | None) -
hf_token(str | None)
Validators:
-
_validate_config
Attributes
tokenizer
cached
property
The function to use for segmenting the input text, based on the configuration.
| RETURNS | DESCRIPTION |
|---|---|
Callable[[str], Sequence[str | int]]
|
Callable[[str], Sequence[str | int]]: A function that takes a string as input and returns a sequence of segments, where each segment is either a string (for tokenization) or an integer (for encoding). |
CountsMetric
flowchart TD
evallm.metrics.builtin.CountsMetric[CountsMetric]
evallm.metrics.base.BaseMetric[BaseMetric]
evallm.metrics.base.BaseMetric --> evallm.metrics.builtin.CountsMetric
click evallm.metrics.builtin.CountsMetric href "" "evallm.metrics.builtin.CountsMetric"
click evallm.metrics.base.BaseMetric href "" "evallm.metrics.base.BaseMetric"
Metric for counting segments in an input text.
Evaluation results
Given an input string, this metric produces a dictionary mapping the metric's
name to a single count. The count represents the number of segments that are
contained in the input text, where the type of segments counted (characters,
tokens, or encodings) can be configured through the segments and
segmentation runtime parameters. If no configuration is specified, this
metric will simply count the number of characters in the input text (after
stripping leading and trailing whitespace) by default.
Note that specifiying a model to use for encoding input texts requires
installing evaLLM with the hf-tokenizers extra:
| PARAMETER | DESCRIPTION |
|---|---|
segments |
(default
=
TYPE:
|
segmentation |
How to split the input text into segments. If If
If |
hf_token |
User access token for HuggingFace.
This is only required when specifying a
gated model to use for
encoding. Note that you can also set the
TYPE:
|
-
API Reference
evallmmetricsbuiltin ClassesCountsConfig
| METHOD | DESCRIPTION |
|---|---|
__init_subclass__ |
Called when a class inherits from |
__eq__ |
Check if this metric is equal to another metric. |
__iter__ |
Iterate over the subtree rooted at this metric in breadth-first order. |
__contains__ |
Check if a metric is contained in the subtree rooted at this metric. |
__repr__ |
String representation of the subtree, rooted in this metric instance. |
result |
Helper method for wrapping the value of a metric's evaluation result in a |
descendants |
Yield nodes in the subtree rooted at self (cycle-safe). |
from_config |
Factory method to create a metric instance from kwargs or JSON payload. |
evaluate |
Evaluate how many segments are contained in the input text. |
| ATTRIBUTE | DESCRIPTION |
|---|---|
value_type |
The metric class' parametrized type, binding the generic type parameter
TYPE:
|
config_schema |
A schema defining the expected runtime configuration parameters for this metric. |
parent |
Get the parent of this metric.
TYPE:
|
result_key |
The key to use for this metric's value in the evaluation result dictionary.
TYPE:
|
name |
The name of this metric's class.
TYPE:
|
is_composite |
Check if this metric is a composite metric (i.e. can have child metrics).
TYPE:
|
is_root |
Check if this metric is a root metric (i.e. has no parent).
TYPE:
|
root |
Get the root metric of the tree this metric belongs to.
TYPE:
|
depth |
Get the depth of this metric in the tree (i.e. the number of edges from this
TYPE:
|
children |
Get an iterator over the children of this metric.
TYPE:
|
config |
Get the runtime configuration of this metric instance as a dictionary. |
Source code in src/evallm/metrics/base.py
Attributes
value_type
class-attribute
value_type: object
The metric class' parametrized type, binding the generic type parameter T.
-
API Reference
evallmmetrics
config_schema
class-attribute
A schema defining the expected runtime configuration parameters for this metric.
If the metric class does not explicitly define a config schema, this defaults to an
empty pydantic model (see
DefaultSchema) that takes no
parameters.
Info
A class' config schema is always configured such that:
- all declared fields must be provided unless they are declared as optional
- no additional fields beyond those declared in the schema are allowed (see
also
pydantic.ConfigDict.extra) - the schema is frozen/immutable once defined (see also
pydantic.ConfigDict.frozen) - configuration parameters provided at runtime are strictly validated against
the schema, raising a
ValidationErrorif the provided parameters violate it (see also pydantic Conversion Table)
-
API Reference
evallm
parent
property
writable
parent: CompositeMetric | None
Get the parent of this metric.
| RETURNS | DESCRIPTION |
|---|---|
CompositeMetric | None
|
CompositeMetric | None: The parent metric, or |
result_key
property
writable
result_key: str
The key to use for this metric's value in the evaluation result dictionary.
By default, this is the same as the metric's name, but it can be
overridden on a per-instance basis. This is useful when multiple instances of
the same metric class are used in a single evaluation request with different
runtime parameters and therefore need distinct keys in the output.
| RETURNS | DESCRIPTION |
|---|---|
result_key
|
The key of this metric instance's value in the evaluation
result dictionary. Defaults to the metric's
TYPE:
|
-
API Reference
evallm
name
property
name: str
The name of this metric's class.
This is a class-, not an instance-level property that's used for identifying
this metric in the catalog. It also serves as the default
result_key for metric instances unless explicitly overridden.
Metric class registration and name updates
When a metric class is registered in the catalog under a custom name using
@register_metric(name=...), the name-property of any pre-existing
instances of that class will be updated to reflect the new name in the
catalog.
| RETURNS | DESCRIPTION |
|---|---|
name
|
The name of this metric. Defaults to the class name if not
overwritten by the
TYPE:
|
-
API Reference
evallm-
metrics -
application
-
is_composite
property
is_composite: bool
Check if this metric is a composite metric (i.e. can have child metrics).
| RETURNS | DESCRIPTION |
|---|---|
bool
|
TYPE:
|
is_root
property
is_root: bool
Check if this metric is a root metric (i.e. has no parent).
| RETURNS | DESCRIPTION |
|---|---|
bool
|
TYPE:
|
root
property
root: BaseMetric[SerializableValueType]
Get the root metric of the tree this metric belongs to.
| RETURNS | DESCRIPTION |
|---|---|
BaseMetric
|
The root metric of the tree this metric belongs to.
TYPE:
|
depth
property
depth: int
Get the depth of this metric in the tree (i.e. the number of edges from this metric to the root).
| RETURNS | DESCRIPTION |
|---|---|
depth
|
The depth of this metric in the tree. Root metrics have depth 0, their children have depth 1, and so on.
TYPE:
|
children
property
children: Iterator[BaseMetric[SerializableValueType]]
Get an iterator over the children of this metric.
| YIELDS | DESCRIPTION |
|---|---|
children
|
An iterator over the child metrics (i.e. direct descendants) of this metric. If this metric is a leaf node, this will be an empty iterator.
TYPE::
|
config
property
Get the runtime configuration of this metric instance as a dictionary.
| RETURNS | DESCRIPTION |
|---|---|
config
|
A dictionary containing the runtime configuration of this metric instance, validated against the metric's schema. |
-
API Reference
evallmmetricsconfig Functionsconfig_schema
Functions
__init_subclass__
Called when a class inherits from BaseMetric.
Sets the default name and config schema of the metric class and validates
& stores the parametrized value type of the metric class (i.e.
the T in BaseMetric[T]) as the
value_type class variable
and ensures that evaluate is implemented with the correct signature.
| RAISES | DESCRIPTION |
|---|---|
TypeError
|
If the metric class does not implement the |
UnserializableValueTypeError
|
If the metric class's parametrized value type
is not an instance of
|
Source code in src/evallm/metrics/base.py
__eq__
Check if this metric is equal to another metric.
Two metrics are considered equal iff they are the same instance.
| PARAMETER | DESCRIPTION |
|---|---|
other
|
The other metric to compare against.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
bool
|
TYPE:
|
Source code in src/evallm/metrics/base.py
__iter__
__iter__() -> Iterator[BaseMetric[SerializableValueType]]
Iterate over the subtree rooted at this metric in breadth-first order.
| YIELDS | DESCRIPTION |
|---|---|
metric
|
An iterator over the subtree rooted at this metric in breadth-first order, excluding this metric itself.
TYPE::
|
Source code in src/evallm/metrics/base.py
__contains__
__contains__(metric: str | BaseMetric[SerializableValueType]) -> bool
Check if a metric is contained in the subtree rooted at this metric.
Note
Passing a metric instance checks for identity (i.e. whether exactly that instance is contained in this subtree), whereas passing a metric's name checks for membership (i.e. whether any metric with that name is contained in this subtree).
Example
Identity-based membership check: Name-based membership check:| PARAMETER | DESCRIPTION |
|---|---|
metric
|
The name of the metric to check for, or the metric instance itself.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
bool
|
TYPE:
|
Source code in src/evallm/metrics/base.py
__repr__
__repr__() -> str
String representation of the subtree, rooted in this metric instance.
| RETURNS | DESCRIPTION |
|---|---|
representation
|
A string representation of the metric instance, including its name and class.
TYPE:
|
Source code in src/evallm/metrics/base.py
result
Helper method for wrapping the value of a metric's evaluation result in a
dictionary to conform to the expected return type of evaluate.
Example
| PARAMETER | DESCRIPTION |
|---|---|
value
|
The result of computing the metric, where
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
result
|
A dictionary containing the given value, keyed by
the metric's |
| RAISES | DESCRIPTION |
|---|---|
TypeError
|
If the given value is not of the expected type |
-
API Reference
evallmmetrics
Source code in src/evallm/metrics/base.py
descendants
descendants(
*, include_self: bool = False, order: Literal["dfs", "bfs"] = "dfs"
) -> Iterator[BaseMetric[SerializableValueType]]
Yield nodes in the subtree rooted at self (cycle-safe).
| PARAMETER | DESCRIPTION |
|---|---|
include_self
|
Whether to include
TYPE:
|
order
|
The order to traverse the tree. "dfs" for depth-first search, "bfs" for breadth-first search.
TYPE:
|
| YIELDS | DESCRIPTION |
|---|---|
descendants
|
An iterator over the descendant nodes of this metric, in the specified traversal order.
TYPE::
|
Source code in src/evallm/metrics/base.py
from_config
classmethod
from_config(*, json_payload: str | None = None, **kwargs: Any) -> BaseMetric[T]
Factory method to create a metric instance from kwargs or JSON payload.
Info
This method can be used to create any metric instance, so long as the
provided config parameters conform to the metric's schema. If the metric
class doesn't define a config schema (the default), calling this method
without kwargs is equivalent to calling the metric class constructor
directly.
The expected parameters depend on the metric's declared config_schema
(see also @config_schema decorator)
and the provided parameters must strictly conform to it.
| PARAMETER | DESCRIPTION |
|---|---|
json_payload
|
A JSON string containing the runtime parameters for this metric instance.
TYPE:
|
| PARAMETER | DESCRIPTION |
|---|---|
**kwargs |
The runtime parameters to use for this metric instance.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
metric
|
An instance of this metric class created using the provided configuration parameters.
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
TypeError
|
If |
ValueError
|
If
|
-
API Reference
evallm-
application -
metricsbase ClassesDefaultSchema
-
Source code in src/evallm/metrics/base.py
evaluate
Evaluate how many segments are contained in the input text.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
The input text to evaluate.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
dict[str, int]
|
dict[str, int]: A dictionary mapping this metric instance's
|
Source code in src/evallm/metrics/builtin/counts.py
JsonFormatConfig
pydantic-model
The configuration schema for the JsonFormatMetric.
| PARAMETER | DESCRIPTION |
|---|---|
expected_schema |
A valid JSON schema conforming to the
JSON Schema draft-2020-12 specification
that describes the expected output format. Can be provided either as a
JSON payload string or as a dictionary. Note that the schema must be a
top-level schema, defined as |
check_formats |
(default=
TYPE:
|
Example configuration
json_payload: str = '''
{
"type": "object",
"properties": {
"question": {
"type": "string"
},
"setup": {
"type": "string"
},
"joke": {
"type": "string"
},
"funniness_score": {
"type": "number",
"minimum": 0.0,
"maximum": 1.0
}
},
"required": ["question", "joke"]
}
'''
config: dict[str, Any] = {"expected_schema": json_payload}
metric: JsonFormatMetric = JsonFormatMetric.from_config(**config)
Fields:
Validators:
-
_validate_expected_schema→expected_schema
JsonFormatMetric
flowchart TD
evallm.metrics.builtin.JsonFormatMetric[JsonFormatMetric]
evallm.metrics.base.BaseMetric[BaseMetric]
evallm.metrics.base.BaseMetric --> evallm.metrics.builtin.JsonFormatMetric
click evallm.metrics.builtin.JsonFormatMetric href "" "evallm.metrics.builtin.JsonFormatMetric"
click evallm.metrics.base.BaseMetric href "" "evallm.metrics.base.BaseMetric"
Metric for evaluating whether text matches a given JSON format.
This metric evaluates whether the input text adheres to a structured output format,
defined by the expected_schema.
| PARAMETER | DESCRIPTION |
|---|---|
expected_schema |
The expected JSON schema as a dictionary that conforms to the JSON Schema draft-2020-12 specification. |
check_formats |
If
TYPE:
|
-
API Reference
evallmmetricsbuiltin ClassesJsonFormatConfig
| METHOD | DESCRIPTION |
|---|---|
__init_subclass__ |
Called when a class inherits from |
__eq__ |
Check if this metric is equal to another metric. |
__iter__ |
Iterate over the subtree rooted at this metric in breadth-first order. |
__contains__ |
Check if a metric is contained in the subtree rooted at this metric. |
__repr__ |
String representation of the subtree, rooted in this metric instance. |
result |
Helper method for wrapping the value of a metric's evaluation result in a |
descendants |
Yield nodes in the subtree rooted at self (cycle-safe). |
from_config |
Factory method to create a metric instance from kwargs or JSON payload. |
evaluate |
Evaluate whether the input text matches the expected JSON format. |
| ATTRIBUTE | DESCRIPTION |
|---|---|
value_type |
The metric class' parametrized type, binding the generic type parameter
TYPE:
|
config_schema |
A schema defining the expected runtime configuration parameters for this metric. |
parent |
Get the parent of this metric.
TYPE:
|
result_key |
The key to use for this metric's value in the evaluation result dictionary.
TYPE:
|
name |
The name of this metric's class.
TYPE:
|
is_composite |
Check if this metric is a composite metric (i.e. can have child metrics).
TYPE:
|
is_root |
Check if this metric is a root metric (i.e. has no parent).
TYPE:
|
root |
Get the root metric of the tree this metric belongs to.
TYPE:
|
depth |
Get the depth of this metric in the tree (i.e. the number of edges from this
TYPE:
|
children |
Get an iterator over the children of this metric.
TYPE:
|
config |
Get the runtime configuration of this metric instance as a dictionary. |
Source code in src/evallm/metrics/base.py
Attributes
value_type
class-attribute
value_type: object
The metric class' parametrized type, binding the generic type parameter T.
-
API Reference
evallmmetrics
config_schema
class-attribute
A schema defining the expected runtime configuration parameters for this metric.
If the metric class does not explicitly define a config schema, this defaults to an
empty pydantic model (see
DefaultSchema) that takes no
parameters.
Info
A class' config schema is always configured such that:
- all declared fields must be provided unless they are declared as optional
- no additional fields beyond those declared in the schema are allowed (see
also
pydantic.ConfigDict.extra) - the schema is frozen/immutable once defined (see also
pydantic.ConfigDict.frozen) - configuration parameters provided at runtime are strictly validated against
the schema, raising a
ValidationErrorif the provided parameters violate it (see also pydantic Conversion Table)
-
API Reference
evallm
parent
property
writable
parent: CompositeMetric | None
Get the parent of this metric.
| RETURNS | DESCRIPTION |
|---|---|
CompositeMetric | None
|
CompositeMetric | None: The parent metric, or |
result_key
property
writable
result_key: str
The key to use for this metric's value in the evaluation result dictionary.
By default, this is the same as the metric's name, but it can be
overridden on a per-instance basis. This is useful when multiple instances of
the same metric class are used in a single evaluation request with different
runtime parameters and therefore need distinct keys in the output.
| RETURNS | DESCRIPTION |
|---|---|
result_key
|
The key of this metric instance's value in the evaluation
result dictionary. Defaults to the metric's
TYPE:
|
-
API Reference
evallm
name
property
name: str
The name of this metric's class.
This is a class-, not an instance-level property that's used for identifying
this metric in the catalog. It also serves as the default
result_key for metric instances unless explicitly overridden.
Metric class registration and name updates
When a metric class is registered in the catalog under a custom name using
@register_metric(name=...), the name-property of any pre-existing
instances of that class will be updated to reflect the new name in the
catalog.
| RETURNS | DESCRIPTION |
|---|---|
name
|
The name of this metric. Defaults to the class name if not
overwritten by the
TYPE:
|
-
API Reference
evallm-
metrics -
application
-
is_composite
property
is_composite: bool
Check if this metric is a composite metric (i.e. can have child metrics).
| RETURNS | DESCRIPTION |
|---|---|
bool
|
TYPE:
|
is_root
property
is_root: bool
Check if this metric is a root metric (i.e. has no parent).
| RETURNS | DESCRIPTION |
|---|---|
bool
|
TYPE:
|
root
property
root: BaseMetric[SerializableValueType]
Get the root metric of the tree this metric belongs to.
| RETURNS | DESCRIPTION |
|---|---|
BaseMetric
|
The root metric of the tree this metric belongs to.
TYPE:
|
depth
property
depth: int
Get the depth of this metric in the tree (i.e. the number of edges from this metric to the root).
| RETURNS | DESCRIPTION |
|---|---|
depth
|
The depth of this metric in the tree. Root metrics have depth 0, their children have depth 1, and so on.
TYPE:
|
children
property
children: Iterator[BaseMetric[SerializableValueType]]
Get an iterator over the children of this metric.
| YIELDS | DESCRIPTION |
|---|---|
children
|
An iterator over the child metrics (i.e. direct descendants) of this metric. If this metric is a leaf node, this will be an empty iterator.
TYPE::
|
config
property
Get the runtime configuration of this metric instance as a dictionary.
| RETURNS | DESCRIPTION |
|---|---|
config
|
A dictionary containing the runtime configuration of this metric instance, validated against the metric's schema. |
-
API Reference
evallmmetricsconfig Functionsconfig_schema
Functions
__init_subclass__
Called when a class inherits from BaseMetric.
Sets the default name and config schema of the metric class and validates
& stores the parametrized value type of the metric class (i.e.
the T in BaseMetric[T]) as the
value_type class variable
and ensures that evaluate is implemented with the correct signature.
| RAISES | DESCRIPTION |
|---|---|
TypeError
|
If the metric class does not implement the |
UnserializableValueTypeError
|
If the metric class's parametrized value type
is not an instance of
|
Source code in src/evallm/metrics/base.py
__eq__
Check if this metric is equal to another metric.
Two metrics are considered equal iff they are the same instance.
| PARAMETER | DESCRIPTION |
|---|---|
other
|
The other metric to compare against.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
bool
|
TYPE:
|
Source code in src/evallm/metrics/base.py
__iter__
__iter__() -> Iterator[BaseMetric[SerializableValueType]]
Iterate over the subtree rooted at this metric in breadth-first order.
| YIELDS | DESCRIPTION |
|---|---|
metric
|
An iterator over the subtree rooted at this metric in breadth-first order, excluding this metric itself.
TYPE::
|
Source code in src/evallm/metrics/base.py
__contains__
__contains__(metric: str | BaseMetric[SerializableValueType]) -> bool
Check if a metric is contained in the subtree rooted at this metric.
Note
Passing a metric instance checks for identity (i.e. whether exactly that instance is contained in this subtree), whereas passing a metric's name checks for membership (i.e. whether any metric with that name is contained in this subtree).
Example
Identity-based membership check: Name-based membership check:| PARAMETER | DESCRIPTION |
|---|---|
metric
|
The name of the metric to check for, or the metric instance itself.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
bool
|
TYPE:
|
Source code in src/evallm/metrics/base.py
__repr__
__repr__() -> str
String representation of the subtree, rooted in this metric instance.
| RETURNS | DESCRIPTION |
|---|---|
representation
|
A string representation of the metric instance, including its name and class.
TYPE:
|
Source code in src/evallm/metrics/base.py
result
Helper method for wrapping the value of a metric's evaluation result in a
dictionary to conform to the expected return type of evaluate.
Example
| PARAMETER | DESCRIPTION |
|---|---|
value
|
The result of computing the metric, where
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
result
|
A dictionary containing the given value, keyed by
the metric's |
| RAISES | DESCRIPTION |
|---|---|
TypeError
|
If the given value is not of the expected type |
-
API Reference
evallmmetrics
Source code in src/evallm/metrics/base.py
descendants
descendants(
*, include_self: bool = False, order: Literal["dfs", "bfs"] = "dfs"
) -> Iterator[BaseMetric[SerializableValueType]]
Yield nodes in the subtree rooted at self (cycle-safe).
| PARAMETER | DESCRIPTION |
|---|---|
include_self
|
Whether to include
TYPE:
|
order
|
The order to traverse the tree. "dfs" for depth-first search, "bfs" for breadth-first search.
TYPE:
|
| YIELDS | DESCRIPTION |
|---|---|
descendants
|
An iterator over the descendant nodes of this metric, in the specified traversal order.
TYPE::
|
Source code in src/evallm/metrics/base.py
from_config
classmethod
from_config(*, json_payload: str | None = None, **kwargs: Any) -> BaseMetric[T]
Factory method to create a metric instance from kwargs or JSON payload.
Info
This method can be used to create any metric instance, so long as the
provided config parameters conform to the metric's schema. If the metric
class doesn't define a config schema (the default), calling this method
without kwargs is equivalent to calling the metric class constructor
directly.
The expected parameters depend on the metric's declared config_schema
(see also @config_schema decorator)
and the provided parameters must strictly conform to it.
| PARAMETER | DESCRIPTION |
|---|---|
json_payload
|
A JSON string containing the runtime parameters for this metric instance.
TYPE:
|
| PARAMETER | DESCRIPTION |
|---|---|
**kwargs |
The runtime parameters to use for this metric instance.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
metric
|
An instance of this metric class created using the provided configuration parameters.
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
TypeError
|
If |
ValueError
|
If
|
-
API Reference
evallm-
application -
metricsbase ClassesDefaultSchema
-
Source code in src/evallm/metrics/base.py
evaluate
Evaluate whether the input text matches the expected JSON format.
This method attempts to parse the input text as JSON and checks whether it contains the expected fields as specified in the configuration.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
The input text to evaluate.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
dict[str, dict[str, bool]]
|
dict[str, dict[str, bool]]: A dictionary mapping this metric instance's
|