Loading a Model
To load a pre-trained model, you can use theModel2Vec.from_pretrained
method. This method allows you to load models from the Hugging Face Hub or from a local path.
Parameters
Parameters
The path to load your static model from.
The Hugging Face token to use when loading a private model. If not provided, no token is used.
Whether to normalize the embeddings after loading. If
True
, embeddings will be normalized; if False
, they won’t. If None
, the model’s default behavior applies.The subfolder within the repository or local directory to load the model from. Leave as
None
to load from the root.The data type to quantize the model to (e.g.,
"float16"
or a torch.dtype
). If a string is passed, it’s converted to the corresponding DType
. Set to None
for no quantization.The dimensionality to load the model at. If
None
, uses the model’s inherent dimensionality. Useful when loading a model with reduced dimensions (e.g., trained via PCA or MRL).Creating Mean Embeddings
To create mean embeddings, you can use theencode
method of the Model2Vec
class. This method allows you to encode a list of sentences into mean embeddings.
Parameters
Parameters
The list of sentences to encode. You can also pass a single sentence.
Whether to show the progress bar.
The maximum length of the sentences. Any tokens beyond this length will be truncated. If this is None, no truncation is done.
The batch size to use.
Whether to use multiprocessing. By default, this is enabled for inputs > multiprocessing_threshold sentences and disabled otherwise.
The threshold in number of sentences for using multiprocessing.
Any additional arguments. These are ignored.
Creating Sequence Embeddings
To create sequence embeddings, you can use theencode_as_sequence
method of the Model2Vec
class. This method allows you to encode a list of sentences into sequence embeddings, which are useful for tasks where you need a single embedding per token.
Parameters
Parameters
The list of sentences to encode. You can also pass a single sentence.
Whether to show the progress bar.
The maximum length of the sentences. Any tokens beyond this length will be truncated. If this is None, no truncation is done.
The batch size to use.
Whether to use multiprocessing. By default, this is enabled for inputs > multiprocessing_threshold sentences and disabled otherwise.
The threshold in number of sentences for using multiprocessing.
Any additional arguments. These are ignored.