autointent.modules.decision.TunableDecision#
- class autointent.modules.decision.TunableDecision(n_trials=320, seed=0, tags=None)#
Bases:
autointent.modules.abc.DecisionModule
Tunable predictor module.
TunableDecision uses an optimization process to find the best thresholds for predicting labels in single-label or multi-label classification tasks. It is designed for datasets with varying score distributions and supports out-of-scope (OOS) detection.
- Variables:
name – Name of the predictor, defaults to “tunable”.
multilabel – Whether the task is multi-label classification.
n_classes – Number of classes determined during fitting.
tags – Tags for predictions, if any.
- Parameters:
n_trials (int)
seed (int)
tags (list[autointent.schemas.Tag] | None)
Examples#
Single-label classification#
import numpy as np from autointent.modules import TunableDecision scores = np.array([[0.2, 0.8], [0.6, 0.4], [0.1, 0.9]]) labels = [1, 0, 1] predictor = TunableDecision(n_trials=100, seed=42) predictor.fit(scores, labels) test_scores = np.array([[0.3, 0.7], [0.5, 0.5]]) predictions = predictor.predict(test_scores) print(predictions)
[1 0]
Multi-label classification#
labels = [[1, 0], [0, 1], [1, 1]] predictor = TunableDecision(n_trials=100, seed=42) predictor.fit(scores, labels) test_scores = np.array([[0.3, 0.7], [0.6, 0.4]]) predictions = predictor.predict(test_scores) print(predictions)
[[1 1] [1 1]]
- name = 'tunable'#
- tags: list[autointent.schemas.Tag] | None#
- n_trials = 320#
- seed = 0#
- classmethod from_context(context, n_trials=320)#
Initialize from context.
- Parameters:
context (autointent.context.Context) – Context
n_trials (int) – Number of trials
- Return type:
- fit(scores, labels, tags=None)#
Fit module.
- When data doesn’t contain out-of-scope utterances, using TunableDecision imposes unnecessary
computational overhead.
- Parameters:
scores (numpy.typing.NDArray[Any]) – Scores to fit
labels (list[autointent.custom_types.LabelType]) – Labels to fit
tags (list[autointent.schemas.Tag] | None) – Tags to fit
- Return type:
None
- predict(scores)#
Predict the best score.
- Parameters:
scores (numpy.typing.NDArray[Any]) – Scores to predict
- Return type:
numpy.typing.NDArray[Any]