autointent.modules.scoring.RerankScorer#

class autointent.modules.scoring.RerankScorer(embedder_name, k, weights, cross_encoder_name, m=None, rank_threshold_cutoff=None, db_dir=None, embedder_device='cpu', batch_size=32, max_length=None)#

Bases: autointent.modules.scoring._knn.knn.KNNScorer

Re-ranking scorer using a cross-encoder for intent classification.

This module uses a cross-encoder to re-rank the nearest neighbors retrieved by a KNN scorer.

Variables:
  • name – Name of the scorer, defaults to “rerank”.

  • _scorer – CrossEncoder instance for re-ranking.

Parameters:
  • embedder_name (str)

  • k (int)

  • weights (autointent.custom_types.WEIGHT_TYPES)

  • cross_encoder_name (str)

  • m (int | None)

  • rank_threshold_cutoff (int | None)

  • db_dir (str | None)

  • embedder_device (str)

  • batch_size (int)

  • max_length (int | None)

name = 'rerank'#
cross_encoder_name#
m#
rank_threshold_cutoff = None#
classmethod from_context(context, k, weights, cross_encoder_name, embedder_name=None, m=None, rank_threshold_cutoff=None)#

Create a RerankScorer instance from a given context.

Parameters:
  • context (autointent.context.Context) – Context object containing optimization information and vector index client.

  • k (int) – Number of closest neighbors to consider during inference.

  • weights (autointent.custom_types.WEIGHT_TYPES) – Weighting strategy.

  • cross_encoder_name (str) – Name of the cross-encoder model used for re-ranking.

  • embedder_name (str | None) – Name of the embedder used for vectorization, or None to use the best existing embedder.

  • m (int | None) – Number of top-ranked neighbors to consider, or None to use k.

  • rank_threshold_cutoff (int | None) – Rank threshold cutoff for re-ranking, or None.

Returns:

An instance of RerankScorer.

Return type:

RerankScorer

fit(utterances, labels)#

Fit the RerankScorer with utterances and labels.

Parameters:
  • utterances (list[str]) – List of utterances to fit the scorer.

  • labels (list[autointent.custom_types.LabelType]) – List of labels corresponding to the utterances.

Return type:

None

load(path)#

Load the RerankScorer from a given path.

Parameters:

path (str) – Path to the directory containing the dumped metadata.

Return type:

None