Spaces:
Runtime error
Runtime error
Update Space (evaluate main: c447fc8e)
Browse files- requirements.txt +1 -1
- seqeval.py +13 -30
requirements.txt
CHANGED
@@ -1,2 +1,2 @@
|
|
1 |
-
git+https://github.com/huggingface/evaluate@
|
2 |
seqeval
|
|
|
1 |
+
git+https://github.com/huggingface/evaluate@c447fc8eda9c62af501bfdc6988919571050d950
|
2 |
seqeval
|
seqeval.py
CHANGED
@@ -14,7 +14,6 @@
|
|
14 |
""" seqeval metric. """
|
15 |
|
16 |
import importlib
|
17 |
-
from dataclasses import dataclass
|
18 |
from typing import List, Optional, Union
|
19 |
|
20 |
import datasets
|
@@ -100,31 +99,14 @@ Examples:
|
|
100 |
"""
|
101 |
|
102 |
|
103 |
-
@dataclass
|
104 |
-
class SeqevalConfig(evaluate.info.Config):
|
105 |
-
|
106 |
-
name: str = "default"
|
107 |
-
|
108 |
-
suffix: bool = False
|
109 |
-
scheme: Optional[str] = None
|
110 |
-
mode: Optional[str] = None
|
111 |
-
sample_weight: Optional[List[int]] = None
|
112 |
-
zero_division: Union[str, int] = "warn"
|
113 |
-
|
114 |
-
|
115 |
@evaluate.utils.file_utils.add_start_docstrings(_DESCRIPTION, _KWARGS_DESCRIPTION)
|
116 |
class Seqeval(evaluate.Metric):
|
117 |
-
|
118 |
-
CONFIG_CLASS = SeqevalConfig
|
119 |
-
ALLOWED_CONFIG_NAMES = ["default"]
|
120 |
-
|
121 |
-
def _info(self, config):
|
122 |
return evaluate.MetricInfo(
|
123 |
description=_DESCRIPTION,
|
124 |
citation=_CITATION,
|
125 |
homepage="https://github.com/chakki-works/seqeval",
|
126 |
inputs_description=_KWARGS_DESCRIPTION,
|
127 |
-
config=config,
|
128 |
features=datasets.Features(
|
129 |
{
|
130 |
"predictions": datasets.Sequence(datasets.Value("string", id="label"), id="sequence"),
|
@@ -139,26 +121,27 @@ class Seqeval(evaluate.Metric):
|
|
139 |
self,
|
140 |
predictions,
|
141 |
references,
|
|
|
|
|
|
|
|
|
|
|
142 |
):
|
143 |
-
if
|
144 |
try:
|
145 |
scheme_module = importlib.import_module("seqeval.scheme")
|
146 |
-
scheme = getattr(scheme_module,
|
147 |
except AttributeError:
|
148 |
-
raise ValueError(
|
149 |
-
f"Scheme should be one of [IOB1, IOB2, IOE1, IOE2, IOBES, BILOU], got {self.config.scheme}"
|
150 |
-
)
|
151 |
-
else:
|
152 |
-
scheme = self.config.scheme
|
153 |
report = classification_report(
|
154 |
y_true=references,
|
155 |
y_pred=predictions,
|
156 |
-
suffix=
|
157 |
output_dict=True,
|
158 |
scheme=scheme,
|
159 |
-
mode=
|
160 |
-
sample_weight=
|
161 |
-
zero_division=
|
162 |
)
|
163 |
report.pop("macro avg")
|
164 |
report.pop("weighted avg")
|
|
|
14 |
""" seqeval metric. """
|
15 |
|
16 |
import importlib
|
|
|
17 |
from typing import List, Optional, Union
|
18 |
|
19 |
import datasets
|
|
|
99 |
"""
|
100 |
|
101 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
102 |
@evaluate.utils.file_utils.add_start_docstrings(_DESCRIPTION, _KWARGS_DESCRIPTION)
|
103 |
class Seqeval(evaluate.Metric):
|
104 |
+
def _info(self):
|
|
|
|
|
|
|
|
|
105 |
return evaluate.MetricInfo(
|
106 |
description=_DESCRIPTION,
|
107 |
citation=_CITATION,
|
108 |
homepage="https://github.com/chakki-works/seqeval",
|
109 |
inputs_description=_KWARGS_DESCRIPTION,
|
|
|
110 |
features=datasets.Features(
|
111 |
{
|
112 |
"predictions": datasets.Sequence(datasets.Value("string", id="label"), id="sequence"),
|
|
|
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")
|