-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcaption_utils.py
More file actions
24 lines (18 loc) · 1.2 KB
/
Copy pathcaption_utils.py
File metadata and controls
24 lines (18 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
################################################################################
# CSE 253: Programming Assignment 4
# Code snippet by Ajit Kumar, Savyasachi
# Fall 2020
################################################################################
from nltk.translate.bleu_score import sentence_bleu, SmoothingFunction
# See this for input references - https://www.nltk.org/api/nltk.translate.html#nltk.translate.bleu_score.sentence_bleu
# A Caption should be a list of strings.
# Reference Captions are list of actual captions - list(list(str))
# Predicted Caption is the string caption based on your model's output - list(str)
# Make sure to process your captions before evaluating bleu scores -
# Converting to lower case, Removing tokens like <start>, <end>, padding etc.
def bleu1(reference_captions, predicted_caption):
return 100 * sentence_bleu(reference_captions, predicted_caption,
weights=(1, 0, 0, 0), smoothing_function=SmoothingFunction().method1)
def bleu4(reference_captions, predicted_caption):
return 100 * sentence_bleu(reference_captions, predicted_caption,
weights=(0, 0, 0, 1), smoothing_function=SmoothingFunction().method1)