artefactual.WEPR#
- class artefactual.WEPR(estimator=None)[source]#
Bases:
TokenProbaMixin,PretrainedMixin,SavePretrainedMixin,ClassifierMixin,BaseEstimatorScores logprob arrays with a mean and a max per rank, the Weighted EPR.
Two features per rank let the calibration weight the informative ranks over the rest, so it reads strictly more of the distribution than EPR. Input and targets are as for EPR; the weights are fixed at the width they were trained at, which the pooling’s feature count then enforces.
- Parameters:
estimator (estimator, default=None) – Final classifier with fit and predict_proba, never fitted in place: a clone is trained. None is the unregularised logistic regression. A FrozenEstimator holds pretrained weights, which fit keeps.
- Variables:
fitted_pipeline (Pipeline) – The pipeline fit trained; absent on a detector that only carries frozen weights.
pipeline (Pipeline) – The pipeline that scores: the entropy step and the classifier. fitted_pipeline_ once fit ran, else rebuilt from a FrozenEstimator.
classes (ndarray of shape (2,)) – The class labels, sorted.
n_features_in (int) – Last dimension of the input fitted on.
- Raises:
TypeError – From fit and predict*, if given completion responses instead of logprob arrays.
Examples
>>> detector = make_pipeline(LogProbParser(k=15), WEPR()).fit( ... responses, y ... )
Methods
cached_fileThe local .skops file identifier names, downloading it if it names a repository.
check_optionsRefuse from_pretrained's extra options before any file is looked up.
The classifier's decision function.
Fit a clone of estimator on the pooled features; a frozen one keeps its weights.
Wrap a loaded classifier, frozen, as a detector.
from_pretrainedAn instance carrying published weights, ready to score.
Names of the pooled features.
get_metadata_routingGet metadata routing of this object.
get_paramsGet parameters for this estimator.
load_fileRead a fitted estimator from a .skops file, refusing types not asked for.
Predicted labels.
Class probabilities; column i is classes_[i].
predict_token_probaPer-token probabilities of class 1, for locating where a response drifts.
save_pretrainedWrite this object's trained estimator to a .skops file.
scoreReturn accuracy on provided data and labels.
set_paramsSet the parameters of this estimator.
Configure whether metadata should be requested to be passed to the
scoremethod.- property classes_: ndarray#
The class labels, sorted; column i of predict_proba is classes_[i].
- Raises:
AttributeError – If the detector is not fitted.
- fit(X, y)[source]#
Fit a clone of estimator on the pooled features; a frozen one keeps its weights.
- Parameters:
X (array-like of shape (n_samples, n_tokens, width) or (n_samples, width)) – Per-rank logprobs, NaN-padded in the 3-D form.
y (array-like of shape (n_samples,)) – Binary labels; the second in sorted order is class 1.
- Returns:
self
- Return type:
- classmethod from_estimator(estimator, identifier, **kwargs)[source]#
Wrap a loaded classifier, frozen, as a detector.
- Parameters:
- Returns:
A detector whose estimator is FrozenEstimator(estimator).
- Return type:
- Raises:
ValueError – If estimator is not a fitted binary classifier.
- property pipeline_: Pipeline#
The entropy step and the classifier that score.
The pipeline fit trained once it ran. A FrozenEstimator was never fitted here, so the pipeline is rebuilt from the parameters on each read, never stored.
- Raises:
AttributeError – If neither holds: the detector is not fitted.
- set_score_request(*, sample_weight: bool | None | str = '$UNCHANGED$') WEPR#
Configure whether metadata should be requested to be passed to the
scoremethod.Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with
enable_metadata_routing=True(seesklearn.set_config()). Please check the User Guide on how the routing mechanism works.The options for each parameter are:
True: metadata is requested, and passed toscoreif provided. The request is ignored if metadata is not provided.False: metadata is not requested and the meta-estimator will not pass it toscore.None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.Added in version 1.3.