File size: 1,400 Bytes
ebdb5af
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import os
import json
import math


class Results:

    def __init__(self, filepath, DOMAINS) -> None:
        self.filepath = filepath
        self.best_intermediate_results_list = []
        self.other_results_list = []
        self.DOMAINS = DOMAINS
        
        self.best_f1_scores = {
            domain: {
                "cross_domain_f1": -math.inf,
                "params": {},
                "balance": None,
                "pos_prob": None,
                "ner_prob": None
            }
            for domain in self.DOMAINS
        }
    
    def best_intermediate_results(self, result):
        self.best_intermediate_results_list.append(result)

        with open(os.path.join(self.filepath, 'best_intermediate_self.json'), "w", encoding="utf-8") as f:
            json.dump(self.best_intermediate_results_list, f, ensure_ascii=False,
                      indent=4)
    
    def best_final_results(self):
        with open(os.path.join(self.filepath, 'best_final_self.json'), "w", encoding="utf-8") as f:
            json.dump(self.best_f1_scores, f, ensure_ascii=False, indent=4)
    
    def other_results(self, result):
        self.other_results_list.append(result)
        
        with open(os.path.join(self.filepath, 'other_self.json'), "w", encoding="utf-8") as f:
            json.dump(self.other_results_list, f, ensure_ascii=False,
                      indent=4)