Move command-line argparse arguments into main() function

This commit is contained in:
Tim Rault
2018-11-02 14:42:05 +01:00
parent c9690e57f8
commit 3ff2ec5eb3
3 changed files with 218 additions and 213 deletions

View File

@@ -37,94 +37,6 @@ logging.basicConfig(format = '%(asctime)s - %(levelname)s - %(name)s - %(messa
level = logging.INFO)
logger = logging.getLogger(__name__)
parser = argparse.ArgumentParser()
## Required parameters
parser.add_argument("--data_dir",
default = None,
type = str,
required = True,
help = "The input data dir. Should contain the .tsv files (or other data files) for the task.")
parser.add_argument("--bert_config_file",
default = None,
type = str,
required = True,
help = "The config json file corresponding to the pre-trained BERT model. \n"
"This specifies the model architecture.")
parser.add_argument("--task_name",
default = None,
type = str,
required = True,
help = "The name of the task to train.")
parser.add_argument("--vocab_file",
default = None,
type = str,
required = True,
help = "The vocabulary file that the BERT model was trained on.")
parser.add_argument("--output_dir",
default = None,
type = str,
required = True,
help = "The output directory where the model checkpoints will be written.")
## Other parameters
parser.add_argument("--init_checkpoint",
default = None,
type = str,
help = "Initial checkpoint (usually from a pre-trained BERT model).")
parser.add_argument("--do_lower_case",
default = False,
action='store_true',
help = "Whether to lower case the input text. Should be True for uncased models and False for cased models.")
parser.add_argument("--max_seq_length",
default = 128,
type = int,
help = "The maximum total input sequence length after WordPiece tokenization. \n"
"Sequences longer than this will be truncated, and sequences shorter \n"
"than this will be padded.")
parser.add_argument("--do_train",
default = False,
action='store_true',
help = "Whether to run training.")
parser.add_argument("--do_eval",
default = False,
action='store_true',
help = "Whether to run eval on the dev set.")
parser.add_argument("--train_batch_size",
default = 32,
type = int,
help = "Total batch size for training.")
parser.add_argument("--eval_batch_size",
default = 8,
type = int,
help = "Total batch size for eval.")
parser.add_argument("--learning_rate",
default = 5e-5,
type = float,
help = "The initial learning rate for Adam.")
parser.add_argument("--num_train_epochs",
default = 3.0,
type = float,
help = "Total number of training epochs to perform.")
parser.add_argument("--warmup_proportion",
default = 0.1,
type = float,
help = "Proportion of training to perform linear learning rate warmup for. "
"E.g., 0.1 = 10%% of training.")
parser.add_argument("--save_checkpoints_steps",
default = 1000,
type = int,
help = "How often to save the model checkpoint.")
parser.add_argument("--no_cuda",
default = False,
action='store_true',
help = "Whether not to use CUDA when available")
parser.add_argument("--local_rank",
type=int,
default=-1,
help = "local_rank for distributed training on gpus")
args = parser.parse_args()
class InputExample(object):
"""A single training/test example for simple sequence classification."""
@@ -428,6 +340,95 @@ def accuracy(out, labels):
return np.sum(outputs==labels)
def main():
parser = argparse.ArgumentParser()
## Required parameters
parser.add_argument("--data_dir",
default=None,
type=str,
required=True,
help="The input data dir. Should contain the .tsv files (or other data files) for the task.")
parser.add_argument("--bert_config_file",
default=None,
type=str,
required=True,
help="The config json file corresponding to the pre-trained BERT model. \n"
"This specifies the model architecture.")
parser.add_argument("--task_name",
default=None,
type=str,
required=True,
help="The name of the task to train.")
parser.add_argument("--vocab_file",
default=None,
type=str,
required=True,
help="The vocabulary file that the BERT model was trained on.")
parser.add_argument("--output_dir",
default=None,
type=str,
required=True,
help="The output directory where the model checkpoints will be written.")
## Other parameters
parser.add_argument("--init_checkpoint",
default=None,
type=str,
help="Initial checkpoint (usually from a pre-trained BERT model).")
parser.add_argument("--do_lower_case",
default=False,
action='store_true',
help="Whether to lower case the input text. Should be True for uncased models and False for cased models.")
parser.add_argument("--max_seq_length",
default=128,
type=int,
help="The maximum total input sequence length after WordPiece tokenization. \n"
"Sequences longer than this will be truncated, and sequences shorter \n"
"than this will be padded.")
parser.add_argument("--do_train",
default=False,
action='store_true',
help="Whether to run training.")
parser.add_argument("--do_eval",
default=False,
action='store_true',
help="Whether to run eval on the dev set.")
parser.add_argument("--train_batch_size",
default=32,
type=int,
help="Total batch size for training.")
parser.add_argument("--eval_batch_size",
default=8,
type=int,
help="Total batch size for eval.")
parser.add_argument("--learning_rate",
default=5e-5,
type=float,
help="The initial learning rate for Adam.")
parser.add_argument("--num_train_epochs",
default=3.0,
type=float,
help="Total number of training epochs to perform.")
parser.add_argument("--warmup_proportion",
default=0.1,
type=float,
help="Proportion of training to perform linear learning rate warmup for. "
"E.g., 0.1 = 10%% of training.")
parser.add_argument("--save_checkpoints_steps",
default=1000,
type=int,
help="How often to save the model checkpoint.")
parser.add_argument("--no_cuda",
default=False,
action='store_true',
help="Whether not to use CUDA when available")
parser.add_argument("--local_rank",
type=int,
default=-1,
help="local_rank for distributed training on gpus")
args = parser.parse_args()
processors = {
"cola": ColaProcessor,
"mnli": MnliProcessor,