Metric
Provides the Metric base class, which defines the interface of metrics.
Classes:
| Name | Description |
|---|---|
Metric |
Base class, defining the interface of metrics. |
Metric
Simple base class / interface definition for metrics.
Methods:
| Name | Description |
|---|---|
reset |
To reset all internal states. Must be implemented by the subclass. |
update |
Calls the private _update method, which must be implemented by the subclass. Used to update internal states with new data. |
compute |
Calls the private _compute method, which must be implemented by the subclass. Used to compute and return the metric results. |
show_result |
Utility method to print the metric result in a readable format. |
reset()
Reset all internal states.
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
Subclasses must implement this method. |
Source code in src/kibad_llm/metric.py
26 27 28 29 30 31 32 | |
update(prediction, reference, record_id=None)
Calls the private _update method to update internal states with new data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prediction
|
Any
|
Predictions made in a dataset. |
required |
reference
|
Any
|
Gold data to compare the predictions to. |
required |
record_id
|
Hashable | None
|
Id to tag the comparison with. |
None
|
Source code in src/kibad_llm/metric.py
47 48 49 50 51 52 53 54 55 | |
compute(*args, reset=True, **kwargs)
Wrapper for _compute.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*args
|
Any
|
Positional args forwarded to the |
()
|
Other Parameters:
| Name | Type | Description |
|---|---|---|
reset |
bool
|
If |
**kwargs |
Any
|
Keyword args forwarded to the |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
result of the evaluation. |
Source code in src/kibad_llm/metric.py
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 | |
show_result(result=None, reset=True)
Utility method to print the metric result in a readable format.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
result
|
dict[str, Any] | None
|
Dict to pretty-print as JSON string or None to compute the result with |
None
|
reset
|
bool
|
Whether to reset after using |
True
|
Source code in src/kibad_llm/metric.py
94 95 96 97 98 99 100 101 102 103 104 | |