PEFT
TensorBoard
Safetensors
ColPali
Turkish
turkish
TR
selimc commited on
Commit
7eafde0
·
verified ·
1 Parent(s): 55f9142

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +16 -6
README.md CHANGED
@@ -48,7 +48,11 @@ The training data was created via the following steps:
48
  The complete code for fine-tuning, testing, and creating similarity maps can be found in the [turkish-colpali GitHub repository](https://github.com/selimcavas/turkish-colpali). All notebooks in the repository are in Turkish to better serve the Turkish NLP community.
49
 
50
  ```python
 
 
 
51
  import torch
 
52
  from PIL import Image
53
  from transformers import ColPaliForRetrieval, ColPaliProcessor
54
 
@@ -61,6 +65,13 @@ model = ColPaliForRetrieval.from_pretrained(
61
 
62
  processor = ColPaliProcessor.from_pretrained(model_name)
63
 
 
 
 
 
 
 
 
64
  # Your inputs
65
  images: List[Image.Image] = [
66
  load_image_from_url(
@@ -77,24 +88,23 @@ images: List[Image.Image] = [
77
  ),
78
  ]
79
 
80
- queries = [
81
  "ekonomiyi düzeltme çabaları demir yolları gelir gider grafik",
82
  "bitkilerin yapısı bitkisel dokular meristem doku",
83
  "besin grupları tablosu karbonhidratlar",
84
  "Türk milli mücadelesi emperyalizm Atatürk görseli"
85
  ]
86
 
87
- # Process the inputs
88
  batch_images = processor(images=images).to(model.device)
89
  batch_queries = processor(text=queries).to(model.device)
90
 
91
  # Forward pass
92
  with torch.no_grad():
93
- image_embeddings = model(**batch_images)
94
- query_embeddings = model(**batch_queries)
95
 
96
- # Score the queries against the images
97
- scores = processor.score_retrieval(query_embeddings, image_embeddings)
98
 
99
  scores
100
 
 
48
  The complete code for fine-tuning, testing, and creating similarity maps can be found in the [turkish-colpali GitHub repository](https://github.com/selimcavas/turkish-colpali). All notebooks in the repository are in Turkish to better serve the Turkish NLP community.
49
 
50
  ```python
51
+ from io import BytesIO
52
+ from typing import List
53
+ import requests
54
  import torch
55
+ from IPython.display import display
56
  from PIL import Image
57
  from transformers import ColPaliForRetrieval, ColPaliProcessor
58
 
 
65
 
66
  processor = ColPaliProcessor.from_pretrained(model_name)
67
 
68
+ def load_image_from_url(url: str) -> Image.Image:
69
+ """
70
+ Load a PIL image from a valid URL.
71
+ """
72
+ response = requests.get(url)
73
+ return Image.open(BytesIO(response.content))
74
+
75
  # Your inputs
76
  images: List[Image.Image] = [
77
  load_image_from_url(
 
88
  ),
89
  ]
90
 
91
+ queries: List[str] = [
92
  "ekonomiyi düzeltme çabaları demir yolları gelir gider grafik",
93
  "bitkilerin yapısı bitkisel dokular meristem doku",
94
  "besin grupları tablosu karbonhidratlar",
95
  "Türk milli mücadelesi emperyalizm Atatürk görseli"
96
  ]
97
 
98
+ # Preprocess inputs
99
  batch_images = processor(images=images).to(model.device)
100
  batch_queries = processor(text=queries).to(model.device)
101
 
102
  # Forward pass
103
  with torch.no_grad():
104
+ image_embeddings = model(**batch_images).embeddings
105
+ query_embeddings = model(**batch_queries).embeddings
106
 
107
+ scores = processor.score_retrieval(query_embeddings, image_embeddings) # (n_queries, n_images)
 
108
 
109
  scores
110