artefactual.WEPR#

class artefactual.WEPR(estimator=None)[source]#

Bases: TokenProbaMixin, PretrainedMixin, SavePretrainedMixin, ClassifierMixin, BaseEstimator

Scores 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_file

The local .skops file identifier names, downloading it if it names a repository.

check_options

Refuse from_pretrained's extra options before any file is looked up.

decision_function

The classifier's decision function.

fit

Fit a clone of estimator on the pooled features; a frozen one keeps its weights.

from_estimator

Wrap a loaded classifier, frozen, as a detector.

from_pretrained

An instance carrying published weights, ready to score.

get_feature_names_out

Names of the pooled features.

get_metadata_routing

Get metadata routing of this object.

get_params

Get parameters for this estimator.

load_file

Read a fitted estimator from a .skops file, refusing types not asked for.

predict

Predicted labels.

predict_proba

Class probabilities; column i is classes_[i].

predict_token_proba

Per-token probabilities of class 1, for locating where a response drifts.

save_pretrained

Write this object's trained estimator to a .skops file.

score

Return accuracy on provided data and labels.

set_params

Set the parameters of this estimator.

set_score_request

Configure whether metadata should be requested to be passed to the score method.

property classes_: ndarray#

The class labels, sorted; column i of predict_proba is classes_[i].

Raises:

AttributeError – If the detector is not fitted.

decision_function(X)[source]#

The classifier’s decision function.

Return type:

ndarray

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:

WEPR

classmethod from_estimator(estimator, identifier, **kwargs)[source]#

Wrap a loaded classifier, frozen, as a detector.

Parameters:
  • estimator (estimator) – A fitted binary classifier.

  • identifier (str or Path) – What named it, for error messages.

  • **kwargs (Any) – Passed to the constructor.

Returns:

A detector whose estimator is FrozenEstimator(estimator).

Return type:

WEPR

Raises:

ValueError – If estimator is not a fitted binary classifier.

get_feature_names_out(input_features=None)[source]#

Names of the pooled features.

Return type:

ndarray

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.

predict(X)[source]#

Predicted labels.

Return type:

ndarray

predict_proba(X)[source]#

Class probabilities; column i is classes_[i].

Return type:

ndarray

set_score_request(*, sample_weight: bool | None | str = '$UNCHANGED$') → WEPR#

Configure whether metadata should be requested to be passed to the score method.

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 (see sklearn.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 to score if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to score.

  • 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.

Parameters:

sample_weight (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for sample_weight parameter in score.

Returns:

self – The updated object.

Return type:

object