我想請問有什麼方法在python語法之下可以加速巢狀for迴圈的
def Compute(testdata,FAQ):
scoreboard=[]
for i in tqdm(range(1035)):
encoded_dict1=tokenizer.encode_plus(
testdata[i][1],
add_special_tokens = True,
max_length = 100,
pad_to_max_length = True,
return_attention_mask = True,
return_tensors = 'pt',
truncation=True
)
invector=model(encoded_dict1['input_ids'],encoded_dict1['attention_mask'],'cls')
faq_score=[]
for j in tqdm(range(5821)):
encoded_dict2=tokenizer.encode_plus(
FAQ[j][2],
add_special_tokens = True,
max_length = 100,
pad_to_max_length = True,
return_attention_mask = True,
return_tensors = 'pt',
truncation=True
)
faqvector=model(encoded_dict2['input_ids'],encoded_dict2['attention_mask'],'cls')
score=float(torch.cosine_similarity(faqvector,invector))
faq_score.append([FAQ[j][1],score])
#print(i,j)
scoreboard.append(faq_score)
return scoreboard