artefactual.DetectorPipeline#

class artefactual.DetectorPipeline(steps, *, transform_input=None, memory=None, verbose=False)[source]#

Bases: Pipeline

A scikit-learn Pipeline from completion responses to scores, with per-token scores.

Behaves as a Pipeline that has predict_token_proba. Its layout is one of: a step implementing TokenTransformer (such as an EntropyTransformer) before a final classifier, or a final TokenClassifier (EPR, WEPR).

Methods

decision_function

Transform the data, and apply decision_function with the final estimator.

fit

Fit the pipeline after checking that it can score per token.

fit_predict

Transform the data, and apply fit_predict with the final estimator.

fit_transform

Fit the model and transform with the final estimator.

get_feature_names_out

Get output feature names for transformation.

get_metadata_routing

Get metadata routing of this object.

get_params

Get parameters for this estimator.

inverse_transform

Apply inverse_transform for each step in a reverse order.

predict

Transform the data, and apply predict with the final estimator.

predict_log_proba

Transform the data, and apply predict_log_proba with the final estimator.

predict_proba

Transform the data, and apply predict_proba with the final estimator.

predict_token_proba

Per-token probabilities of class 1.

score

Transform the data, and apply score with the final estimator.

score_samples

Transform the data, and apply score_samples with the final estimator.

set_callbacks

Set callbacks for the estimator.

set_output

Set the output container when "transform" and "fit_transform" are called.

set_params

Set the parameters of this estimator.

set_score_request

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

transform

Transform the data, and apply transform with the final estimator.

fit(X, y=None, **params)[source]#

Fit the pipeline after checking that it can score per token.

Raises:

TypeError – If no step is a TokenTransformer before a final classifier and the last step is not a TokenClassifier.

Return type:

DetectorPipeline

predict_token_proba(X)[source]#

Per-token probabilities of class 1.

Like predict_proba, it raises NotFittedError on an unfitted pipeline.

Parameters:

X (array-like) – What the first step accepts, e.g. completion responses for a LogProbParser.

Returns:

Probability of class 1 per token, NaN at padded positions.

Return type:

ndarray of shape (n_sequences, max_tokens, 1)

Raises:

TypeError – If the last step is not a fitted classifier of two classes.

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

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