import tensorflow as tf import tensorflow_hub as hub # Load the pre-trained model gpus = tf.config.list_physical_devices('GPU') for gpu in gpus: # Control GPU memory usage tf.config.experimental.set_memory_growth(gpu, True) module_url = 'https://tfhub.dev/google/universal-sentence-encoder/4' model = hub.load(module_url) # Generate Embeddings sentence1_emb = model(stsb_test['sentence1']).numpy() sentence2_emb = model(stsb_test['sentence2']).numpy() # Cosine Similarity stsb_test['USE_cosine_score'] = cos_sim(sentence1_emb, sentence2_emb)