autointent.Ranker#
- class autointent.Ranker(cross_encoder_config, classifier_head=None)#
Cross-encoder for Natural Language Inference (NLI).
This class uses
sentence_transformers.cross_encoder.CrossEncoder
model to extract features. It can use either the model’s classifier or a custom trainedsklearn.linear_model.LogisticRegressionCV
to rank documents using similarity scores to the query.- Parameters:
cross_encoder_config (autointent.configs.CrossEncoderConfig | str | dict[str, Any])
classifier_head (sklearn.linear_model.LogisticRegressionCV | None)
- cross_encoder: sentence_transformers.CrossEncoder#
- fit(utterances, labels)#
Construct training samples and train the logistic regression classifier.
- predict(pairs)#
Predict probabilities of two utterances having the same intent label.
- Parameters:
pairs (list[tuple[str, str]]) – List of text pairs to classify
- Returns:
Array of probabilities
- Raises:
ValueError – If classifier is not trained yet
- Return type:
numpy.typing.NDArray[Any]
- rank(query, query_docs, top_k=None)#
Rank documents according to meaning closeness to the query.
- save(path)#
Save the model and classifier to disk.
- Parameters:
path (str) – Directory path to save the model and classifier
- Return type:
None
- classmethod load(path, override_config=None)#
Load the model and classifier from disk.
- Parameters:
path (pathlib.Path) – Directory path containing the saved model and classifier
override_config (autointent.configs.CrossEncoderConfig | None) – one can override presaved settings
- Returns:
Initialized Ranker instance
- Return type:
- clear_ram()#
Clear model from RAM and GPU memory.
- Return type:
None