Skip to content

squad

allennlp_models.rc.tools.squad

[SOURCE]


Functions taken from the official evaluation script for SQuAD version 2.0.

make_qid_to_has_ans#

def make_qid_to_has_ans(dataset)

normalize_answer#

def normalize_answer(s)

Lower text and remove punctuation, articles and extra whitespace.

get_tokens#

def get_tokens(s)

compute_exact#

def compute_exact(a_pred: str, a_gold: str) -> int

compute_f1#

def compute_f1(a_pred: str, a_gold: str) -> float

metric_max_over_ground_truths#

def metric_max_over_ground_truths(
    metric_fn: Callable[[_P, _G], _T],
    prediction: _P,
    ground_truths: Sequence[_G]
) -> _T

get_metric_score#

def get_metric_score(
    prediction: str,
    gold_answers: Sequence[str]
) -> Tuple[int, float]