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 str or a sequence of str.

y_predsequence or mapping

Predicted answer per item (str), aligned with y_true.

normalize{“squad”, “basic”, None}, default=”squad”

Normalisation before tokenisation.

tokenizercallable or None, default=None

tokenizer(text) -> sequence of str; None splits on whitespace.

sample_weightarray-like of shape (n_items,), default=None

Per-item weights of the mean.

average{“mean”, None}, default=”mean”

None returns 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:

Any

Examples

>>> token_f1_score(["the cat sat"], ["a cat sat down"])
0.8