Unverified Commit 5680a2e6 authored by Baber Abbasi's avatar Baber Abbasi Committed by GitHub
Browse files

Filters bugfix; add `metrics` and `filter` to logged sample (#2517)

* allow !function filters

* bugfix

* nit

* add `filter` to logged samples

* add `filter` and `metric` to logged samples to identification

* convert `metric` to `metrics`: list
parent 0ef7548d
import logging
from typing import Callable, Dict
from typing import Callable, Dict, Union
import evaluate as hf_evaluate
......@@ -185,8 +185,12 @@ def register_filter(name):
return decorate
def get_filter(filter_name: str) -> type:
def get_filter(filter_name: Union[str, Callable]) -> Callable:
try:
return FILTER_REGISTRY[filter_name]
except KeyError:
eval_logger.warning(f"filter `{filter_name}` is not registered!")
except KeyError as e:
if callable(filter_name):
return filter_name
else:
eval_logger.warning(f"filter `{filter_name}` is not registered!")
raise e
......@@ -552,6 +552,8 @@ def evaluate(
"filtered_resps": [
req.filtered_resps[filter_key] for req in requests
],
"filter": filter_key,
"metrics": list(metrics.keys()),
"doc_hash": hash_string(
json.dumps(
requests[0].doc,
......
......@@ -37,16 +37,18 @@ class RegexFilter(Filter):
if match:
match = match[self.group_select]
if isinstance(match, tuple):
match = [m for m in match if m][0]
match = [m for m in match if m]
if match:
match = match[0]
else:
match = self.fallback
match = match.strip()
else:
match = self.fallback
filtered.append(match)
return filtered
# print(resps)
filtered_resps = list(map(lambda x: filter_set(x), resps))
# print(filtered_resps)
return filtered_resps
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment