forked from avisinghal6/VIDEO_CAPTIONING_PIPELINE
-
Notifications
You must be signed in to change notification settings - Fork 0
/
meteor_metric.py
39 lines (36 loc) · 1.19 KB
/
meteor_metric.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
from nltk.translate import meteor
from nltk import word_tokenize
from nltk.translate.bleu_score import sentence_bleu
from evaluate import load
bertscore = load("bertscore")
import json
import nltk
nltk.download('punkt')
nltk.download('wordnet')
def get_meteor_score(data, bard_captions):
output = {}
for key in bard_captions:
input_captions = ""
k=f'v_{key}'
for i in data[k]['sentences']:
input_captions = input_captions + i+'. '
output[key] = meteor([word_tokenize(input_captions)],word_tokenize(bard_captions[key]))
return output
def get_bleu_score(data, bard_captions):
output = {}
for key in bard_captions:
input_captions = ""
k=f'v_{key}'
for i in data[k]['sentences']:
input_captions = input_captions + i+'. '
output[key] = sentence_bleu([word_tokenize(input_captions)],word_tokenize(bard_captions[key]))
return output
def get_bert_score(data, bard_captions):
output = {}
for key in bard_captions:
input_captions = ""
k=f'v_{key}'
for i in data[k]['sentences']:
input_captions = input_captions + i+'. '
output[key] =bertscore.compute(predictions=[bard_captions[key]], references=[input_captions], lang="en")
return output