labels = np.array(y_true)
predictions = np.array(y_pred)
predictions = np.argsort(predictions, -1)
ranks = []
for i in range(predictions.shape[0]):
for j in range(predictions.shape[1]):
if predictions[i][j] in np.arange(labels[i][j]):
ranks.append(j)
break
return np.mean(np.asarray(ranks).astype(float))
@register_metric("loss")
After Change
predictions = np.flip(np.argsort(predictions, -1), -1)
rank_tot = 0
for el in predictions:
for i, x in enumerate(el):
if x == 0:
rank_tot += i
break
return float(rank_tot)/num_examples
@register_metric("r@1_insQA")
def r_at_1_insQA(y_true, y_pred):