autointent.modules.scoring.RerankScorer#

class autointent.modules.scoring.RerankScorer(k, weights, m=None, rank_threshold_cutoff=None, cross_encoder_config=None, embedder_config=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.

Parameters:
  • embedder_config (autointent.configs.EmbedderConfig | str | dict[str, Any] | None) – Config of the embedder used for vectorization

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

  • weights (autointent.custom_types.WeightType) –

    Weighting strategy:

    • ”uniform”: Equal weight for all neighbors

    • ”distance”: Weight inversely proportional to distance

    • ”closest”: Only the closest neighbor of each class is weighted

  • cross_encoder_config (autointent.configs.CrossEncoderConfig | str | dict[str, Any] | None) – Config of the cross-encoder model used for re-ranking

  • 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

name = 'rerank'#

Name of the module.

cross_encoder_config#
m#
rank_threshold_cutoff = None#
classmethod from_context(context, k, weights='distance', m=None, cross_encoder_config=None, embedder_config=None, rank_threshold_cutoff=None)#

Create a RerankScorer instance from a given context.

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

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

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

  • cross_encoder_config (autointent.configs.CrossEncoderConfig | str | None) – Config of the cross-encoder model used for re-ranking

  • embedder_config (autointent.configs.EmbedderConfig | str | None) – Config of the embedder used for vectorization, or None to use the best existing embedder

  • m (pydantic.PositiveInt | 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

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 (autointent.custom_types.ListOfLabels) – List of labels corresponding to the utterances

Return type:

None

clear_cache()#

Clear cached data in memory used by the scorer and vector index.

Return type:

None