Commit 1e5ca88d authored by Percedal's avatar Percedal
Browse files

script eval

parent 176990ae
import json
import pandas as pd
import argparse
def load_dictionary():
dictionary = {}
df = pd.read_csv("sens.csv", index_col="Acronym").drop("Unnamed: 0", axis=1)
for row in df.itertuples():
token = row[1]
lem_def = row[3]
if token not in dictionary:
dictionary[token] = []
dictionary[token].append(lem_def)
return dictionary
def load_annot(path):
with open(path, "r") as file:
return json.load(file)
def count(annot):
count_dict = {}
for d in annot:
_,_,_,acr = d.values()
for d2 in acr:
tid,tk,_,_,deflem,_,pred = d2.values()
if not tk in count_dict:
count_dict[tk] = {
"count":[0,0],
"senses":{}
}
count_dict[tk]["count"][1] += 1
if pred == "...":
print(f"--> Prédiction manquante pour id token {tid} ({tk})")
elif pred == deflem:
count_dict[tk]["count"][0] += 1
return count_dict
def acc(count_dict):
prec = 0
rapp = 0
somme = 0
prm = {k:None for k in count_dict.keys()}
for k,v in count_dict.items():
count = v["count"][0]
total = v["count"][1]
prec += count
rapp += total - count
somme += total
prm[k] = {
"precision" : count/total,
"rappel" : 1-count/total
}
return prec/somme, rapp/somme, prm
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Eval modèle")
parser.add_argument(
"json",
action="store",
nargs=1,
help="Fichier json complété (champ prédiction renseigné)"
)
parser.add_argument(
"output",
action="store",
nargs="?",
help="Output (format json), optionnel"
)
args = parser.parse_args()
annot = load_annot(args.json[0])
prec, rapp, prm = acc(count(annot))
print("Précision :", prec)
if args.output:
with open(args.output, "w") as file:
json.dump(
{
"precision": prec,
"rappel" : rapp,
"tokens": prm
},
file,
indent=4
)
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment