autointent.modules.RerankScorer#

class autointent.modules.RerankScorer(k=5, weights='distance', use_cross_encoder_scores=False, m=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 (pydantic.PositiveInt) – 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 (pydantic.PositiveInt | None) – Number of top-ranked neighbors to consider, or None to use k

  • use_cross_encoder_scores (bool)

name = 'rerank'#

Name of the module to reference in search space configuration.

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

Create a RerankScorer instance from a given context.

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

  • k (pydantic.PositiveInt) – 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

  • use_cross_encoder_scores (bool) – use crosencoder scores for the output probability vector computation

Return type:

RerankScorer

get_implicit_initialization_params()#

Return default params used in __init__ method.

Some parameters of the module may be inferred using context rather from __init__ method. But they need to be logged for reproducibility during loading from disk.

Returns:

Dictionary of default params

Return type:

dict[str, Any]

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