i not sure, but maybe this work.
def corr_loss(weights, y_pred,uncorrelated_c_pairs):
    num_classes = len(weights[:,0])
   
    loss=0
    for uncorr_c_pair in uncorrelated_c_pairs:
          c1, c2, v = uncorr_c_pair
          loss += torch.sum(y_pred[:,c1]*y_pred[:,c2])*((y_pred[:,c1].sum()+y_pred[:,c2].sum()))/(y_pred[:,c1].sum()*y_pred[:,c2].sum())
 
    return loss