Skip to content

metric

The base class of the evaluation metrics in the tinyBIG toolkit.

...

Attributes:

Name Type Description
name str, default = 'base_metric'

Name of the evaluation metric.

Methods:

Name Description
__init__

It performs the initialization of the evaluation metric.

evaluate

It performs the evaluation based on the inputs.

__call__

It reimplementation the build-in callable method.

Source code in tinybig/metric/base_metric.py
class metric:
    """
    The base class of the evaluation metrics in the tinyBIG toolkit.

    ...

    Attributes
    ----------
    name: str, default = 'base_metric'
        Name of the evaluation metric.

    Methods
    ----------
    __init__
        It performs the initialization of the evaluation metric.

    evaluate
        It performs the evaluation based on the inputs.

    __call__
        It reimplementation the build-in callable method.
    """
    def __init__(self, name: str = 'base_metric', *args, **kwargs):
        """
        The initialization method of the base metric class.

        It initializes a metric object based on the provided method parameters.

        Parameters
        ----------
        name: str, default = 'base_metric'
            The name of the metric, with default value "base_metric".

        Returns
        ----------
        object
            The metric object.
        """
        self.name = name

    @staticmethod
    def from_config(configs: dict):
        if configs is None:
            raise ValueError("configs cannot be None")
        assert 'metric_class' in configs
        class_name = configs['metric_class']
        parameters = configs['metric_parameters'] if 'metric_parameters' in configs else {}
        return config.get_obj_from_str(class_name)(**parameters)

    def to_config(self):
        class_name = self.__class__.__name__
        attributes = {attr: getattr(self, attr) for attr in self.__dict__}

        return {
            "metric_class": class_name,
            "metric_parameters": attributes
        }

    @abstractmethod
    def evaluate(self, *args, **kwargs):
        """
        The evaluate method of the base metric class.

        It is declared to be an abstractmethod and needs to be implemented in the inherited evaluation metric classes.
        The evaluate method accepts prediction results and ground-truth results as inputs and return the evaluation metric scores as the outputs.

        Returns
        ----------
        float | dict
            The evaluation metric scores.
        """
        pass

    @abstractmethod
    def __call__(self, *args, **kwargs):
        """
        Reimplementation of the build-in callable method.

        It is declared to be an abstractmethod and needs to be implemented in the inherited evaluation metric classes.
        This callable method accepts prediction results and ground-truth results as inputs and return the evaluation metric scores as the outputs.

        Returns
        ----------
        float | dict
            The evaluation metric scores.
        """
        pass

__call__(*args, **kwargs) abstractmethod

Reimplementation of the build-in callable method.

It is declared to be an abstractmethod and needs to be implemented in the inherited evaluation metric classes. This callable method accepts prediction results and ground-truth results as inputs and return the evaluation metric scores as the outputs.

Returns:

Type Description
float | dict

The evaluation metric scores.

Source code in tinybig/metric/base_metric.py
@abstractmethod
def __call__(self, *args, **kwargs):
    """
    Reimplementation of the build-in callable method.

    It is declared to be an abstractmethod and needs to be implemented in the inherited evaluation metric classes.
    This callable method accepts prediction results and ground-truth results as inputs and return the evaluation metric scores as the outputs.

    Returns
    ----------
    float | dict
        The evaluation metric scores.
    """
    pass

__init__(name='base_metric', *args, **kwargs)

The initialization method of the base metric class.

It initializes a metric object based on the provided method parameters.

Parameters:

Name Type Description Default
name str

The name of the metric, with default value "base_metric".

'base_metric'

Returns:

Type Description
object

The metric object.

Source code in tinybig/metric/base_metric.py
def __init__(self, name: str = 'base_metric', *args, **kwargs):
    """
    The initialization method of the base metric class.

    It initializes a metric object based on the provided method parameters.

    Parameters
    ----------
    name: str, default = 'base_metric'
        The name of the metric, with default value "base_metric".

    Returns
    ----------
    object
        The metric object.
    """
    self.name = name

evaluate(*args, **kwargs) abstractmethod

The evaluate method of the base metric class.

It is declared to be an abstractmethod and needs to be implemented in the inherited evaluation metric classes. The evaluate method accepts prediction results and ground-truth results as inputs and return the evaluation metric scores as the outputs.

Returns:

Type Description
float | dict

The evaluation metric scores.

Source code in tinybig/metric/base_metric.py
@abstractmethod
def evaluate(self, *args, **kwargs):
    """
    The evaluate method of the base metric class.

    It is declared to be an abstractmethod and needs to be implemented in the inherited evaluation metric classes.
    The evaluate method accepts prediction results and ground-truth results as inputs and return the evaluation metric scores as the outputs.

    Returns
    ----------
    float | dict
        The evaluation metric scores.
    """
    pass