artefactual.DetectorPipeline#
- class artefactual.DetectorPipeline(steps, *, transform_input=None, memory=None, verbose=False)[source]#
Bases:
PipelineA 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_functionTransform the data, and apply decision_function with the final estimator.
Fit the pipeline after checking that it can score per token.
fit_predictTransform the data, and apply fit_predict with the final estimator.
fit_transformFit the model and transform with the final estimator.
get_feature_names_outGet output feature names for transformation.
get_metadata_routingGet metadata routing of this object.
get_paramsGet parameters for this estimator.
inverse_transformApply inverse_transform for each step in a reverse order.
predictTransform the data, and apply predict with the final estimator.
predict_log_probaTransform the data, and apply predict_log_proba with the final estimator.
predict_probaTransform the data, and apply predict_proba with the final estimator.
Per-token probabilities of class 1.
scoreTransform the data, and apply score with the final estimator.
score_samplesTransform the data, and apply score_samples with the final estimator.
set_callbacksSet callbacks for the estimator.
set_outputSet the output container when "transform" and "fit_transform" are called.
set_paramsSet the parameters of this estimator.
Configure whether metadata should be requested to be passed to the
scoremethod.transformTransform 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:
- 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
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.