MCPcopy Create free account
hub / github.com/huggingface/evaluate / _compute

Method _compute

metrics/seqeval/seqeval.py:120–164  ·  view source on GitHub ↗
(
        self,
        predictions,
        references,
        suffix: bool = False,
        scheme: Optional[str] = None,
        mode: Optional[str] = None,
        sample_weight: Optional[List[int]] = None,
        zero_division: Union[str, int] = "warn",
    )

Source from the content-addressed store, hash-verified

118 )
119
120 def _compute(
121 self,
122 predictions,
123 references,
124 suffix: bool = False,
125 scheme: Optional[str] = None,
126 mode: Optional[str] = None,
127 sample_weight: Optional[List[int]] = None,
128 zero_division: Union[str, int] = "warn",
129 ):
130 if scheme is not None:
131 try:
132 scheme_module = importlib.import_module("seqeval.scheme")
133 scheme = getattr(scheme_module, scheme)
134 except AttributeError:
135 raise ValueError(f"Scheme should be one of [IOB1, IOB2, IOE1, IOE2, IOBES, BILOU], got {scheme}")
136 report = classification_report(
137 y_true=references,
138 y_pred=predictions,
139 suffix=suffix,
140 output_dict=True,
141 scheme=scheme,
142 mode=mode,
143 sample_weight=sample_weight,
144 zero_division=zero_division,
145 )
146 report.pop("macro avg")
147 report.pop("weighted avg")
148 overall_score = report.pop("micro avg")
149
150 scores = {
151 type_name: {
152 "precision": score["precision"],
153 "recall": score["recall"],
154 "f1": score["f1-score"],
155 "number": score["support"],
156 }
157 for type_name, score in report.items()
158 }
159 scores["overall_precision"] = overall_score["precision"]
160 scores["overall_recall"] = overall_score["recall"]
161 scores["overall_f1"] = overall_score["f1-score"]
162 scores["overall_accuracy"] = accuracy_score(y_true=references, y_pred=predictions)
163
164 return scores

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected