To load a pre-trained model, you can use the Model2Vec.from_pretrained method. This method allows you to load models from the Hugging Face Hub or from a local path.
Copy
from model2vec import Model2Vecmodel = Model2Vec.from_pretrained("minishlab/potion-base-8M")
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 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).
To create mean embeddings, you can use the encode method of the Model2Vec class. This method allows you to encode a list of sentences into mean embeddings.
Copy
from model2vec import Model2Vecmodel = Model2Vec.from_pretrained("minishlab/potion-base-8M")embeddings = model.encode(["Hello world", "Static embeddings are great!"])
To create sequence embeddings, you can use the encode_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.
Copy
from model2vec import Model2Vecmodel = Model2Vec.from_pretrained("minishlab/potion-base-8M")embeddings = model.encode_as_sequence(["Hello world", "Static embeddings are great!"], mode="sequence")