|
import pyarrow.parquet as pq |
|
|
|
METADATA_FILEPATH = '/home/sena/plato_backend/scripts/huggingface_embedding_sharing/huggingface_embedding_sharing/save_backup/metadata_file.parquet' |
|
EMBEDDINGS_FILEPATH = '/home/sena/plato_backend/scripts/huggingface_embedding_sharing/huggingface_embedding_sharing/embeddings_2.txt' |
|
|
|
|
|
def read_embeddings(filepath): |
|
|
|
|
|
with open(filepath, 'rb') as f: |
|
lines = f.readlines() |
|
|
|
embedding_dict = {} |
|
|
|
for index, line in enumerate(lines): |
|
line_as_list = line.split() |
|
|
|
|
|
float_list = [float(byte_string.decode('utf-8')) for byte_string in line_as_list] |
|
|
|
|
|
embedding_dict[index] = float_list |
|
|
|
return embedding_dict |
|
|
|
|
|
|
|
metadata_df = pq.read_table(METADATA_FILEPATH).to_pandas() |
|
|
|
|
|
unique_id = '390U_535R_2021-08-21064631_69' |
|
|
|
|
|
row = metadata_df.loc[metadata_df['unique_id'] == unique_id] |
|
|
|
|
|
dat_row_value = row['dat_row'] |
|
embedding_file_value = row['embedding_file'] |
|
|
|
|
|
embeddings = read_embeddings(EMBEDDINGS_FILEPATH) |
|
vector = embeddings[int(dat_row_value)] |
|
|
|
print(f"Row: {row}, Dat Row: {dat_row_value}, Embedding File: {embedding_file_value}, Vector length: {len(vector)}") |
|
|
|
|
|
|
|
|
|
|
|
|