token_f1_score#
- scikitplot.corpus.token_f1_score(y_true, y_pred, *, normalize='squad', tokenizer=None, sample_weight=None, average='mean')[source]#
Token-overlap F1 between predicted and reference answers (SQuAD style).
- Parameters:
- y_truesequence or mapping
Reference answers per item: a
stror a sequence ofstr.- y_predsequence or mapping
Predicted answer per item (
str), aligned withy_true.- normalize{“squad”, “basic”, None}, default=”squad”
Normalisation before tokenisation.
- tokenizercallable or None, default=None
tokenizer(text) -> sequence of str;Nonesplits on whitespace.- sample_weightarray-like of shape (n_items,), default=None
Per-item weights of the mean.
- average{“mean”, None}, default=”mean”
Nonereturns per-item values.
- Returns:
- float or numpy.ndarray
Per item, the best F1 over its references. Two empty token lists score 1; one empty list scores 0.
- Raises:
- TypeError, ValueError
For malformed inputs or a tokenizer that does not return strings.
- Parameters:
- Return type:
Examples
>>> token_f1_score(["the cat sat"], ["a cat sat down"]) 0.8