Skip to content

Recall metric

Bases: FBetaScore

Computes token-level recall for LM string outputs.

Formula (per field, SQuAD-style multiset over normalized tokens):

recall = |Counter(y_true_tokens)  Counter(y_pred_tokens)| / |y_true_tokens|

Mirrors F1Score: tokenization, masking and average modes behave identically; only the result formula differs.

Example:

program.compile(
    metrics=[
        synalinks.metrics.Recall(),
    ],
)

Parameters:

Name Type Description Default
average str

Type of averaging across per-field results. One of None, "micro", "macro", "weighted".

None
name str

(Optional) string name of the metric instance.

'recall'
in_mask list

(Optional) list of keys to keep to compute the metric.

None
out_mask list

(Optional) list of keys to remove to compute the metric.

None
in_mask_pattern str

(Optional) Regex pattern; fields whose names match are kept (combined with in_mask via OR).

None
out_mask_pattern str

(Optional) Regex pattern; fields whose names match are dropped (combined with out_mask via OR).

None
Source code in synalinks/src/metrics/precision_recall_metrics.py
@synalinks_export("synalinks.metrics.Recall")
class Recall(FBetaScore):
    """Computes token-level recall for LM string outputs.

    Formula (per field, SQuAD-style multiset over normalized tokens):

    ```python
    recall = |Counter(y_true_tokens) ∩ Counter(y_pred_tokens)| / |y_true_tokens|
    ```

    Mirrors `F1Score`: tokenization, masking and `average` modes behave
    identically; only the result formula differs.


    Example:

    ```python
    program.compile(
        metrics=[
            synalinks.metrics.Recall(),
        ],
    )
    ```

    Args:
        average (str): Type of averaging across per-field results.
            One of `None`, `"micro"`, `"macro"`, `"weighted"`.
        name (str): (Optional) string name of the metric instance.
        in_mask (list): (Optional) list of keys to keep to compute the metric.
        out_mask (list): (Optional) list of keys to remove to compute the metric.
        in_mask_pattern (str): (Optional) Regex pattern; fields whose names match
            are kept (combined with ``in_mask`` via OR).
        out_mask_pattern (str): (Optional) Regex pattern; fields whose names match
            are dropped (combined with ``out_mask`` via OR).
    """

    def __init__(
        self,
        average=None,
        name="recall",
        in_mask=None,
        out_mask=None,
        in_mask_pattern=None,
        out_mask_pattern=None,
    ):
        super().__init__(
            average=average,
            beta=1.0,
            name=name,
            in_mask=in_mask,
            out_mask=out_mask,
            in_mask_pattern=in_mask_pattern,
            out_mask_pattern=out_mask_pattern,
        )
        self._formula = "recall"

    def get_config(self):
        base_config = super().get_config()
        del base_config["beta"]
        return base_config