frex.pipeline_stages.scorers package
Submodules
frex.pipeline_stages.scorers.candidate_bool_scorer module
- class frex.pipeline_stages.scorers.candidate_bool_scorer.CandidateBoolScorer(*, success_scoring_explanation: frex.models.explanation.Explanation, failure_scoring_explanation: frex.models.explanation.Explanation, **kwargs)[source]
Bases:
frex.pipeline_stages.pipeline_stage.PipelineStage
CandidateBoolScorer is a scoring pipeline stage that scores based on whether or not the candidate matches some given condition. The score function for this class returns a bool indicating whether the condition was matched, and an appropriate explanation is attached to the candidate.
- Parameters
success_scoring_explanation – The explanation to add to the Candidate after applying the scoring function if the score function indicates True.
failure_scoring_explanation – The explanation to add to the Candidate after applying the scoring function if the score function indicates False.
- __call__(*, candidates: Generator[frex.models.candidate.Candidate, None, None], context: Any) Generator[frex.models.candidate.Candidate, None, None] [source]
For each of candidate being yielded by the Generator, apply a scoring function to the candidate and yield it as output. Based on whether or not the scoring function passed some condition, different explanations are applied.
- Parameters
candidates – A Generator yielding candidates. In the setup of a FREx Pipeline, this is typically another PipelineStage that is yielding candidates into the next stage.
context – The current context being used to execute the Pipeline.
- Returns
A Generator, yielding updated Candidate objects that have this stage’s scoring function applied.
- abstract score(*, candidate: frex.models.candidate.Candidate) Tuple[bool, float] [source]
Apply a custom scoring function to the input candidate that also checks for the success of some condition.
- Parameters
candidate – A domain-specific candidate to apply the scoring function
- Returns
A tuple (x, y) where x is a boolean indicating whether the candidate passed some condition and y is the score applied to the candidate.
frex.pipeline_stages.scorers.candidate_ranker module
- class frex.pipeline_stages.scorers.candidate_ranker.CandidateRanker[source]
Bases:
frex.pipeline_stages.pipeline_stage.PipelineStage
CandidateRanker is a PipelineStage that will sort the current candidates. Sorting is performed based on the total_score property of candidates, which sums up the applied_scores currently applied to the candidate.
Sorting needs to collect all candidates coming in from the generator, so it should be used infrequently.
- __call__(*, candidates: Generator[frex.models.candidate.Candidate, None, None], context: Any) Generator[frex.models.candidate.Candidate, None, None] [source]
Collect all candidates being yielded by an input Generator, sort them based on their total_score, and yield the sorted candidates in descending order.
- Parameters
candidates – A Generator yielding candidates. In the setup of a FREx Pipeline, this is typically another PipelineStage that is yielding candidates into the next stage.
context – The current context being used to execute the Pipeline.
- Returns
A Generator, yielding Candidate objects in order based on their total_score property.
frex.pipeline_stages.scorers.candidate_scorer module
- class frex.pipeline_stages.scorers.candidate_scorer.CandidateScorer(*, scoring_explanation: frex.models.explanation.Explanation, **kwargs)[source]
Bases:
frex.pipeline_stages.pipeline_stage.PipelineStage
CandidateScorer is a PipelineStage that applies some score to candidates. The scoring function must be defined in the particular application that is utilizing FREx.
A new CandidateScorer class can be minimally defined by creating a new subclass of CandidateScorer and defining the score() function.
- Parameters
scoring_explanation – The explanation to add to the Candidate after applying the scoring function.
- __call__(*, candidates: Generator[frex.models.candidate.Candidate, None, None], context: Any) Generator[frex.models.candidate.Candidate, None, None] [source]
For each of candidate being yielded by the Generator, apply a scoring function to the candidate and yield it as output.
- Parameters
candidates – A Generator yielding candidates. In the setup of a FREx Pipeline, this is typically another PipelineStage that is yielding candidates into the next stage.
context – The current context being used to execute the Pipeline.
- Returns
A Generator, yielding updated Candidate objects that have this stage’s scoring function applied.
- abstract score(*, candidate: frex.models.candidate.Candidate) float [source]
Apply a custom scoring function to the input candidate.
- Parameters
candidate – A domain-specific candidate to apply the scoring function
- Returns
A score applied to be applied the candidate based on the implemented scoring function.