anal.py 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. from functools import lru_cache
  2. from glob import glob
  3. import json
  4. import re
  5. import sys
  6. data_list = glob(f"{sys.argv[1]}/jsons/*")
  7. pattern = re.compile(r'\-?\d+\.\d+|\-?\d+')
  8. right = 0
  9. all_fail = 0
  10. truncate = 8
  11. print(len(data_list))
  12. from run_with_earlystopping import check
  13. retry_times = []
  14. retry_times_no_one = []
  15. def checklist(gt,anss):
  16. for ans in anss:
  17. if check(gt,ans):
  18. return True
  19. return False
  20. for file in data_list:
  21. with open(file, 'r') as f:
  22. data = json.load(f)
  23. retry_time = len(data['answers_list'])
  24. retry_times.append(retry_time)
  25. answers = []
  26. for i in data['answers_list']:
  27. if i in ["I Don't Know","I can't understand this question.","I can't help with this question.","I don't know how to solve this question.","I don't know the answer to this question.","I don't know the answer to this question, sorry."]:
  28. pass
  29. else:
  30. answers.append(i)
  31. if checklist(data['ground_truth'],answers):
  32. right += 1
  33. else:
  34. all_fail += 1
  35. import numpy as np
  36. all_len = len(data_list)
  37. print('Acc rate',right,all_len,right/all_len)