PyTorch
English
Tevatron
phi3_v
vidore
custom_code
MrLight commited on
Commit
3f8b454
1 Parent(s): 54c02c0

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +19 -4
README.md CHANGED
@@ -39,7 +39,7 @@ def get_embedding(last_hidden_state: torch.Tensor, attention_mask: torch.Tensor)
39
  ### Encode Text Query
40
 
41
  ```python
42
- queries = ["query: Where can we find Llama?", "query: What is the LLaMA model?"]
43
  query_inputs = processor(queries, return_tensors="pt", padding="longest", max_length=128, truncation=True).to('cuda:0')
44
  output = model(**query_inputs, return_dict=True, output_hidden_states=True)
45
  query_embeddings = get_embedding(output.hidden_states[-1], query_inputs["attention_mask"])
@@ -49,12 +49,24 @@ query_embeddings = get_embedding(output.hidden_states[-1], query_inputs["attenti
49
 
50
  ```python
51
  from PIL import Image
 
 
 
 
 
 
 
 
 
 
 
 
 
52
 
53
- passage_image1 = Image.open("path/to/your/image1.png")
54
- passage_image2 = Image.open("path/to/your/image2.png")
55
  passage_images = [passage_image1, passage_image2]
56
  passage_prompts = ["\nWhat is shown in this image?</s>", "\nWhat is shown in this image?</s>"]
57
 
 
58
  passage_inputs = processor(passage_prompts, images=passage_images, return_tensors="pt", padding="longest", max_length=4096, truncation=True).to('cuda:0')
59
  output = model(**passage_inputs, return_dict=True, output_hidden_states=True)
60
  doc_embeddings = get_embedding(output.hidden_states[-1], passage_inputs["attention_mask"])
@@ -72,7 +84,10 @@ print(similarities)
72
  ### Encode Document Text
73
  This DSE checkpoint is warm-up with `Tevatron/msmarco-passage-aug`, thus the model can also effectively encode document as text input.
74
  ```python
75
- passage_prompts = ["Llama is in Aferica</s>", "LLaMA is an LLM released by Meta.</s>"]
 
 
 
76
 
77
  passage_inputs = processor(passage_prompts, images=None, return_tensors="pt", padding="longest", max_length=4096, truncation=True).to('cuda:0')
78
  output = model(**passage_inputs, return_dict=True, output_hidden_states=True)
 
39
  ### Encode Text Query
40
 
41
  ```python
42
+ queries = ["query: Where can we see Llama?", "query: What is LLaMA model?"]
43
  query_inputs = processor(queries, return_tensors="pt", padding="longest", max_length=128, truncation=True).to('cuda:0')
44
  output = model(**query_inputs, return_dict=True, output_hidden_states=True)
45
  query_embeddings = get_embedding(output.hidden_states[-1], query_inputs["attention_mask"])
 
49
 
50
  ```python
51
  from PIL import Image
52
+ import requests
53
+ from io import BytesIO
54
+
55
+ # URLs of the images
56
+ url1 = "https://huggingface.co/Tevatron/dse-phi3-docmatix-v1.0/blob/main/animal-llama.png"
57
+ url2 = "https://huggingface.co/Tevatron/dse-phi3-docmatix-v1.0/blob/main/meta-llama.png"
58
+
59
+ # Download and open images
60
+ response1 = requests.get(url1)
61
+ response2 = requests.get(url2)
62
+
63
+ passage_image1 = Image.open(BytesIO(response1.content))
64
+ passage_image2 = Image.open(BytesIO(response2.content))
65
 
 
 
66
  passage_images = [passage_image1, passage_image2]
67
  passage_prompts = ["\nWhat is shown in this image?</s>", "\nWhat is shown in this image?</s>"]
68
 
69
+ # Process inputs and get embeddings
70
  passage_inputs = processor(passage_prompts, images=passage_images, return_tensors="pt", padding="longest", max_length=4096, truncation=True).to('cuda:0')
71
  output = model(**passage_inputs, return_dict=True, output_hidden_states=True)
72
  doc_embeddings = get_embedding(output.hidden_states[-1], passage_inputs["attention_mask"])
 
84
  ### Encode Document Text
85
  This DSE checkpoint is warm-up with `Tevatron/msmarco-passage-aug`, thus the model can also effectively encode document as text input.
86
  ```python
87
+ passage_prompts = [
88
+ "The llama (/ˈlɑːmə/; Spanish pronunciation: [ˈʎama] or [ˈʝama]) (Lama glama) is a domesticated South American camelid, widely used as a meat and pack animal by Andean cultures since the pre-Columbian era.</s>",
89
+ "Llama (acronym for Large Language Model Meta AI, and formerly stylized as LLaMA) is a family of autoregressive large language models (LLMs) released by Meta AI starting in February 2023.[2][3] The latest version is Llama 3.1, released in July 2024.[4]"
90
+ ]
91
 
92
  passage_inputs = processor(passage_prompts, images=None, return_tensors="pt", padding="longest", max_length=4096, truncation=True).to('cuda:0')
93
  output = model(**passage_inputs, return_dict=True, output_hidden_states=True)