TermCoverageGrader#

class scikitplot.corpus.TermCoverageGrader(top_k=3, accept=0.8, reject=0.3)[source]#

Grade hits by the share of the query’s words their text contains.

coverage = |query words found in the top hits| / |query words|, with words \w+ lower-cased and counted once. Coverage at or above accept is correct; at or below reject is incorrect; between is ambiguous. No hits, or a query without a word, is incorrect with score 0.

Parameters:
top_kint, default=3

Hits whose text is read.

acceptfloat, default=0.8

Coverage from which the evidence is correct.

rejectfloat, default=0.3

Coverage up to which it is incorrect; below accept.

Raises:
TypeError, ValueError

If top_k is not a positive int or the thresholds are not 0 <= reject < accept <= 1.

Parameters:

Examples

>>> from types import SimpleNamespace as NS
>>> from scikitplot.corpus import TermCoverageGrader
>>> hit = NS(doc=NS(text="chunk spans are slices of the source"))
>>> TermCoverageGrader()("chunk spans", [hit]).grade.value
'correct'
>>> TermCoverageGrader()("chunk embeddings cache", [hit]).grade.value
'ambiguous'
__call__(query, hits)[source]#

Grade hits for query.

Parameters:
querystr

The query the hits are evidence for.

hitsiterable

Ranked hits; hit.doc.text (or hit.text) is read, and a hit without text contributes no word.

Returns:
GradeResult
Parameters:
Return type:

GradeResult

accept: float = 0.8#
reject: float = 0.3#
top_k: int = 3#