plexus.scores.KeywordClassifier module
- class plexus.scores.KeywordClassifier.KeywordClassifier(keywords, scorecard_name, score_name, **kwargs)
Bases:
Score
A keyword classifier that returns True if the input sentence contains any of the keywords or matches any of the regular expressions.
This classifier supports both plain string keywords and regular expressions for more flexible matching.
Examples
Plain string keywords: - “child” - “children” - “dependent”
Regular expressions: - r”child” - r”children” - r”dependent”
Initialize the Score instance with the given parameters.
Parameters
- **parametersdict
Arbitrary keyword arguments that are used to initialize the Parameters instance.
Raises
- ValidationError
If the provided parameters do not pass validation.
- __init__(keywords, scorecard_name, score_name, **kwargs)
Initialize the Score instance with the given parameters.
Parameters
- **parametersdict
Arbitrary keyword arguments that are used to initialize the Parameters instance.
Raises
- ValidationError
If the provided parameters do not pass validation.
- is_relevant(sentence)
Check if the input sentence is relevant based on the keywords.
- Parameters:
sentence – The input sentence to check.
- Returns:
True if the sentence is relevant, False otherwise.
- load_context(context=None)
Load any necessary artifacts or models based on the MLflow context.
This function is required by the standard MLFlow model interface for running inference in production.
- predict(model_input: Input)
Make predictions on the input data.
- Parameters:
model_input – The input data for making predictions, which conforms to Score.Input.
- Returns:
The predictions, which can be one of the supported output types.
- predict_validation()
Predict on the validation set.
This method should be implemented by subclasses to provide the prediction logic on the validation set.
- register_model()
Register the model with the model registry.
- save_model()
Save the model to the model registry.