Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug in evaluation for tie in scores. #10

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 16 additions & 8 deletions eval_utils/rank_answerer.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,22 @@

def rankOptions(options, gtOptions, scores):
'''Rank a batch of examples against a list of options.'''
numOptions = options.size(1)
# Compute score of GT options in 'scores'
gtScores = scores.gather(1, gtOptions.unsqueeze(1))
# Sort all predicted scores
sortedScore, _ = torch.sort(scores, 1)
# In sorted scores, count how many are greater than the GT score
ranks = torch.sum(sortedScore.gt(gtScores).float(), 1)
return ranks + 1
# sort in descending order - largest score gets highest rank
sortedRanks, rankedIdx = scores.sort(1, descending=True)

# convert from rankedIdx to ranks
ranks = rankedIdx.clone().fill_(0)
for i in range(rankedIdx.size(0)):
for j in range(100):
ranks[i][rankedIdx[i][j]] = j
ranks += 1

gtOptions = gtOptions.view(-1)
gtRanks = torch.LongTensor(gtOptions.size(0))
for i in range(gtOptions.size(0)):
gtRanks[i] = int(ranks[i, gtOptions[i]])

return gtRanks


def rankABot(aBot, dataset, split, scoringFunction, exampleLimit=None):
Expand Down