Skip to content

Commit

Permalink
Mod: Slight code cleaning of CIDEr-D computation.
Browse files Browse the repository at this point in the history
  • Loading branch information
Labbeti committed Jun 9, 2023
1 parent 3e6d0f9 commit 252001a
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions src/aac_metrics/functional/cider_d.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,25 +262,21 @@ def __compute_cider(
# compute vector for test captions
vec, norm, length = __counter_to_vec(cand, log_n_refs, n, doc_frequencies)
# compute vector for ref captions
ngrams_scores = np.zeros((n,))
ngrams_scores = np.zeros((len(refs), n))
vec_refs = []
for ref in refs:
for j, ref in enumerate(refs):
vec_ref, norm_ref, length_ref = __counter_to_vec(
ref, log_n_refs, n, doc_frequencies
)
vec_refs.append(vec_ref)
ngrams_scores += __similarity(
ngrams_scores[j] = __similarity(
vec, vec_ref, norm, norm_ref, length, length_ref, n, sigma
)
# change by vrama91 - mean of ngram scores, instead of sum
score_avg = np.mean(ngrams_scores)
# divide by number of references
score_avg /= len(refs)
# multiply score by 10
score_avg *= scale
# append score of an image to the score list
scores[i] = score_avg

# Use this weird mean calculation instead of ".mean()" because it can give slight differences compared to the original implementation
score_avg = ngrams_scores.sum(axis=0).mean() / len(refs)
scores[i] = score_avg
tfidf_lst.append((vec, vec_refs))

scores = scores * scale
return scores, tfidf_lst

0 comments on commit 252001a

Please sign in to comment.