metric
METRIC_REGISTRY = MetricRegistry() module-attribute ¶
Registry for metrics.
Contains the recnexteval metrics by default and allows registration of new metrics via the register function.
Example
from recnexteval.pipelines import METRIC_REGISTRY
# Construct a Recall object with parameter K=20
algo = METRIC_REGISTRY.get("Recall")(K=20)
from recnexteval.algorithms import Recall
METRIC_REGISTRY.register("HelloWorld", Recall)
# Also construct a Recall object with parameter K=20
algo = METRIC_REGISTRY.get("HelloWorld")(K=20)
MetricRegistry ¶
Registry for easy retrieval of metric types by name.
The registry comes preregistered with all the recnexteval metrics.
Source code in src/recnexteval/registries/metric.py
8 9 10 11 12 13 14 15 16 | |
IS_BASE = True class-attribute instance-attribute ¶
name property ¶
Name of the object's class.
:return: Name of the object's class :rtype: str
registered = {} instance-attribute ¶
src = src instance-attribute ¶
get(key) ¶
Retrieve the value for this key.
This value is a Python type, most often a class.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key | str | The key to fetch. | required |
Returns:
| Type | Description |
|---|---|
type[T] | The class type associated with the key. |
Raises:
| Type | Description |
|---|---|
KeyError | If the key is not found in the registry. |
Source code in src/recnexteval/registries/base.py
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 | |
register(key, cls) ¶
Register a new Python type (most often a class).
After registration, the key can be used to fetch the Python type from the registry.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key | str | Key to register the type at. Needs to be unique to the registry. | required |
cls | type[T] | Class to register. | required |
Raises:
| Type | Description |
|---|---|
KeyError | If the key is already registered. |
Source code in src/recnexteval/registries/base.py
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 | |
get_registered_keys(include_base=False) ¶
Get a list of all registered keys.
Returns:
| Type | Description |
|---|---|
list[str] | A list of all registered keys. |
Source code in src/recnexteval/registries/base.py
106 107 108 109 110 111 112 113 114 115 | |
registered_values() ¶
Get a list of all registered types.
Returns:
| Type | Description |
|---|---|
list[type[T]] | A list of all registered types. |
Source code in src/recnexteval/registries/base.py
117 118 119 120 121 122 123 | |
registered_items() ¶
Get a list of all registered key-type pairs.
Returns:
| Type | Description |
|---|---|
list[tuple[str, type[T]]] | A list of all registered key-type pairs. |
Source code in src/recnexteval/registries/base.py
125 126 127 128 129 130 131 | |
MetricEntry ¶
Bases: NamedTuple
Entry for the metric registry.
The intended use of this class is to store the name of the metric and the top-K value for the metric specified by the user.
Mainly this will happen during the building phase of the evaluator pipeline in :class:Builder.
Attributes:
| Name | Type | Description |
|---|---|---|
name | str | Name of the algorithm. |
K | None | int | Top-K value for the metric. |
Source code in src/recnexteval/registries/metric.py
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | |