image_output_1.png
import csv

import numpy as np

ROOT_PATH = '/kaggle/input/CORD-19-research-challenge/'
METADATA_PATH = f'{ROOT_PATH}/metadata.csv'
SAMPLE_SIZE = None

def create_embedding_dict(filepath, sample_size=None):
    """function to create embedding dictionary using given file"""
    embedding_dict = {}
    with open(filepath) as csvfile:
        reader = csv.reader(csvfile, delimiter=',')
        for i, row in enumerate(reader):
            if i == sample_size:
                break
            embed = np.zeros((768,))
            for idx, val in enumerate(row):
                if idx > 0:
                    embed[idx - 1] = float(val)
            embedding_dict[row[0]] = embed
    return embedding_dict

embedding_dict = create_embedding_dict(f'{ROOT_PATH}/cord19_specter_embeddings_2020-04-10/cord19_specter_embeddings_2020-04-10.csv', sample_size=SAMPLE_SIZE)
embedding_mat = np.array(list(embedding_dict.values()))
(embedding_mat.shape, len(embedding_dict))