senaK-quasara commited on
Commit
984890f
1 Parent(s): 2abc0fd

Upload read_dataset.py

Browse files
Files changed (1) hide show
  1. read_dataset.py +49 -0
read_dataset.py ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pyarrow.parquet as pq
2
+
3
+ METADATA_FILEPATH = 'path/to/your/metadata_file.parquet'
4
+ EMBEDDINGS_FILEPATH = 'path/to/your/embeddings.dat'
5
+
6
+
7
+ def read_embeddings(filepath):
8
+
9
+ # Read the lines from the file
10
+ with open(filepath, 'rb') as f:
11
+ lines = f.readlines()
12
+
13
+ embedding_dict = {}
14
+
15
+ for index, line in enumerate(lines):
16
+ line_as_list = line.split()
17
+
18
+ # Decode the byte string to a regular string and convert to float
19
+ float_list = [float(byte_string.decode('utf-8')) for byte_string in line_as_list]
20
+
21
+ # Save the float list (embeddings) to the dictionary with the index as the key
22
+ embedding_dict[index] = float_list
23
+
24
+ return embedding_dict
25
+
26
+
27
+ #Read the metadata file
28
+ metadata_df = pq.read_table(METADATA_FILEPATH).to_pandas()
29
+
30
+ ## How to reach embeddings - example for a specific row
31
+ unique_id = '390U_535R_2021-08-21064631_69'
32
+
33
+ # Get the row with the unique_id
34
+ row = metadata_df.loc[metadata_df['unique_id'] == unique_id]
35
+
36
+ # Get the values for 'data_row' and 'embedding_file'
37
+ dat_row_value = row['dat_row'] # index of the row in the embedding file
38
+ embedding_file_value = row['embedding_file'] # specific embedding file for the row
39
+
40
+ # Read the embeddings in the embedding file
41
+ embeddings = read_embeddings(EMBEDDINGS_FILEPATH)
42
+ vector = embeddings[dat_row_value]
43
+
44
+ print(f"Row: {row}, Dat Row: {dat_row_value}, Embedding File: {embedding_file_value}, Vector length: {len(vector)}")
45
+ #print(f"Vector: {vector}")
46
+
47
+
48
+
49
+