sum(param.nelement() for param in nli_model.encoder.parameters() if param.requires_grad))) best_nli_dev_acc = 0 best_nli_train_acc = -np.infty # load trained model from checkpoint if len(sys.argv) > 1: checkpoint_dir = sys.argv[1] print('loading from checkpoint in {}'.format(checkpoint_dir)) model_pipeline_pytorch.load_checkpoint(nli_model, checkpoint=checkpoint_dir) nli_state['lr'] = 0.01 print('resetting lr as {}'.format(nli_state['lr'])) nli_model.embed.weight.data = load_embeddings.load_embeddings( nli_dm.vocab, constants.EMBED_DATA_PATH, nli_args.embedding_size) squad_model.embed.weight.data = load_embeddings.load_embeddings( squad_dm.vocab, constants.EMBED_DATA_PATH, nli_args.embedding_size) nli_criterion = nn.NLLLoss() squad_criterion = nn.NLLLoss() for epoch in range(NumEpochs): nli_dm.shuffle_train_data() squad_dm.shuffle_train_data() print('lr {}'.format(nli_state['lr'])) nli_optimizer = optim.SGD( [param for param in nli_model.parameters() if param.requires_grad], lr=nli_state['lr']) squad_optimizer = optim.SGD([
}) squad_state = {k: v for k, v in squad_args.items()} if __name__ == "__main__": print(args) checkpoint = sys.argv[1] print('found checkpoint dir {}'.format(checkpoint)) dm = wrangle.DataManager(args) if args.add_squad: # add squad to vocab to match checkpoint squad_dm = SquadDataManager(squad_args, vocab=dm.vocab) args.n_embed = dm.vocab.n_words if args.type == 'siamese': model = siamese_pytorch.SiameseClassifier(config=args) model.embed.weight.data = load_embeddings.load_embeddings( dm.vocab, constants.EMBED_DATA_PATH, args.embedding_size) elif args.type == 'decomposable': model = decomposable_pytorch.SNLIClassifier(config=args) model.encoder.embedding.weight.data = load_embeddings.load_embeddings( dm.vocab, constants.EMBED_DATA_PATH, args.embedding_size) else: model = Seq2SeqPytorch(args=args, vocab=dm.vocab) model.encoder.embedding.weight.data = load_embeddings.load_embeddings( dm.vocab, constants.EMBED_DATA_PATH, args.embedding_size) model_pipeline_pytorch.load_checkpoint(model, checkpoint=checkpoint) model.eval() if args.cuda: model = model.cuda()