MLNTeam-Unical commited on
Commit
1b771e8
1 Parent(s): 4ed1904

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +19 -16
README.md CHANGED
@@ -155,62 +155,65 @@ In this respect, we carried out three actions:
155
  ## How to use
156
  Data provided within this repository can be straightforwardly loaded via the *datasets* library as follows:
157
 
158
- ```
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
 
 
155
  ## How to use
156
  Data provided within this repository can be straightforwardly loaded via the *datasets* library as follows:
157
 
158
+ ```python
159
  from datasets import load_dataset
160
  dataset = load_dataset("MLNTeam-Unical/NFT-70M_transactions")
161
+ ```
162
 
163
+ Complementary data involving textual and visual embeddings can be integrated as follows:
164
 
165
+ ```python
 
 
166
  from datasets import load_dataset
167
  import numpy as np
168
 
169
 
170
  transactions_dataset=load_dataset("MLNTeam-Unical/NFT-70M_transactions")
 
171
  image_dataset=load_dataset("MLNTeam-Unical/NFT-70M_image")
 
172
  text_dataset=load_dataset("MLNTeam-Unical/NFT-70M_text")
173
 
174
 
175
+ # Mapping from image_id to the row_index within the image dataset
 
176
  image_id2row_index={int(id):k for k,id in enumerate(image_dataset["train"]["id"])}
177
+
178
+ # Mapping from text_id to row_index within the text dataset
179
  text_id2row_index={int(id):k for k,id in enumerate(text_dataset["train"]["id"])}
180
 
181
 
182
  def get_image_embedding(image_id,image_id2row_index,image_dataset):
183
+ # If the mapping contains the image, the embedding exists
184
  idx_emb=image_id2row_index.get(int(image_id),None)
185
 
186
  if idx_emb:
187
+ # If the embedding exists, return it
188
  return np.array(image_dataset["train"].select([idx_emb])["emb"][0])
189
  else:
 
190
  return None
191
 
192
  def get_text_embedding(text_id,text_id2row_index,text_dataset):
193
+ # If the mapping contains the image, the embedding exists
194
  idx_emb=text_id2row_index.get(int(text_id),None)
195
+
196
  if idx_emb:
197
+ # If the embedding exists, return it
198
  return np.array(text_dataset["train"].select([idx_emb])["emb"][0])
199
  else:
 
200
  return None
 
201
 
202
+ ### USAGE EXAMPLE ###
203
+
204
+ # Select transaction_id
205
  transaction_id=120
206
 
207
+ # Get the image_id (e.g., collection_image or nft_image)
208
  id_image=transactions_dataset["train"].select([transaction_id])["collection_image"][0]
209
 
210
+ # Get the image
211
  image_embedding=get_image_embedding(id_image,image_id2row_index,image_dataset)
212
 
213
+ # Get the text_id
214
  id_text=transactions_dataset["train"].select([transaction_id])["collection_description"][0]
215
 
216
+ # Get the text
217
  text_embedding=get_text_embedding(id_text,text_id2row_index,text_dataset)
218
  ```
219