File size: 766 Bytes
3891395
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
from typing import Union, Dict

from evaluation.evaluate_utils.evaluate_dicts import evaluate_dicts
from evaluation.evaluate_utils.evaluate_numbers import evaluate_numbers
from evaluation.evaluate_utils.evaluate_strings import evaluate_strings

EvaluatorFactory = {
    "string": evaluate_strings,
    "number": evaluate_numbers,
    "json": evaluate_dicts,
    "string list": evaluate_strings,
}

EvaluatorFactoryFromType = {
    str: evaluate_strings,
    int: evaluate_numbers,
    float: evaluate_numbers,
    bool: evaluate_strings,
    list: evaluate_strings
}


def get_evaluator(evaluator: str):
    return EvaluatorFactory[evaluator]


def get_evaluator_from_gold_answer(gold_answer: Union[str, int, float]):
    return EvaluatorFactoryFromType[gold_answer]