File size: 4,810 Bytes
58bb377
 
7b6db41
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
58bb377
7b6db41
 
58bb377
 
 
306748c
58bb377
306748c
 
 
 
58bb377
 
7b6db41
58bb377
7b6db41
58bb377
7b6db41
58bb377
 
 
306748c
 
 
7b6db41
306748c
7b6db41
 
58bb377
7b6db41
306748c
58bb377
7b6db41
306748c
 
 
 
 
 
 
58bb377
 
 
306748c
 
 
58bb377
306748c
 
 
 
 
 
58bb377
306748c
58bb377
306748c
 
7b6db41
58bb377
306748c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7b6db41
58bb377
7b6db41
58bb377
7b6db41
58bb377
7b6db41
58bb377
7b6db41
 
 
 
58bb377
7b6db41
58bb377
7b6db41
58bb377
 
 
7b6db41
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
---
base_model: jinaai/jina-embeddings-v3
language:
- multilingual
- af
- am
- ar
- as
- az
- be
- bg
- bn
- br
- bs
- ca
- cs
- cy
- da
- de
- el
- en
- eo
- es
- et
- eu
- fa
- fi
- fr
- fy
- ga
- gd
- gl
- gu
- ha
- he
- hi
- hr
- hu
- hy
- id
- is
- it
- ja
- jv
- ka
- kk
- km
- kn
- ko
- ku
- ky
- la
- lo
- lt
- lv
- mg
- mk
- ml
- mn
- mr
- ms
- my
- ne
- nl
- 'no'
- om
- or
- pa
- pl
- ps
- pt
- ro
- ru
- sa
- sd
- si
- sk
- sl
- so
- sq
- sr
- su
- sv
- sw
- ta
- te
- th
- tl
- tr
- ug
- uk
- ur
- uz
- vi
- xh
- yi
- zh
library_name: model2vec
license: mit
model_name: onnx
tags:
- embeddings
- static-embeddings
- sentence-transformers
---

# alikia2x/jina-embedding-v3-m2v-1024

This [Model2Vec](https://github.com/MinishLab/model2vec) model is a distilled version of the 
[jinaai/jina-embeddings-v3](https://huggingface.co/jinaai/jina-embeddings-v3) 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.


## Installation

Install model2vec using pip:
```
pip install model2vec
```

## Usage

### Via `model2vec`

Load this model using the `from_pretrained` method:

```python
from model2vec import StaticModel

# Load a pretrained Model2Vec model
model = StaticModel.from_pretrained("alikia2x/jina-embedding-v3-m2v-1024")

# Compute text embeddings
embeddings = model.encode(["Hello"])
```

### Via `sentence-transformers`

```bash
pip install sentence-transformers
```

```python
from sentence_transformers import SentenceTransformer

model = SentenceTransformer("alikia2x/jina-embedding-v3-m2v-1024")

# embedding:
# array([[ 1.1825741e-01, -1.2899181e-02, -1.0492010e-01, ...,
#          1.1131058e-03,  8.2779792e-04, -7.6874542e-08]],
#       shape=(1, 1024), dtype=float32)
embeddings = model.encode(["Hello"])
```

### Via ONNX

```bash
pip install onnxruntime transformers
```

You need to download `onnx/model.onnx` in this repository first.

```python
import onnxruntime
from transformers import AutoTokenizer
import numpy as np

tokenizer_model = "alikia2x/jina-embedding-v3-m2v-1024"
onnx_embedding_path = "path/to/your/model.onnx"

texts = ["Hello"]
tokenizer = AutoTokenizer.from_pretrained(tokenizer_model)
session = onnxruntime.InferenceSession(onnx_embedding_path)

inputs = tokenizer(texts, add_special_tokens=False, return_tensors="np")
input_ids = inputs["input_ids"]
lengths = [len(seq) for seq in input_ids[:-1]]
offsets = [0] + np.cumsum(lengths).tolist()
flattened_input_ids = input_ids.flatten().astype(np.int64)

inputs = {
    "input_ids": flattened_input_ids,
    "offsets": np.array(offsets, dtype=np.int64),
}

outputs = session.run(None, inputs)
embeddings = outputs[0]
embeddings = embeddings.flatten()

# [ 1.1825741e-01 -1.2899181e-02 -1.0492010e-01 ...  1.1131058e-03
#   8.2779792e-04 -7.6874542e-08]
print(embeddings)
```

Note: A quantized (INT8) version of this model is also available, offering reduced memory usage with minimal performance impact.
Simply replace `onnx/model.onnx` with the `onnx/model_INT8.onnx` file.
Our testing shows less than a 1% drop in the F1 score on a real down-stream task.

## How it works

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.

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 zipf weighting. During inference, we simply take the mean of all token embeddings occurring in a sentence.

## Additional Resources

- [All Model2Vec models on the hub](https://huggingface.co/models?library=model2vec)
- [Model2Vec Repo](https://github.com/MinishLab/model2vec)
- [Model2Vec Results](https://github.com/MinishLab/model2vec?tab=readme-ov-file#results)
- [Model2Vec Tutorials](https://github.com/MinishLab/model2vec/tree/main/tutorials)

## Library Authors

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).

## Citation

Please cite the [Model2Vec repository](https://github.com/MinishLab/model2vec) if you use this model in your work.
```
@software{minishlab2024model2vec,
  authors = {Stephan Tulkens, Thomas van Dongen},
  title = {Model2Vec: Turn any Sentence Transformer into a Small Fast Model},
  year = {2024},
  url = {https://github.com/MinishLab/model2vec},
}
```