c672738b39c8f739551da0d88991a2fedfba3e14,deeppavlov/models/ranking/metrics.py,,recall_at_k,#Any#Any#Any#,24
Before Change
return recall_at_k(labels, predictions, k=10)
def recall_at_k(y_true, y_pred, k):
labels = np.array(y_true)
predictions = np.array(y_pred)
predictions = np.argsort(predictions, -1)[:, :k]
flags = np.zeros_like(predictions)
for i in range(predictions.shape[0]):
for j in range(predictions.shape[1]):
if predictions[i][j] in np.arange(labels[i][j]):
flags[i][j] = 1.
return np.mean((np.sum(flags, -1) >= 1.).astype(float))
After Change
predictions = np.flip(np.argsort(predictions, -1), -1)[:, :k]
num_correct = 0
for el in predictions:
if 0 in el:
num_correct += 1
return float(num_correct) / num_examples
@register_metric("rank_response")
def rank_response(y_true, y_pred):
In pattern: SUPERPATTERN
Frequency: 3
Non-data size: 4
Instances
Project Name: deepmipt/DeepPavlov
Commit Name: c672738b39c8f739551da0d88991a2fedfba3e14
Time: 2018-10-04
Author: puleon@mail.ru
File Name: deeppavlov/models/ranking/metrics.py
Class Name:
Method Name: recall_at_k
Project Name: deepmipt/DeepPavlov
Commit Name: c672738b39c8f739551da0d88991a2fedfba3e14
Time: 2018-10-04
Author: puleon@mail.ru
File Name: deeppavlov/models/ranking/metrics.py
Class Name:
Method Name: rank_response
Project Name: asappresearch/sru
Commit Name: faf3aa876462323f2fa721ebd633752d6489808f
Time: 2020-09-18
Author: taolei@csail.mit.edu
File Name: sru/modules.py
Class Name: SRU
Method Name: forward