Spaces:
Sleeping
Sleeping
remove unnecesory data
Browse files- dicrect_compute_metric.py +0 -49
dicrect_compute_metric.py
DELETED
@@ -1,49 +0,0 @@
|
|
1 |
-
from typing import Optional
|
2 |
-
|
3 |
-
import evaluate
|
4 |
-
|
5 |
-
|
6 |
-
class DirectComputeMetric(evaluate.EvaluationModule):
|
7 |
-
"""
|
8 |
-
Base class for metrics that directly compute the score from the predictions and references without add_batch
|
9 |
-
"""
|
10 |
-
|
11 |
-
def compute(self, *, predictions=None, references=None, **kwargs) -> Optional[dict]:
|
12 |
-
"""Compute the evaluation module.
|
13 |
-
|
14 |
-
Usage of positional arguments is not allowed to prevent mistakes.
|
15 |
-
|
16 |
-
Args:
|
17 |
-
predictions (`list/array/tensor`, *optional*):
|
18 |
-
Predictions.
|
19 |
-
references (`list/array/tensor`, *optional*):
|
20 |
-
References.
|
21 |
-
**kwargs (optional):
|
22 |
-
Keyword arguments that will be forwarded to the evaluation module [`~evaluate.EvaluationModule.compute`]
|
23 |
-
method (see details in the docstring).
|
24 |
-
|
25 |
-
Return:
|
26 |
-
`dict` or `None`
|
27 |
-
|
28 |
-
- Dictionary with the results if this evaluation module is run on the main process (`process_id == 0`).
|
29 |
-
- `None` if the evaluation module is not run on the main process (`process_id != 0`).
|
30 |
-
|
31 |
-
```py
|
32 |
-
>>> import evaluate
|
33 |
-
>>> accuracy = evaluate.load("accuracy")
|
34 |
-
>>> accuracy.compute(predictions=[0, 1, 1, 0], references=[0, 1, 0, 1])
|
35 |
-
```
|
36 |
-
"""
|
37 |
-
all_kwargs = {"predictions": predictions, "references": references, **kwargs}
|
38 |
-
if predictions is None and references is None:
|
39 |
-
missing_kwargs = {k: None for k in self._feature_names() if k not in all_kwargs}
|
40 |
-
all_kwargs.update(missing_kwargs)
|
41 |
-
else:
|
42 |
-
missing_inputs = [k for k in self._feature_names() if k not in all_kwargs]
|
43 |
-
if missing_inputs:
|
44 |
-
raise ValueError(
|
45 |
-
f"Evaluation module inputs are missing: {missing_inputs}. All required inputs are {list(self._feature_names())}"
|
46 |
-
)
|
47 |
-
inputs = {input_name: all_kwargs[input_name] for input_name in self._feature_names()}
|
48 |
-
compute_kwargs = {k: kwargs[k] for k in kwargs if k not in self._feature_names()}
|
49 |
-
return self._compute(**inputs, **compute_kwargs)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|