def main(args):
json.dump(vars(args), open(os.path.join(args.output_dir, '<STR_LIT>'), '<STR_LIT:w>'))<EOL>if args.gpu_id == -<NUM_LIT:1>:<EOL><INDENT>ctx = mx.cpu()<EOL><DEDENT>else:<EOL><INDENT>ctx = mx.gpu(args.gpu_id)<EOL><DEDENT>mx.random.seed(args.seed, ctx=ctx)<EOL>if args.mode == '<STR_LIT:train>':<EOL><INDENT>train_dataset = read_dataset(args, '<STR_LIT>')<EOL>val_dataset = read_dataset(args, '<STR_LIT>')<EOL>vocab_path = os.path.join(args.output_dir, '<STR_LIT>')<EOL>if os.path.exists(vocab_path):<EOL><INDENT>vocab = nlp.Vocab.from_json(open(vocab_path).read())<EOL><DEDENT>else:<EOL><INDENT>vocab = build_vocab(train_dataset)<EOL>with open(vocab_path, '<STR_LIT:w>') as fout:<EOL><INDENT>fout.write(vocab.to_json())<EOL><DEDENT><DEDENT>glove = nlp.embedding.create(args.embedding, source=args.embedding_source)<EOL>vocab.set_embedding(glove)<EOL>train_data_loader = prepare_data_loader(args, train_dataset, vocab)<EOL>val_data_loader = prepare_data_loader(args, val_dataset, vocab, test=True)<EOL>model = NLIModel(len(vocab), args.embedding_size, args.hidden_size,<EOL>args.dropout, args.intra_attention)<EOL>train_model(model, train_data_loader, val_data_loader, vocab.embedding, ctx, args)<EOL><DEDENT>elif args.mode == '<STR_LIT:test>':<EOL><INDENT>model_args = argparse.Namespace(**json.load(<EOL>open(os.path.join(args.model_dir, '<STR_LIT>'))))<EOL>vocab = nlp.Vocab.from_json(<EOL>open(os.path.join(args.model_dir, '<STR_LIT>')).read())<EOL>val_dataset = read_dataset(args, '<STR_LIT>')<EOL>val_data_loader = prepare_data_loader(args, val_dataset, vocab, test=True)<EOL>model = NLIModel(len(vocab), model_args.embedding_size,<EOL>model_args.hidden_size, <NUM_LIT:0.>, model_args.intra_attention)<EOL>model.load_parameters(os.path.join(<EOL>args.model_dir, '<STR_LIT>', '<STR_LIT>'), ctx=ctx)<EOL>loss_func = gluon.loss.SoftmaxCrossEntropyLoss()<EOL>logger.info('<STR_LIT>'.format(args.test_file))<EOL>loss, acc = test_model(model, val_data_loader, loss_func, ctx)<EOL>logger.info('<STR_LIT>'.format(loss, acc))<EOL><DEDENT>
Entry point: train or test.