-
-
Save gauravbansal98/812754eb6a39a6329d0876306378b5cf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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