def load(self, epoch_num): load_path = self.get_path(epoch_num) self.language_model = torch_utils.load_model(load_path).cuda() self.init_trainer() # Need to reset optimizer
config['beam_size'] = 5 config['log_path'] = 'logs.txt' config['save_directory'] = 'logs/squad_saved_data' config['use_pretrained_embeddings'] = True config['pretrained_embeddings_path'] = 'datasets/squad/word_embeddings.npy' config['finetune_embeddings'] = False config['load_model'] = False config['gpu_mode'] = True config[ 'load_path'] = 'logs/squad_saved_data/model_6.pyt7' # CHANGE THIS TO WHATEVER PATH YOU WANT io_utils.check_dir('logs/squad_saved_data') language_model = LanguageModel(config) if config['load_model']: language_model = torch_utils.load_model(config['load_path']) language_model.cuda() language_wrapper = LanguageWrapper(language_model, language_model_loader.get_vocab()) language_trainer = LanguageTrainer(config, language_wrapper, language_model_loader) for i in range(0, 15): loss, accuracy, predictions = language_trainer.train(epoch_num=i) if i % 3 == 2: predictions = language_trainer.predict( dataset_type=constants.DATASET_TEST, epoch_num=10, max_length=20,
from data_loaders.language_model_loader_truncate import LanguageModelLoaderTruncate from models.language_model import LanguageModel from models.language_trainer import LanguageTrainer from models.language_wrapper import LanguageWrapper from helpers import constants import torch from helpers import torch_utils, utils from torch.autograd import variable dataset_path = 'datasets/newsqa' load_path = 'logs/squad_saved_data_truncated/model_2.pyt7' language_model_loader = LanguageModelLoaderTruncate( dataset_path, tokenizer_type=constants.TOKENIZER_TAB) language_model = torch_utils.load_model(load_path).cuda() language_model.config['save_directory'] = 'logs/newsqa_saved_data' language_wrapper = LanguageWrapper(language_model, language_model_loader.get_vocab()) language_trainer = LanguageTrainer(language_model.config, language_wrapper, language_model_loader) #test_predictions = language_trainer.predict(dataset_type=constants.DATASET_TEST, # epoch_num=10, max_length=20) #dev_predictions = language_trainer.predict(dataset_type=constants.DATASET_VALIDATION, # epoch_num=10, max_length=10) train_predictions = language_trainer.predict( dataset_type=constants.DATASET_TRAIN, epoch_num=10, max_length=10) utils.save_lines( train_predictions,
from models.language_model import LanguageModel from helpers import torch_utils config = {} config['vocab_size'] = 12 config['embedding_size'] = 20 config['hidden_size'] = 50 config['num_layers'] = 1 config['dropout'] = 0.0 config['batch_first'] = True model = LanguageModel(config) torch_utils.save_model(model, path='test.model') model = torch_utils.load_model(path='test.model')