MLNTeam-Unical commited on
Commit
4ed1904
·
1 Parent(s): 023a686

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +54 -0
README.md CHANGED
@@ -159,8 +159,62 @@ Data provided within this repository can be straightforwardly loaded via the *da
159
  from datasets import load_dataset
160
  dataset = load_dataset("MLNTeam-Unical/NFT-70M_transactions")
161
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
162
  ```
163
 
 
164
  ## Ethical use of data and informed consent
165
  This data repository is made available for research and informational purposes only.
166
 
 
159
  from datasets import load_dataset
160
  dataset = load_dataset("MLNTeam-Unical/NFT-70M_transactions")
161
 
162
+
163
+ ```
164
+ if you want to ....
165
+ ```
166
+ from datasets import load_dataset
167
+ import numpy as np
168
+
169
+
170
+ transactions_dataset=load_dataset("MLNTeam-Unical/NFT-70M_transactions")
171
+
172
+ image_dataset=load_dataset("MLNTeam-Unical/NFT-70M_image")
173
+
174
+ text_dataset=load_dataset("MLNTeam-Unical/NFT-70M_text")
175
+
176
+
177
+ ################################################################################
178
+ #compute a mapping from image_id to the row_index within the image dataset
179
+ image_id2row_index={int(id):k for k,id in enumerate(image_dataset["train"]["id"])}
180
+ #compute a mapping from text_id to row_index within the text dataset
181
+ text_id2row_index={int(id):k for k,id in enumerate(text_dataset["train"]["id"])}
182
+
183
+
184
+ def get_image_embedding(image_id,image_id2row_index,image_dataset):
185
+ #if the mapping contains the image, the embedding is present
186
+ idx_emb=image_id2row_index.get(int(image_id),None)
187
+
188
+ if idx_emb:
189
+ #if the embedding is present it is returned
190
+ return np.array(image_dataset["train"].select([idx_emb])["emb"][0])
191
+ else:
192
+ #otherwise None is returned
193
+ return None
194
+
195
+ def get_text_embedding(text_id,text_id2row_index,text_dataset):
196
+ #if the mapping contains the image, the embedding is present
197
+ idx_emb=text_id2row_index.get(int(text_id),None)
198
+ if idx_emb:
199
+ #if the embedding is present it is returned
200
+ return np.array(text_dataset["train"].select([idx_emb])["emb"][0])
201
+ else:
202
+ #otherwise None is returned
203
+ return None
204
+ #### USAGE EXAMPLE #########
205
+
206
+ transaction_id=120
207
+
208
+ id_image=transactions_dataset["train"].select([transaction_id])["collection_image"][0]
209
+
210
+ image_embedding=get_image_embedding(id_image,image_id2row_index,image_dataset)
211
+
212
+ id_text=transactions_dataset["train"].select([transaction_id])["collection_description"][0]
213
+
214
+ text_embedding=get_text_embedding(id_text,text_id2row_index,text_dataset)
215
  ```
216
 
217
+
218
  ## Ethical use of data and informed consent
219
  This data repository is made available for research and informational purposes only.
220