Skip to content

Instantly share code, notes, and snippets.

@gauravbansal98
Created May 14, 2020 11:48
Show Gist options
  • Save gauravbansal98/812754eb6a39a6329d0876306378b5cf to your computer and use it in GitHub Desktop.
Save gauravbansal98/812754eb6a39a6329d0876306378b5cf to your computer and use it in GitHub Desktop.
def evaluate_model(model, descriptions, photos, tokenizer, max_length):
actual, predicted = list(), list()
# step over the whole set
for key, desc_list in descriptions.items():
# generate description
yhat = generate_desc(model, tokenizer, photos[key], max_length)
# store actual and predicted
references = [d.split() for d in desc_list]
actual.append(references)
predicted.append(yhat.split())
# calculate BLEU score
print('BLEU-1: %f' % corpus_bleu(actual, predicted, weights=(1.0, 0, 0, 0)))
print('BLEU-2: %f' % corpus_bleu(actual, predicted, weights=(0.5, 0.5, 0, 0)))
print('BLEU-3: %f' % corpus_bleu(actual, predicted, weights=(0.3, 0.3, 0.3, 0)))
print('BLEU-4: %f' % corpus_bleu(actual, predicted, weights=(0.25, 0.25, 0.25, 0.25)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment