Upload 5 files
Browse files- README.md +100 -0
- config.json +13 -0
- model.safetensors +3 -0
- modules.json +14 -0
- tokenizer.json +0 -0
README.md
ADDED
@@ -0,0 +1,100 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
base_model: ibm-granite/granite-embedding-30m-english
|
3 |
+
language:
|
4 |
+
- en
|
5 |
+
library_name: model2vec
|
6 |
+
license: mit
|
7 |
+
model_name: granite-embedding-english
|
8 |
+
tags:
|
9 |
+
- embeddings
|
10 |
+
- static-embeddings
|
11 |
+
- sentence-transformers
|
12 |
+
---
|
13 |
+
|
14 |
+
# granite-embedding-english Model Card
|
15 |
+
|
16 |
+
This [Model2Vec](https://github.com/MinishLab/model2vec) model is a distilled version of the ibm-granite/granite-embedding-30m-english(https://huggingface.co/ibm-granite/granite-embedding-30m-english) 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.
|
17 |
+
|
18 |
+
|
19 |
+
## Installation
|
20 |
+
|
21 |
+
Install model2vec using pip:
|
22 |
+
```
|
23 |
+
pip install model2vec
|
24 |
+
```
|
25 |
+
|
26 |
+
## Usage
|
27 |
+
|
28 |
+
### Using Model2Vec
|
29 |
+
|
30 |
+
The [Model2Vec library](https://github.com/MinishLab/model2vec) is the fastest and most lightweight way to run Model2Vec models.
|
31 |
+
|
32 |
+
Load this model using the `from_pretrained` method:
|
33 |
+
```python
|
34 |
+
from model2vec import StaticModel
|
35 |
+
|
36 |
+
# Load a pretrained Model2Vec model
|
37 |
+
model = StaticModel.from_pretrained("granite-embedding-english")
|
38 |
+
|
39 |
+
# Compute text embeddings
|
40 |
+
embeddings = model.encode(["Example sentence"])
|
41 |
+
```
|
42 |
+
|
43 |
+
### Using Sentence Transformers
|
44 |
+
|
45 |
+
You can also use the [Sentence Transformers library](https://github.com/UKPLab/sentence-transformers) to load and use the model:
|
46 |
+
|
47 |
+
```python
|
48 |
+
from sentence_transformers import SentenceTransformer
|
49 |
+
|
50 |
+
# Load a pretrained Sentence Transformer model
|
51 |
+
model = SentenceTransformer("granite-embedding-english")
|
52 |
+
|
53 |
+
# Compute text embeddings
|
54 |
+
embeddings = model.encode(["Example sentence"])
|
55 |
+
```
|
56 |
+
|
57 |
+
### Distilling a Model2Vec model
|
58 |
+
|
59 |
+
You 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:
|
60 |
+
|
61 |
+
```python
|
62 |
+
from model2vec.distill import distill
|
63 |
+
|
64 |
+
# Distill a Sentence Transformer model, in this case the BAAI/bge-base-en-v1.5 model
|
65 |
+
m2v_model = distill(model_name="BAAI/bge-base-en-v1.5", pca_dims=256)
|
66 |
+
|
67 |
+
# Save the model
|
68 |
+
m2v_model.save_pretrained("m2v_model")
|
69 |
+
```
|
70 |
+
|
71 |
+
## How it works
|
72 |
+
|
73 |
+
Model2vec 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.
|
74 |
+
|
75 |
+
It 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.
|
76 |
+
|
77 |
+
## Additional Resources
|
78 |
+
|
79 |
+
- [Model2Vec Repo](https://github.com/MinishLab/model2vec)
|
80 |
+
- [Model2Vec Base Models](https://huggingface.co/collections/minishlab/model2vec-base-models-66fd9dd9b7c3b3c0f25ca90e)
|
81 |
+
- [Model2Vec Results](https://github.com/MinishLab/model2vec/tree/main/results)
|
82 |
+
- [Model2Vec Tutorials](https://github.com/MinishLab/model2vec/tree/main/tutorials)
|
83 |
+
- [Website](https://minishlab.github.io/)
|
84 |
+
|
85 |
+
|
86 |
+
## Library Authors
|
87 |
+
|
88 |
+
Model2Vec 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).
|
89 |
+
|
90 |
+
## Citation
|
91 |
+
|
92 |
+
Please cite the [Model2Vec repository](https://github.com/MinishLab/model2vec) if you use this model in your work.
|
93 |
+
```
|
94 |
+
@software{minishlab2024model2vec,
|
95 |
+
authors = {Stephan Tulkens and Thomas van Dongen},
|
96 |
+
title = {Model2Vec: Fast State-of-the-Art Static Embeddings},
|
97 |
+
year = {2024},
|
98 |
+
url = {https://github.com/MinishLab/model2vec}
|
99 |
+
}
|
100 |
+
```
|
config.json
ADDED
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"model_type": "model2vec",
|
3 |
+
"architectures": [
|
4 |
+
"StaticModel"
|
5 |
+
],
|
6 |
+
"tokenizer_name": "ibm-granite/granite-embedding-30m-english",
|
7 |
+
"apply_pca": 256,
|
8 |
+
"apply_zipf": null,
|
9 |
+
"sif_coefficient": 0.0001,
|
10 |
+
"hidden_dim": 256,
|
11 |
+
"seq_length": 1000000,
|
12 |
+
"normalize": true
|
13 |
+
}
|
model.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:847f9d0e20b9e7c45038f4878382487c74ba78e00564be51c9c450b392672452
|
3 |
+
size 51471448
|
modules.json
ADDED
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
[
|
2 |
+
{
|
3 |
+
"idx": 0,
|
4 |
+
"name": "0",
|
5 |
+
"path": ".",
|
6 |
+
"type": "sentence_transformers.models.StaticEmbedding"
|
7 |
+
},
|
8 |
+
{
|
9 |
+
"idx": 1,
|
10 |
+
"name": "1",
|
11 |
+
"path": "1_Normalize",
|
12 |
+
"type": "sentence_transformers.models.Normalize"
|
13 |
+
}
|
14 |
+
]
|
tokenizer.json
ADDED
The diff for this file is too large to render.
See raw diff
|
|