Upload metric.py with huggingface_hub
Browse files
metric.py
CHANGED
|
@@ -15,6 +15,7 @@ from .dataclass import __file__ as _
|
|
| 15 |
from .file_utils import __file__ as _
|
| 16 |
from .fusion import __file__ as _
|
| 17 |
from .generator_utils import __file__ as _
|
|
|
|
| 18 |
from .instructions import __file__ as _
|
| 19 |
from .load import __file__ as _
|
| 20 |
from .loaders import __file__ as _
|
|
@@ -47,6 +48,7 @@ from .stream import __file__ as _
|
|
| 47 |
from .task import __file__ as _
|
| 48 |
from .templates import __file__ as _
|
| 49 |
from .text_utils import __file__ as _
|
|
|
|
| 50 |
from .utils import __file__ as _
|
| 51 |
from .validate import __file__ as _
|
| 52 |
|
|
@@ -112,6 +114,20 @@ class MetricRecipe(SequntialOperatorInitilizer):
|
|
| 112 |
UNITXT_METRIC_SCHEMA = Features({"predictions": Value("string"), "references": dict(UNITXT_DATASET_SCHEMA)})
|
| 113 |
|
| 114 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 115 |
# @evaluate.utils.file_utils.add_start_docstrings(_DESCRIPTION, _KWARGS_DESCRIPTION)
|
| 116 |
class Metric(evaluate.Metric):
|
| 117 |
def _info(self):
|
|
@@ -128,14 +144,4 @@ class Metric(evaluate.Metric):
|
|
| 128 |
)
|
| 129 |
|
| 130 |
def _compute(self, predictions: List[str], references: Iterable, flatten: bool = False, split_name: str = "all"):
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
multi_stream = recipe(predictions=predictions, references=references, split_name=split_name)
|
| 134 |
-
|
| 135 |
-
if flatten:
|
| 136 |
-
operator = FlattenInstances()
|
| 137 |
-
multi_stream = operator(multi_stream)
|
| 138 |
-
|
| 139 |
-
stream = multi_stream[split_name]
|
| 140 |
-
|
| 141 |
-
return list(stream)
|
|
|
|
| 15 |
from .file_utils import __file__ as _
|
| 16 |
from .fusion import __file__ as _
|
| 17 |
from .generator_utils import __file__ as _
|
| 18 |
+
from .hf_utils import __file__ as _
|
| 19 |
from .instructions import __file__ as _
|
| 20 |
from .load import __file__ as _
|
| 21 |
from .loaders import __file__ as _
|
|
|
|
| 48 |
from .task import __file__ as _
|
| 49 |
from .templates import __file__ as _
|
| 50 |
from .text_utils import __file__ as _
|
| 51 |
+
from .type_utils import __file__ as _
|
| 52 |
from .utils import __file__ as _
|
| 53 |
from .validate import __file__ as _
|
| 54 |
|
|
|
|
| 114 |
UNITXT_METRIC_SCHEMA = Features({"predictions": Value("string"), "references": dict(UNITXT_DATASET_SCHEMA)})
|
| 115 |
|
| 116 |
|
| 117 |
+
def _compute(predictions: List[str], references: Iterable, flatten: bool = False, split_name: str = "all"):
|
| 118 |
+
recipe = MetricRecipe()
|
| 119 |
+
|
| 120 |
+
multi_stream = recipe(predictions=predictions, references=references, split_name=split_name)
|
| 121 |
+
|
| 122 |
+
if flatten:
|
| 123 |
+
operator = FlattenInstances()
|
| 124 |
+
multi_stream = operator(multi_stream)
|
| 125 |
+
|
| 126 |
+
stream = multi_stream[split_name]
|
| 127 |
+
|
| 128 |
+
return list(stream)
|
| 129 |
+
|
| 130 |
+
# TODO: currently we have two classes with this name. metric.Metric and matrics.Metric...
|
| 131 |
# @evaluate.utils.file_utils.add_start_docstrings(_DESCRIPTION, _KWARGS_DESCRIPTION)
|
| 132 |
class Metric(evaluate.Metric):
|
| 133 |
def _info(self):
|
|
|
|
| 144 |
)
|
| 145 |
|
| 146 |
def _compute(self, predictions: List[str], references: Iterable, flatten: bool = False, split_name: str = "all"):
|
| 147 |
+
return _compute(predictions=predictions, references=references, flatten=flatten, split_name=split_name)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|