autointent.Embedder#

class autointent.Embedder(model_name, device='cpu', batch_size=32, max_length=None, use_cache=False)#

A wrapper for managing embedding models using Sentence Transformers.

This class handles initialization, saving, loading, and clearing of embedding models, as well as calculating embeddings for input texts.

Parameters:
embedder_subdir: str = 'sentence_transformers'#
metadata_dict_name: str = 'metadata.json'#
model_name#
device = 'cpu'#
batch_size = 32#
max_length = None#
use_cache = False#
logger#
__hash__()#

Compute a hash value for the Embedder.

Returns:

The hash value of the Embedder.

Return type:

int

clear_ram()#

Move the embedding model to CPU and delete it from memory.

Return type:

None

delete()#

Delete the embedding model and its associated directory.

Return type:

None

dump(path)#

Save the embedding model and metadata to disk.

Parameters:

path (pathlib.Path) – Path to the directory where the model will be saved.

Return type:

None

load(path)#

Load the embedding model and metadata from disk.

Parameters:

path (pathlib.Path | str) – Path to the directory where the model is stored.

Return type:

None

embed(utterances)#

Calculate embeddings for a list of utterances.

Parameters:

utterances (list[str]) – List of input texts to calculate embeddings for.

Returns:

A numpy array of embeddings.

Return type:

numpy.typing.NDArray[numpy.float32]