Update README.md
Browse files
README.md
CHANGED
@@ -1,199 +1,127 @@
|
|
1 |
---
|
2 |
library_name: transformers
|
3 |
-
|
|
|
|
|
|
|
|
|
4 |
---
|
5 |
|
6 |
-
#
|
7 |
|
8 |
-
|
9 |
|
|
|
10 |
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
|
12 |
-
## Model Details
|
13 |
|
14 |
-
|
15 |
|
16 |
-
|
17 |
|
18 |
-
|
|
|
|
|
|
|
19 |
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
-
|
26 |
-
|
27 |
|
28 |
-
|
|
|
|
|
|
|
|
|
29 |
|
30 |
-
|
|
|
31 |
|
32 |
-
- **Repository:** [More Information Needed]
|
33 |
-
- **Paper [optional]:** [More Information Needed]
|
34 |
-
- **Demo [optional]:** [More Information Needed]
|
35 |
|
36 |
-
|
37 |
-
|
38 |
-
<!-- Address questions around how the model is intended to be used, including the foreseeable users of the model and those affected by the model. -->
|
39 |
-
|
40 |
-
### Direct Use
|
41 |
-
|
42 |
-
<!-- This section is for the model use without fine-tuning or plugging into a larger ecosystem/app. -->
|
43 |
-
|
44 |
-
[More Information Needed]
|
45 |
-
|
46 |
-
### Downstream Use [optional]
|
47 |
-
|
48 |
-
<!-- This section is for the model use when fine-tuned for a task, or when plugged into a larger ecosystem/app -->
|
49 |
-
|
50 |
-
[More Information Needed]
|
51 |
-
|
52 |
-
### Out-of-Scope Use
|
53 |
-
|
54 |
-
<!-- This section addresses misuse, malicious use, and uses that the model will not work well for. -->
|
55 |
-
|
56 |
-
[More Information Needed]
|
57 |
-
|
58 |
-
## Bias, Risks, and Limitations
|
59 |
-
|
60 |
-
<!-- This section is meant to convey both technical and sociotechnical limitations. -->
|
61 |
-
|
62 |
-
[More Information Needed]
|
63 |
-
|
64 |
-
### Recommendations
|
65 |
-
|
66 |
-
<!-- This section is meant to convey recommendations with respect to the bias, risk, and technical limitations. -->
|
67 |
-
|
68 |
-
Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model. More information needed for further recommendations.
|
69 |
-
|
70 |
-
## How to Get Started with the Model
|
71 |
-
|
72 |
-
Use the code below to get started with the model.
|
73 |
-
|
74 |
-
[More Information Needed]
|
75 |
|
76 |
## Training Details
|
77 |
|
78 |
-
|
79 |
-
|
80 |
-
<!-- This should link to a Dataset Card, perhaps with a short stub of information on what the training data is all about as well as documentation related to data pre-processing or additional filtering. -->
|
81 |
-
|
82 |
-
[More Information Needed]
|
83 |
-
|
84 |
-
### Training Procedure
|
85 |
-
|
86 |
-
<!-- This relates heavily to the Technical Specifications. Content here should link to that section when it is relevant to the training procedure. -->
|
87 |
-
|
88 |
-
#### Preprocessing [optional]
|
89 |
-
|
90 |
-
[More Information Needed]
|
91 |
-
|
92 |
-
|
93 |
-
#### Training Hyperparameters
|
94 |
-
|
95 |
-
- **Training regime:** [More Information Needed] <!--fp32, fp16 mixed precision, bf16 mixed precision, bf16 non-mixed precision, fp16 non-mixed precision, fp8 mixed precision -->
|
96 |
-
|
97 |
-
#### Speeds, Sizes, Times [optional]
|
98 |
-
|
99 |
-
<!-- This section provides information about throughput, start/end time, checkpoint size if relevant, etc. -->
|
100 |
-
|
101 |
-
[More Information Needed]
|
102 |
-
|
103 |
-
## Evaluation
|
104 |
-
|
105 |
-
<!-- This section describes the evaluation protocols and provides the results. -->
|
106 |
-
|
107 |
-
### Testing Data, Factors & Metrics
|
108 |
-
|
109 |
-
#### Testing Data
|
110 |
-
|
111 |
-
<!-- This should link to a Dataset Card if possible. -->
|
112 |
-
|
113 |
-
[More Information Needed]
|
114 |
-
|
115 |
-
#### Factors
|
116 |
-
|
117 |
-
<!-- These are the things the evaluation is disaggregating by, e.g., subpopulations or domains. -->
|
118 |
-
|
119 |
-
[More Information Needed]
|
120 |
-
|
121 |
-
#### Metrics
|
122 |
-
|
123 |
-
<!-- These are the evaluation metrics being used, ideally with a description of why. -->
|
124 |
-
|
125 |
-
[More Information Needed]
|
126 |
-
|
127 |
-
### Results
|
128 |
-
|
129 |
-
[More Information Needed]
|
130 |
-
|
131 |
-
#### Summary
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
## Model Examination [optional]
|
136 |
-
|
137 |
-
<!-- Relevant interpretability work for the model goes here -->
|
138 |
-
|
139 |
-
[More Information Needed]
|
140 |
-
|
141 |
-
## Environmental Impact
|
142 |
-
|
143 |
-
<!-- Total emissions (in grams of CO2eq) and additional considerations, such as electricity usage, go here. Edit the suggested text below accordingly -->
|
144 |
-
|
145 |
-
Carbon emissions can be estimated using the [Machine Learning Impact calculator](https://mlco2.github.io/impact#compute) presented in [Lacoste et al. (2019)](https://arxiv.org/abs/1910.09700).
|
146 |
-
|
147 |
-
- **Hardware Type:** [More Information Needed]
|
148 |
-
- **Hours used:** [More Information Needed]
|
149 |
-
- **Cloud Provider:** [More Information Needed]
|
150 |
-
- **Compute Region:** [More Information Needed]
|
151 |
-
- **Carbon Emitted:** [More Information Needed]
|
152 |
|
153 |
-
|
154 |
|
155 |
-
|
156 |
|
157 |
-
|
158 |
|
159 |
-
|
|
|
160 |
|
161 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
162 |
|
163 |
-
|
|
|
|
|
|
|
|
|
|
|
164 |
|
165 |
-
[More Information Needed]
|
166 |
|
167 |
-
#### Software
|
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 |
-
[More Information Needed]
|
196 |
|
197 |
-
|
198 |
|
199 |
-
|
|
|
|
|
|
1 |
---
|
2 |
library_name: transformers
|
3 |
+
language:
|
4 |
+
- en
|
5 |
+
pipeline_tag: image-feature-extraction
|
6 |
+
license: cc-by-nc-4.0
|
7 |
+
inference: false
|
8 |
---
|
9 |
|
10 |
+
# nomic-embed-vision-v1: Expanding the Latent Space
|
11 |
|
12 |
+
`nomic-embed-vision-v1` is a high performing vision embedding model that shares the same embedding space as [nomic-embed-text-v1](https://huggingface.co/nomic-ai/nomic-embed-text-v1.5).
|
13 |
|
14 |
+
All Nomic Embed Text models are now **multimodal**!
|
15 |
|
16 |
+
| Name | Imagenet 0-shot | Datacomp (Avg. 38) | MTEB |
|
17 |
+
| :-------------------------------:| :-------------- | :----------------- | :------: |
|
18 |
+
| `nomic-embed-vision-v1.5` | **71.0** | **56.8** | **62.28** |
|
19 |
+
| `nomic-embed-vision-v1` | 70.7 | 56.7 | 62.39 |
|
20 |
+
| OpenAI CLIP ViT B/16 | 68.3 | 56.3 | 43.82 |
|
21 |
+
| Jina CLIP v1 | 59.1 | 52.2 | 60.1 |
|
22 |
|
|
|
23 |
|
24 |
+
## Hosted Inference API
|
25 |
|
26 |
+
The easiest way to get started with Nomic Embed is through the Nomic Embedding API.
|
27 |
|
28 |
+
Generating embeddings with the `nomic` Python client is as easy as
|
29 |
+
```python
|
30 |
+
from nomic import embed
|
31 |
+
import numpy as np
|
32 |
|
33 |
+
output = embed.image(
|
34 |
+
images=[
|
35 |
+
"image_path_1.jpeg",
|
36 |
+
"image_path_2.png",
|
37 |
+
],
|
38 |
+
model='nomic-embed-vision-v1',
|
39 |
+
)
|
40 |
|
41 |
+
print(output['usage'])
|
42 |
+
embeddings = np.array(output['embeddings'])
|
43 |
+
print(embeddings.shape)
|
44 |
+
```
|
45 |
+
For more information, see the [API reference](https://docs.nomic.ai/reference/endpoints/nomic-embed-vision)
|
46 |
|
47 |
+
## Data Visualization
|
48 |
+
Click the Nomic Atlas map below to visualize a 100,000 sample CC3M comparing the Vision and Text Embedding Space!
|
49 |
|
|
|
|
|
|
|
50 |
|
51 |
+
[![image/webp](https://cdn-uploads.huggingface.co/production/uploads/607997c83a565c15675055b3/aKJogjDQ4BBiYGRIIrFMa.webp)](https://atlas.nomic.ai/data/nomic-multimodal-series/cc3m-100k-image-bytes-v15/map)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
52 |
|
53 |
## Training Details
|
54 |
|
55 |
+
We align our vision embedder to the text embedding by employing a technique similar to [LiT](https://arxiv.org/abs/2111.07991) but instead lock the text embedder!
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
56 |
|
57 |
+
For more details, see the Nomic Embed Vision Technical Report (soon to be released!) and corresponding [blog post](https://blog.nomic.ai/posts/nomic-embed-vision)
|
58 |
|
59 |
+
Training code is released in the `contrastors` [repository](https://github.com/nomic-ai/contrastors)
|
60 |
|
61 |
+
## Usage
|
62 |
|
63 |
+
Note `nomic-embed-text` *requires* prefixes! We support the prefixes `[search_query, search_document, classification, clustering]`.
|
64 |
+
For retrieval applications, you should prepend `search_document` for all your documents and `search_query` for your queries.
|
65 |
|
66 |
+
For example, you are building a RAG application over the top of Wikipedia. You would embed all Wikipedia articles with the prefix `search_document`
|
67 |
+
and any questions you ask with `search_query`. For example:
|
68 |
+
```python
|
69 |
+
queries = ["search_query: who is the first president of the united states?", "search_query: when was babe ruth born?"]
|
70 |
+
documents = ["search_document: <article about US Presidents>", "search_document: <article about Babe Ruth>"]
|
71 |
+
```
|
72 |
+
You can
|
73 |
+
### Transformers
|
74 |
|
75 |
+
```python
|
76 |
+
import torch
|
77 |
+
import torch.nn.functional as F
|
78 |
+
from transformers import AutoTokenizer, AutoModel, AutoImageProcessor
|
79 |
+
from PIL import Image
|
80 |
+
import requests
|
81 |
|
|
|
82 |
|
|
|
83 |
|
84 |
+
processor = AutoImageProcessor.from_pretrained("nomic-ai/nomic-embed-vision-v1")
|
85 |
+
vision_model = AutoModel.from_pretrained("nomic-ai/nomic-embed-vision-v1", trust_remote_code=True)
|
86 |
|
87 |
+
url = 'http://images.cocodataset.org/val2017/000000039769.jpg'
|
88 |
+
image = Image.open(requests.get(url, stream=True).raw)
|
89 |
|
90 |
+
inputs = processor(image, return_tensors="pt")
|
91 |
|
92 |
+
img_emb = vision_model(**inputs).last_hidden_state
|
93 |
+
img_embeddings = F.normalize(img_emb[:, 0], p=2, dim=1)
|
94 |
+
```
|
95 |
|
96 |
+
Additionally, you can perform multimodal retrieval!
|
97 |
|
98 |
+
```python
|
99 |
|
100 |
+
def mean_pooling(model_output, attention_mask):
|
101 |
+
token_embeddings = model_output[0]
|
102 |
+
input_mask_expanded = attention_mask.unsqueeze(-1).expand(token_embeddings.size()).float()
|
103 |
+
return torch.sum(token_embeddings * input_mask_expanded, 1) / torch.clamp(input_mask_expanded.sum(1), min=1e-9)
|
104 |
|
105 |
+
sentences = ['search_query: What are cute animals to cuddle with?', 'search_query: What do cats look like?']
|
106 |
|
107 |
+
tokenizer = AutoTokenizer.from_pretrained('nomic-ai/nomic-embed-text-v1')
|
108 |
+
text_model = AutoModel.from_pretrained('nomic-ai/nomic-embed-text-v1', trust_remote_code=True)
|
109 |
+
text_model.eval()
|
110 |
|
111 |
+
encoded_input = tokenizer(sentences, padding=True, truncation=True, return_tensors='pt')
|
112 |
|
113 |
+
with torch.no_grad():
|
114 |
+
model_output = text_model(**encoded_input)
|
115 |
|
116 |
+
text_embeddings = mean_pooling(model_output, encoded_input['attention_mask'])
|
117 |
+
text_embeddings = F.normalize(text_embeddings, p=2, dim=1)
|
118 |
|
119 |
+
print(torch.matmul(img_embeddings, text_embeddings.T))
|
120 |
+
```
|
121 |
|
|
|
122 |
|
123 |
+
# Join the Nomic Community
|
124 |
|
125 |
+
- Nomic: [https://nomic.ai](https://nomic.ai)
|
126 |
+
- Discord: [https://discord.gg/myY5YDR8z8](https://discord.gg/myY5YDR8z8)
|
127 |
+
- Twitter: [https://twitter.com/nomic_ai](https://twitter.com/nomic_ai)
|