CoolFace
Modelpublic

krumeto/text-class-tutorial-model2vec

sourceHugging Facemitupdated 1y agoView on Hugging Face
0likes6downloads
README.md97 linesDownload Raw Back to root
1---2library_name: model2vec3license: mit4model_name: tmpg4andd9b5tags:6- embeddings7- static-embeddings8- sentence-transformers9---10 11# tmpg4andd9b Model Card12 13This [Model2Vec](https://github.com/MinishLab/model2vec) model is a distilled version of a Sentence Transformer. It uses static embeddings, allowing text embeddings to be computed orders of magnitude faster on both GPU and CPU. It is designed for applications where computational resources are limited or where real-time performance is critical. Model2Vec models are the smallest, fastest, and most performant static embedders available. The distilled models are up to 50 times smaller and 500 times faster than traditional Sentence Transformers.14 15 16## Installation17 18Install model2vec using pip:19```20pip install model2vec21```22 23## Usage24 25### Using Model2Vec26 27The [Model2Vec library](https://github.com/MinishLab/model2vec) is the fastest and most lightweight way to run Model2Vec models.28 29Load this model using the `from_pretrained` method:30```python31from model2vec import StaticModel32 33# Load a pretrained Model2Vec model34model = StaticModel.from_pretrained("tmpg4andd9b")35 36# Compute text embeddings37embeddings = model.encode(["Example sentence"])38```39 40### Using Sentence Transformers41 42You can also use the [Sentence Transformers library](https://github.com/UKPLab/sentence-transformers) to load and use the model:43 44```python45from sentence_transformers import SentenceTransformer46 47# Load a pretrained Sentence Transformer model48model = SentenceTransformer("tmpg4andd9b")49 50# Compute text embeddings51embeddings = model.encode(["Example sentence"])52```53 54### Distilling a Model2Vec model55 56You can distill a Model2Vec model from a Sentence Transformer model using the `distill` method. First, install the `distill` extra with `pip install model2vec[distill]`. Then, run the following code:57 58```python59from model2vec.distill import distill60 61# Distill a Sentence Transformer model, in this case the BAAI/bge-base-en-v1.5 model62m2v_model = distill(model_name="BAAI/bge-base-en-v1.5", pca_dims=256)63 64# Save the model65m2v_model.save_pretrained("m2v_model")66```67 68## How it works69 70Model2vec creates a small, fast, and powerful model that outperforms other static embedding models by a large margin on all tasks we could find, while being much faster to create than traditional static embedding models such as GloVe. Best of all, you don't need any data to distill a model using Model2Vec.71 72It works by passing a vocabulary through a sentence transformer model, then reducing the dimensionality of the resulting embeddings using PCA, and finally weighting the embeddings using [SIF weighting](https://openreview.net/pdf?id=SyK00v5xx). During inference, we simply take the mean of all token embeddings occurring in a sentence.73 74## Additional Resources75 76- [Model2Vec Repo](https://github.com/MinishLab/model2vec)77- [Model2Vec Base Models](https://huggingface.co/collections/minishlab/model2vec-base-models-66fd9dd9b7c3b3c0f25ca90e)78- [Model2Vec Results](https://github.com/MinishLab/model2vec/tree/main/results)79- [Model2Vec Tutorials](https://github.com/MinishLab/model2vec/tree/main/tutorials)80- [Website](https://minishlab.github.io/)81 82 83## Library Authors84 85Model2Vec was developed by the [Minish Lab](https://github.com/MinishLab) team consisting of [Stephan Tulkens](https://github.com/stephantul) and [Thomas van Dongen](https://github.com/Pringled).86 87## Citation88 89Please cite the [Model2Vec repository](https://github.com/MinishLab/model2vec) if you use this model in your work.90```91@article{minishlab2024model2vec,92  author = {Tulkens, Stephan and {van Dongen}, Thomas},93  title = {Model2Vec: Fast State-of-the-Art Static Embeddings},94  year = {2024},95  url = {https://github.com/MinishLab/model2vec}96}97```