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
CustomRetrievalIndexranker from a pairwise function.- Parameters:
- score_funccallable
score_func(query, text, **kwargs) -> float, for exampleedit_similarity, a RapidFuzz ratio or a cross-encoder.- greater_is_betterbool, default=True
Falsefor a distance, which is negated so higher is better.- use_normalized_textbool, default=True
Compare with
normalized_textwhen 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_funcon every call.
- Returns:
- PairwiseRanker
- Raises:
- TypeError
For a non-callable
score_func, non-bool flags, orkwargsthat do not fit its signature.- ValueError
For a non-finite
score_cutoff.
- Parameters:
- Return type:
See also
make_levenshtein_rankerThe 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']