Training
Train your own lightweight classification models with Model2Vec
Installation
To train, make sure you install the training extra:
Training a Classifier
Model2Vec supports training simple classifiers on top of static models. These models are extremely lightweight and can be trained on a CPU.
Initializing a Classifier
To initialize a classifier, you can use the Classifier
class. This class allows you to create a lightweight model that can be trained on your data. We support both single- and multi-label classification, which work seamlessly based on the labels you provide.
Load a Dataset
Next, load a dataset to train on.
Training and Evaluating the Classifier
Persistence
You can easily turn a trained classifier into a scikit-learn compatible pipeline and save it locally, or push it to the HuggingFace Hub:
Then, you can load it back with:
Note that, since the converted pipeline is a scikit-learn pipeline, you don’t need Torch anymore for inference. This allows you to deploy your model in a lightweight environment without the need for heavy dependencies.