Commit 5c1f194b authored by Baber's avatar Baber
Browse files

fix metric

parent 6c7c413d
...@@ -7,7 +7,7 @@ output_type: generate_until ...@@ -7,7 +7,7 @@ output_type: generate_until
test_split: test test_split: test
download_dataset: !function utils.niah_single_1 download_dataset: !function utils.niah_single_1
doc_to_text: "{{input}}" doc_to_text: "{{input}}"
doc_to_target: "{{outputs[0]}}" doc_to_target: "{{outputs}}"
process_results: !function utils.process_results process_results: !function utils.process_results
metric_list: metric_list:
......
...@@ -181,16 +181,27 @@ def postprocess_pred(predict_str: str) -> str: ...@@ -181,16 +181,27 @@ def postprocess_pred(predict_str: str) -> str:
return predict_str return predict_str
def string_match_all(preds: list[str], refs: list[list[str]]) -> float:
score = sum(
[
sum([1.0 if r.lower() in pred.lower() else 0.0 for r in ref]) / len(ref)
for pred, ref in zip(preds, refs)
]
) / len(preds)
return score
def process_results(doc: dict, results: list[str]) -> dict[str, float]: def process_results(doc: dict, results: list[str]) -> dict[str, float]:
# hacky: set all other lengths to -1 # hacky: set all other lengths to -1
metrics = {str(length): -1.0 for length in SEQ_LENGTHS} metrics = {str(length): -1.0 for length in SEQ_LENGTHS}
input_len = doc["max_length"] input_len = doc["max_length"]
acc = 1.0 if postprocess_pred(results[0]) in doc["input"] else 0.0 pred = postprocess_pred(results[0])
metrics[str(input_len)] = acc score = string_match_all([pred], [doc["outputs"]])
metrics[str(input_len)] = score
return metrics return metrics
def aggregate_metrics(metrics: list[int]) -> float: def aggregate_metrics(metrics: list[float]) -> float:
res = [x for x in metrics if x != -1] res = [x for x in metrics if x != -1]
if not res: if not res:
# we don't have any samples with this length # we don't have any samples with this length
......
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