registry
Global registry for automatic metrics discovery
| CLASS | DESCRIPTION |
|---|---|
Catalog |
Interface for a global catalog that keeps track of distinct available metrics. |
MetricsCatalog |
A global catalog that keeps track of distinct available metrics. |
| FUNCTION | DESCRIPTION |
|---|---|
register_metric |
Decorator for registering a metric class in a global |
Type Aliases
Classes
Catalog
flowchart TD
evallm.metrics.registry.Catalog[Catalog]
click evallm.metrics.registry.Catalog href "" "evallm.metrics.registry.Catalog"
Interface for a global catalog that keeps track of distinct available metrics.
Defines a register(metric: BaseMetric[SerializableValueType]) method that serves
as a hook for the @register_metric decorator, enabling automatic registration of
BaseMetric[SerializableValueType]-subclasses in the catalog at definition time.
Also provides convenience methods for looking up metric classes by name and
renaming registered metrics.
-
API Reference
evallm-
application -
metricsbase ClassesBaseMetric
-
-
API Reference
evallmapplication
-
API Reference
evallm
MetricsCatalog
A global catalog that keeps track of distinct available metrics.
Implements the Catalog protocol by maintaining an internal registry of metric
names mapped to their corresponding BaseMetric[SerializableValueType] subclasses.
Provides methods for looking up metric classes by name and renaming registered
metrics.
Important
In order for metrics to be registered in the catalog, the module in which they are defined and decorated has to be imported.
-
API Reference
evallmmetricsmetrics Extension Path for Custom Metrics 3. Registering your metric
-
API Reference
evallm
| METHOD | DESCRIPTION |
|---|---|
get_metric |
Get the metric class corresponding to the given name. |
available |
Get a list of registered metrics' names. |
is_registered |
Check if a given metric is registered in the catalog. |
register |
Registers a metric in the catalog. |
rename_metric |
Renames a metric and updates its references in the catalog. |
Functions
get_metric
classmethod
get_metric(name: str) -> type[BaseMetric[SerializableValueType]]
Get the metric class corresponding to the given name.
| PARAMETER | DESCRIPTION |
|---|---|
name
|
The name of the metric to retrieve.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
metric
|
The metric class corresponding to the given name.
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
KeyError
|
If no metric with the given name is registered in the catalog. |
Source code in src/evallm/metrics/registry.py
available
classmethod
Get a list of registered metrics' names.
| RETURNS | DESCRIPTION |
|---|---|
names
|
A list of the names of all metrics currently registered in the catalog. |
-
API Reference
evallmapplication
Source code in src/evallm/metrics/registry.py
is_registered
classmethod
is_registered(
metric: BaseMetric[SerializableValueType] | type[BaseMetric[SerializableValueType]],
) -> bool
Check if a given metric is registered in the catalog.
| PARAMETER | DESCRIPTION |
|---|---|
metric
|
A metric to check for. Can be
either a
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
bool
|
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
TypeError
|
If the provided |
Source code in src/evallm/metrics/registry.py
register
classmethod
register(metric: type[BaseMetric[SerializableValueType]]) -> None
Registers a metric in the catalog.
| PARAMETER | DESCRIPTION |
|---|---|
metric
|
The
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
TypeError
|
If trying to register a class that is not a subclass of
|
ValueError
|
If a metric with the same name is already registered. |
Source code in src/evallm/metrics/registry.py
rename_metric
classmethod
Renames a metric and updates its references in the catalog.
| PARAMETER | DESCRIPTION |
|---|---|
old_name
|
The current name of the metric to rename.
TYPE:
|
new_name
|
The new name to assign to the metric.
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
KeyError
|
If no metric with |
ValueError
|
If
|
Source code in src/evallm/metrics/registry.py
Functions
register_metric
register_metric(
cls: type[BaseMetric[SerializableValueType]],
) -> type[BaseMetric[SerializableValueType]]
register_metric(
cls: None = None,
/,
*,
catalog: type[Catalog] = MetricsCatalog,
name: str | None = None,
) -> Callable[
[type[BaseMetric[SerializableValueType]]], type[BaseMetric[SerializableValueType]]
]
Decorator for registering a metric class in a global Catalog class.
Decorated metric classes are automatically registered at import time and thus the module in which a given metric is defined has to be imported in order for it to become available for lookup in the catalog.
Tip
You can use a custom catalog in which to register your metrics (e.g. because
you want to maintain separate catalogs for different types of metrics) by
implementing the Catalog protocol.
| PARAMETER | DESCRIPTION |
|---|---|
catalog
|
An optional
TYPE:
|
name
|
An optional name to register the metric under. Must be unique among registered metric names in the catalog, and cannot be an empty string if provided. If not provided, the metric will be registered under its class name.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
type[BaseMetric[SerializableValueType]] | Callable[[type[BaseMetric[SerializableValueType]]], type[BaseMetric[SerializableValueType]]]
|
decorator
(type[BaseMetric[SerializableValueType]] | Callable[
[type[BaseMetric[SerializableValueType]]],
type[BaseMetric[SerializableValueType]]]): The decorated metric class (
|
| RAISES | DESCRIPTION |
|---|---|
TypeError
|
If
|
UnserializableValueTypeError
|
If the value type |
ValueError
|
If
|
-
API Reference
evallm
Source code in src/evallm/metrics/registry.py
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 | |