make_pairwise_ranker#

scikitplot.corpus.make_pairwise_ranker(score_func, *, greater_is_better=True, use_normalized_text=True, score_cutoff=None, name=None, **kwargs)[source]#

Make a CustomRetrievalIndex ranker from a pairwise function.

Parameters:
score_funccallable

score_func(query, text, **kwargs) -> float, for example edit_similarity, a RapidFuzz ratio or a cross-encoder.

greater_is_betterbool, default=True

False for a distance, which is negated so higher is better.

use_normalized_textbool, default=True

Compare with normalized_text when a document has one.

score_cutofffloat or None, default=None

Minimum (signed) score of a returned hit.

namestr or None, default=None

Recorded as each hit’s native_metric.

**kwargsdict

Passed to score_func on every call.

Returns:
PairwiseRanker
Raises:
TypeError

For a non-callable score_func, non-bool flags, or kwargs that do not fit its signature.

ValueError

For a non-finite score_cutoff.

Parameters:
Return type:

PairwiseRanker

See also

make_levenshtein_ranker

The Levenshtein ranker with backend provenance.

Examples

>>> from scikitplot.corpus import (
...     CorpusDocument,
...     CustomRetrievalIndex,
...     edit_similarity,
...     make_pairwise_ranker,
... )
>>> index = CustomRetrievalIndex(
...     custom_scorer_fn=make_pairwise_ranker(edit_similarity)
... )
>>> index.build(
...     [
...         CorpusDocument.create("a.txt", 0, "kitten"),
...         CorpusDocument.create("b.txt", 0, "sitting"),
...     ]
... )
>>> [hit.doc.text for hit in index.search("kitten")]
['kitten', 'sitting']