autointent.modules.scoring.DNNCScorer#

class autointent.modules.scoring.DNNCScorer(k, cross_encoder_config=None, embedder_config=None)#

Bases: autointent.modules.base.BaseScorer

Scoring module for intent classification using discriminative nearest neighbor classification.

This module uses a Ranker for scoring candidate intents and can optionally train a logistic regression head on top of cross-encoder features.

Parameters:

Examples:#

from autointent.modules.scoring import DNNCScorer
utterances = ["what is your name?", "how are you?"]
labels = [0, 1]
scorer = DNNCScorer(
    cross_encoder_config="cross-encoder/ms-marco-MiniLM-L-6-v2",
    embedder_config="sergeyzh/rubert-tiny-turbo",
    k=5,
)
scorer.fit(utterances, labels)

test_utterances = ["Hello!", "What's up?"]
scores = scorer.predict(test_utterances)
Reference:

Zhang, J. G., Hashimoto, K., Liu, W., Wu, C. S., Wan, Y., Yu, P. S., … & Xiong, C. (2020). Discriminative Nearest Neighbor Few-Shot Intent Detection by Transferring Natural Language Inference. arXiv preprint arXiv:2010.13009.

name = 'dnnc'#

Name of the module.

supports_multilabel = False#

Whether the module supports multilabel classification

supports_multiclass = True#

Whether the module supports multiclass classification

cross_encoder_config#
embedder_config#
k#
classmethod from_context(context, k, cross_encoder_config=None, embedder_config=None)#

Create a DNNCScorer instance using a Context object.

Parameters:
Return type:

DNNCScorer

fit(utterances, labels)#

Fit the scorer by training or loading the vector index.

Parameters:
  • utterances (list[str]) – List of training utterances

  • labels (autointent.custom_types.ListOfLabels) – List of labels corresponding to the utterances

Raises:

ValueError – If the vector index mismatches the provided utterances

Return type:

None

predict(utterances)#

Predict class scores for the given utterances.

Parameters:

utterances (list[str]) – List of utterances to score

Returns:

Array of predicted scores

Return type:

numpy.typing.NDArray[Any]

predict_with_metadata(utterances)#

Predict class scores along with metadata for the given utterances.

Parameters:

utterances (list[str]) – List of utterances to score

Returns:

  • Array of predicted scores

  • List of metadata with neighbor details and scores

Return type:

Tuple containing

clear_cache()#

Clear cached data in memory used by the vector index.

Return type:

None