-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathmain.py
48 lines (40 loc) · 1.22 KB
/
main.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
40
41
42
43
44
45
46
47
48
from pycocoevalcap.bleu.bleu import Bleu
from pycocoevalcap.cider.cider import Cider
from pycocoevalcap.meteor.meteor import Meteor
from pycocoevalcap.rouge.rouge import Rouge
from pycocoevalcap.spice.spice import Spice
import json
with open('examples/gts.json', 'r') as file:
gts = json.load(file)
with open('examples/res.json', 'r') as file:
res = json.load(file)
def bleu():
scorer = Bleu(n=4)
# scorer += (hypo[0], ref1) # hypo[0] = 'word1 word2 word3 ...'
# # ref = ['word1 word2 word3 ...', 'word1 word2 word3 ...']
score, scores = scorer.compute_score(gts, res)
print('belu = %s' % score)
def cider():
scorer = Cider()
# scorer += (hypo[0], ref1)
(score, scores) = scorer.compute_score(gts, res)
print('cider = %s' % score)
def meteor():
scorer = Meteor()
score, scores = scorer.compute_score(gts, res)
print('meter = %s' % score)
def rouge():
scorer = Rouge()
score, scores = scorer.compute_score(gts, res)
print('rouge = %s' % score)
def spice():
scorer = Spice()
score, scores = scorer.compute_score(gts, res)
print('spice = %s' % score)
def main():
bleu()
cider()
meteor()
rouge()
spice()
main()