-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathargs.py
executable file
·139 lines (111 loc) · 8.07 KB
/
args.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
import argparse
def _add_common_args(arg_parser):
arg_parser.add_argument('--config', type=str)
arg_parser.add_argument("--local_rank", type=int, default=-1, help="")
arg_parser.add_argument("--world_size", type=int, default=-1, help="")
# Input
arg_parser.add_argument('--types_path', type=str, help="Path to type specifications")
# Preprocessing
arg_parser.add_argument('--tokenizer_path', type=str, help="Path to tokenizer")
arg_parser.add_argument('--lowercase', action='store_true', default=False,
help="If true, input is lowercased during preprocessing")
arg_parser.add_argument('--sampling_processes', type=int, default=4,
help="Number of sampling processes. 0 = no multiprocessing for sampling")
# Logging
arg_parser.add_argument('--label', type=str, help="Label of run. Used as the directory name of logs/models")
arg_parser.add_argument('--log_path', type=str, help="Path do directory where training/evaluation logs are stored")
arg_parser.add_argument('--store_predictions', action='store_true', default=False,
help="If true, store predictions on disc (in log directory)")
arg_parser.add_argument('--store_examples', action='store_true', default=False,
help="If true, store evaluation examples on disc (in log directory)")
arg_parser.add_argument('--example_count', type=int, default=None,
help="Count of evaluation example to store (if store_examples == True)")
arg_parser.add_argument('--debug', action='store_true', default=False, help="Debugging mode on/off")
# Model / Training / Evaluation
arg_parser.add_argument("--ignore_gpu_usage", action="store_true",
help="If ignored, will occupy gpu which is been used")
arg_parser.add_argument('--device_id', type=int, default=-1, help="gpu device id")
arg_parser.add_argument('--model_path', type=str, help="Path to directory that contains model checkpoints")
arg_parser.add_argument('--model_type', type=str, default="identifier", help="Type of model")
arg_parser.add_argument('--cpu', action='store_true', default=False,
help="If true, train/evaluate on CPU even if a CUDA device is available")
arg_parser.add_argument('--eval_batch_size', type=int, default=1, help="Evaluation batch size")
arg_parser.add_argument('--prop_drop', type=float, default=0.1, help="Probability of dropout used in Identifier")
arg_parser.add_argument('--freeze_transformer', action='store_true', default=False, help="Freeze BERT weights")
arg_parser.add_argument('--no_overlapping', action='store_true', default=False,
help="If true, do not evaluate on overlapping entities "
"and relations with overlapping entities")
arg_parser.add_argument('--no_partial_overlapping', action='store_true', default=False,
help="If true, do not evaluate on overlapping entities "
"and relations with overlapping entities")
arg_parser.add_argument('--no_duplicate', action='store_true', default=False,
help="If true, do not evaluate on overlapping entities "
"and relations with overlapping entities")
arg_parser.add_argument('--cls_threshold', type=float, default=0.5)
arg_parser.add_argument('--boundary_threshold', type=float, default=0.5)
arg_parser.add_argument('--use_msf', action="store_true",
help="Use multi-scale feature in decoder or use token-level sentence encoding")
arg_parser.add_argument('--use_topk_query', action="store_true",
help="Use top-k query or use query embedding, take effect if fpn_type is not None")
arg_parser.add_argument('--fpn_layer', type=int, default=16, help="")
arg_parser.add_argument("--fpn_type", type=str, default=None,
choices=[None, "uni-lstm", "bi-lstm", "uni", "bi", "uni-attn", "bi-attn"])
arg_parser.add_argument('--num_dec_layer', type=int, default=3, help="")
arg_parser.add_argument('--entity_queries_num', type=int, default=60)
arg_parser.add_argument('--pos_size', type=int, default=25)
arg_parser.add_argument('--char_lstm_layers', type=int, default=1)
arg_parser.add_argument('--char_size', type=int, default=25)
arg_parser.add_argument('--char_lstm_drop', type=float, default=0.2)
arg_parser.add_argument('--lstm_drop', type=float, default=0.1)
arg_parser.add_argument('--use_glove', action='store_true', default=False)
arg_parser.add_argument('--use_pos', action='store_true', default=False)
arg_parser.add_argument('--use_char_lstm', action='store_true', default=False)
arg_parser.add_argument('--use_lstm', action='store_true', default=False)
arg_parser.add_argument('--pool_type', type=str, default="max")
arg_parser.add_argument('--wordvec_path', type=str)
arg_parser.add_argument('--use_aux_loss', action='store_true', default=False)
arg_parser.add_argument('--split_epoch', type=int, default=0, help="")
# Misc
arg_parser.add_argument('--seed', type=int, default=-1, help="Seed")
arg_parser.add_argument('--cache_path', type=str, default=None,
help="Path to cache transformer models (for HuggingFace transformers library)")
def train_argparser():
arg_parser = argparse.ArgumentParser()
# Input
arg_parser.add_argument('--train_path', type=str, help="Path to train dataset")
arg_parser.add_argument('--valid_path', type=str, help="Path to validation dataset")
# Logging
arg_parser.add_argument('--save_path', type=str, help="Path to directory where model checkpoints are stored")
arg_parser.add_argument('--init_eval', action='store_true', default=False,
help="If true, evaluate validation set before training")
arg_parser.add_argument('--save_optimizer', action='store_true', default=False,
help="Save optimizer alongside model")
arg_parser.add_argument('--train_log_iter', type=int, default=1, help="Log training process every x iterations")
arg_parser.add_argument('--final_eval', action='store_true', default=False,
help="Evaluate the model only after training, not at every epoch")
# Model / Training
arg_parser.add_argument('--train_batch_size', type=int, default=2, help="Training batch size")
arg_parser.add_argument('--epochs', type=int, default=20, help="Number of epochs")
arg_parser.add_argument('--lr', type=float, default=5e-5, help="Learning rate")
arg_parser.add_argument('--lr_warmup', type=float, default=0.1,
help="Proportion of total train iterations to warmup in linear increase/decrease schedule")
arg_parser.add_argument('--weight_decay', type=float, default=0.01, help="Weight decay to apply")
arg_parser.add_argument('--max_grad_norm', type=float, default=1.0, help="Maximum gradient norm")
arg_parser.add_argument('--match_solver', type=str, help="", default="hungarian")
arg_parser.add_argument('--type_loss', type=str, help="", default="celoss")
arg_parser.add_argument('--match_warmup_epoch', type=int, help="", default=0)
arg_parser.add_argument('--nil_weight', type=float, default=-1)
arg_parser.add_argument('--match_boundary_weight', type=float, default=10.0)
arg_parser.add_argument('--match_class_weight', type=float, default=2.0)
arg_parser.add_argument('--loss_boundary_weight', type=float, default=2.0)
arg_parser.add_argument('--loss_class_weight', type=float, default=2.0)
arg_parser.add_argument('--deeply_weight', type=str, help="", default="same")
arg_parser.add_argument('--copy_weight', action='store_true', default=False)
_add_common_args(arg_parser)
return arg_parser
def eval_argparser():
arg_parser = argparse.ArgumentParser()
# Input
arg_parser.add_argument('--dataset_path', type=str, help="Path to dataset")
_add_common_args(arg_parser)
return arg_parser