Skip to content
Snippets Groups Projects
Commit 7c0fd548 authored by Alexis Nasr's avatar Alexis Nasr
Browse files

ajout de l'option v dans eval_mcf pour le calcul de la précision et du rappel pour chaque étiquette

parent 2d61f0d5
No related branches found
No related tags found
No related merge requests found
......@@ -13,6 +13,12 @@ refMcdFileName = sys.argv[3]
hypMcdFileName = sys.argv[4]
lang = sys.argv[5]
if len(sys.argv) == 7:
verbose = True
else:
verbose = False
#print('reading mcd from file :', refMcdFileName)
refMcd = Mcd(refMcdFileName)
......@@ -44,6 +50,10 @@ hypWordBuffer.readAllMcfFile()
govCorrect = 0
labelCorrect = 0
hypTotal = {}
refTotal = {}
refInterHypTotal = {}
hypSize = hypWordBuffer.getLength()
for index in range(hypSize):
refWord = refWordBuffer.getWord(index)
......@@ -52,16 +62,40 @@ for index in range(hypSize):
hypGov = hypWord.getFeat("GOV")
refLabel = refWord.getFeat("LABEL")
hypLabel = hypWord.getFeat("LABEL")
if hypLabel in hypTotal :
hypTotal[hypLabel] += 1
else:
hypTotal[hypLabel] = 1
if refLabel in refTotal :
refTotal[refLabel] += 1
else:
refTotal[refLabel] = 1
if refGov == hypGov :
govCorrect += 1
if refLabel == hypLabel :
labelCorrect += 1
LAS = labelCorrect / hypSize
UAS = govCorrect / hypSize
print(lang, LAS, UAS)
if refLabel in refInterHypTotal :
refInterHypTotal[refLabel] += 1
else:
refInterHypTotal[refLabel] = 1
LAS = 100 * labelCorrect / hypSize
UAS = 100 * govCorrect / hypSize
print("%s\t%.2f\t%.2f" % (lang, LAS, UAS))
if verbose :
print("------------------------------")
print("label\tprec\trec\tfscore")
print("------------------------------")
for label in refInterHypTotal:
precision = refInterHypTotal[label] / hypTotal[label]
recall = refInterHypTotal[label] / refTotal[label]
fscore = 2 * precision * recall / (precision + recall)
print("%s\t%.2f\t%.2f\t%.2f" % (label, precision, recall, fscore) )
# print("REF GOV = ", refGov, "HYP GOV = ", hypGov, "REF LABEL = ", refLabel, "HYP LABEL = ", hypLabel)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment