def summary(
        self,
        normalize_by_coverage: bool = False,
        annotation: Optional[np.ndarray] = None,
    ) -> pd.DataFrame:
        """Returns following summary statistics for each rule:

        - **label**: Set of unique labels returned by the rule, excluding "None" (abstain).
        - **coverage**: Fraction of the records labeled by the rule.
        - **annotated_coverage**: Fraction of annotated records labeled by the rule (if annotations are available).
        - **overlaps**: Fraction of the records labeled by the rule together with at least one other rule.
        - **correct**: Number of labels the rule predicted correctly (if annotations are available).
        - **incorrect**: Number of labels the rule predicted incorrectly or missed (if annotations are available).
        - **precision**: Fraction of correct labels given by the rule (if annotations are available). The precision does not penalize the rule for abstains.

        Args:
            normalize_by_coverage: Normalize the overlaps by the respective coverage.
            annotation: An optional matrix with ints holding the annotations (see ``self.annotation``).
                By default, we will use ``self.annotation(include_missing=True)``.

        Returns:
            The summary statistics for each rule in a pandas DataFrame.
        """
        annotation = annotation if annotation is not None else self._annotation
        has_weak_label = self.matrix().sum(2) >= 0

        # polarity (label)
        polarity = [
            set(
                [
                    self._labels[i]
                    # get indices of votes
                    for i in np.nonzero(
                        # remove abstentions
                        self.matrix()[:, m, :][self.matrix()[:, m, :].sum(1) >= 0]
                    )[1]
                ]
            )
            for m in range(len(self._rules))
        ]
        polarity.append(set().union(*polarity))

        # coverage
        coverage = has_weak_label.sum(axis=0) / len(self._records)
        coverage = np.append(
            coverage,
            (has_weak_label.sum(axis=1) > 0).sum() / len(self._records),
        )

        # overlaps
        has_overlaps = has_weak_label.sum(axis=1) > 1
        overlaps = self._compute_overlaps_conflicts(has_weak_label, has_overlaps, coverage, normalize_by_coverage)

        # index for the summary
        index = list(self._rules_name2index.keys()) + ["total"]

        # only add annotated_coverage, correct, incorrect and precision if we have annotations
        has_annotation = annotation.sum(1) >= 0
        if any(has_annotation):
            # annotated coverage
            annotated_coverage = has_weak_label[has_annotation].sum(axis=0) / has_annotation.sum()
            annotated_coverage = np.append(
                annotated_coverage,
                (has_weak_label[has_annotation].sum(axis=1) > 0).sum() / has_annotation.sum(),
            )

            # correct/incorrect
            correct, incorrect = self._compute_correct_incorrect(annotation)

            # precision, ignore division by 0 warnings: we allow np.nan and np.inf
            with np.errstate(divide="ignore", invalid="ignore"):
                precision = correct / (correct + incorrect)

            return pd.DataFrame(
                {
                    "label": polarity,
                    "coverage": coverage,
                    "annotated_coverage": annotated_coverage,
                    "overlaps": overlaps,
                    "correct": correct,
                    "incorrect": incorrect,
                    "precision": precision,
                },
                index=index,
            )

        return pd.DataFrame(
            {
                "label": polarity,
                "coverage": coverage,
                "overlaps": overlaps,
            },
            index=index,
        )
Returns following summary statistics for each rule:

        - **label**: Set of unique labels returned by the rule, excluding "None" (abstain).
        - **coverage**: Fraction of the records labeled by the rule.
        - **annotated_coverage**: Fraction of annotated records labeled by the rule (if annotations are available).
        - **overlaps**: Fraction of the records labeled by the rule together with at least one other rule.
        - **correct**: Number of labels the rule predicted correctly (if annotations are available).
        - **incorrect**: Number of labels the rule predicted incorrectly or missed (if annotations are available).
        - **precision**: Fraction of correct labels given by the rule (if annotations are available). The precision does not penalize the rule for abstains.

        Args:
            normalize_by_coverage: Normalize the overlaps by the respective coverage.
            annotation: An optional matrix with ints holding the annotations (see ``self.annotation``).
                By default, we will use ``self.annotation(include_missing=True)``.

        Returns:
            The summary statistics for each rule in a pandas DataFrame.
        
argilla-v1/src/argilla_v1/labeling/text_classification/weak_labels.py