hanxiao commited on
Commit
668152b
1 Parent(s): a3213ad

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +16 -4
README.md CHANGED
@@ -38,16 +38,28 @@ from numpy.linalg import norm
38
 
39
  cos_sim = lambda a,b: (a @ b.T) / (norm(a)*norm(b))
40
 
 
41
  model = AutoModel.from_pretrained('jinaai/jina-clip-v1', trust_remote_code=True)
42
 
43
- sentences = ['The Eiffel Tower is in Paris.', 'The capital of France is Paris.']
44
- images = ['tower.jpg', 'paris.jpg'] # here we use filenames, but it also accepts URL, PIL.Image objects and dataURI strings
45
 
46
- text_embeddings = model.encode_text(sentences) # encode_text and encode_image are helper function made by us to easily get embeddings
47
- image_embeddings = model.encode_image(images)
 
 
 
48
 
 
 
 
 
 
49
  print(cos_sim(text_embeddings[0], text_embeddings[1])) # text embedding similarity
50
  print(cos_sim(text_embeddings[0], image_embeddings[0])) # text-image cross-modal similarity
 
 
 
51
  ```
52
 
53
 
 
38
 
39
  cos_sim = lambda a,b: (a @ b.T) / (norm(a)*norm(b))
40
 
41
+ # Initialize the model
42
  model = AutoModel.from_pretrained('jinaai/jina-clip-v1', trust_remote_code=True)
43
 
44
+ # New meaningful sentences
45
+ sentences = ['Bridge close-shot', 'Bridge in far away']
46
 
47
+ # Public image URLs
48
+ image_urls = [
49
+ 'https://fastly.picsum.photos/id/74/4288/2848.jpg?hmac=q02MzzHG23nkhJYRXR-_RgKTr6fpfwRgcXgE0EKvNB8',
50
+ 'https://fastly.picsum.photos/id/84/1280/848.jpg?hmac=YFRYDI4UsfbeTzI8ZakNOR98wVU7a-9a2tGF542539s'
51
+ ]
52
 
53
+ # Encode text and images
54
+ text_embeddings = model.encode_text(sentences)
55
+ image_embeddings = model.encode_image(image_urls) # also accepts PIL.image, local filenames, dataURI
56
+
57
+ # Compute similarities
58
  print(cos_sim(text_embeddings[0], text_embeddings[1])) # text embedding similarity
59
  print(cos_sim(text_embeddings[0], image_embeddings[0])) # text-image cross-modal similarity
60
+ print(cos_sim(text_embeddings[0], image_embeddings[1])) # text-image cross-modal similarity
61
+ print(cos_sim(text_embeddings[1], image_embeddings[0])) # text-image cross-modal similarity
62
+ print(cos_sim(text_embeddings[1], image_embeddings[1])) # text-image cross-modal similarity
63
  ```
64
 
65