-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.py
52 lines (38 loc) · 1.48 KB
/
run.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
49
50
51
52
import os
import sys
from capreolus.utils.loginit import get_logger
from capreolus.task import RerankTask
from capreolus_extensions.LCETrainer import *
from capreolus_extensions.LCEReranker_and_Loss import *
from capreolus_extensions.LCEExactor import *
from capreolus_extensions.LCESampler import LCETrainTripletSampler
from capreolus_extensions.Tctv2MsmarcoSearcher import *
from utils import *
from args import get_args
logger = get_logger(__name__)
def run_single_fold(args, config):
fold = config['fold']
task = RerankTask(config)
if args.train:
logger.info(f"TASK: {args.config_path}")
logger.info(f"TRAINING ON FOLD {fold}")
preds, scores = task.train()
scores = scores["fold_dev_metrics"]
if args.eval:
logger.info(f"TASK: {args.config_path}\tEVALUATING ON FOLD {fold}")
task.predict_on_dev()
scores = task.evaluate_on_dev()
logger.info(f"dev metrics on fold {fold}: ")
logger.info(scores)
def main():
args = get_args()
config = load_yaml(args.config_path)
pretrain_dir = args.pretrained_dir
if pretrain_dir != "":
config["reranker"]["pretrained"] = os.path.join(pretrain_dir, config["reranker"]["pretrained"])
config["reranker"]["extractor"]["tokenizer"]["pretrained"] = \
os.path.join(pretrain_dir, config["reranker"]["extractor"]["tokenizer"]["pretrained"])
record_commit_id(args.config_path)
run_single_fold(args, config)
if __name__ == "__main__":
main()