top_param=3) top_rank_5 = model.top_rank_accuracy(prediction, validation_dataset, top_param=5) loss = model.loss_fn(prediction, outputs) print(f"Validation Loss : {loss.data[0]}") return loss.data[0], top_rank_1, top_rank_3, top_rank_5 if __name__ == "__main__": use_cuda = torch.cuda.is_available() dataset = SimpleDataset( training_file="IR_train_hard.json", preprocessing=False, preprocessed_data_filename="hard_training_unprocessed") validation_dataset = SimpleDataset( training_file="IR_val_hard.json", preprocessing=False, preprocessed_data_filename="hard_val_unprocessed") model, top_rank_1_arr, \ top_rank_3_arr, top_rank_5_arr = train_cbow_reg_network( dataset, validation_dataset, num_epochs=30, batch_size=256, embedding_space=300, hidden_layer_dim=256,
save_model(f"{modelname}_Easy", hidden_layer_dim, embedding_space, learning_rate, loss_fn_name, model) return top_rank_1_arr[-1], top_rank_3_arr[-1], top_rank_5_arr[-1] else: loss, top_rank_1, \ top_rank_3, top_rank_5 = validate_model(dataset.vocab_size, dataset.w2i, validation_dataset, model=model) return top_rank_1, top_rank_3, top_rank_5 if __name__ == '__main__': use_cuda = torch.cuda.is_available() easy_dataset = SimpleDataset( training_file="IR_train_easy.json", preprocessing=True, preprocessed_data_filename="easy_training_processed_with_questions") test_dataset = SimpleDataset( training_file="IR_test_easy.json", preprocessing=True, preprocessed_data_filename="easy_val_processed_with_questions") loss_fn = torch.nn.MSELoss(size_average=True) loss_fn = torch.nn.SmoothL1Loss(size_average=True) Embedding_Spaces = [100, 150, 200, 250, 300, 350] Hidden_Dims = [56, 256, 512, 1024] Learning_Rates = [0.001, 0.0001, 0.00001] best_top_1 = 0 best_top_params = []
top_rank_1 = model.top_rank_accuracy(prediction, outputs, top_param=1) top_rank_3 = model.top_rank_accuracy(prediction, outputs, top_param=3) top_rank_5 = model.top_rank_accuracy(prediction, outputs, top_param=5) loss = model.loss_fn(prediction, outputs) print(f"Validation Loss : {loss.data[0]}") return loss.data[0], top_rank_1, top_rank_3, top_rank_5 if __name__ == "__main__": use_cuda = torch.cuda.is_available() dataset = SimpleDataset( training_file="IR_train_easy.json", preprocessing=True, preprocessed_data_filename="easy_training_processed") validation_dataset = SimpleDataset( training_file="IR_val_easy.json", preprocessing=True, preprocessed_data_filename="easy_val_processed") model, top_rank_1_arr, \ top_rank_3_arr, top_rank_5_arr = train_cbow_network( dataset, validation_dataset, num_epochs=30, batch_size=64, embedding_space=150, hidden_layer_dim=256,
model.load_state_dict(torch.load(f"models/{model_hard_file}")) loss, top_rank_1, \ top_rank_3, top_rank_5 = validation_func(hard_dataset.vocab_size, hard_dataset.w2i, hard_testset, model=model) print("HARD RESULTS") print(top_rank_1) print(top_rank_3) print(top_rank_5) if __name__ == '__main__': easy_dataset = SimpleDataset( training_file="IR_train_easy.json", preprocessing=True, preprocessed_data_filename="easy_training_processed_with_questions" ) easy_dataset_cbow = SimpleDataset( training_file="IR_train_easy.json", preprocessing=True, preprocessed_data_filename="easy_training_unprocessed" # Saved to wrong file, didn't want to wait an hour to reprocess ) easy_test_dataset = SimpleDataset( training_file="IR_test_easy.json", preprocessing=True, preprocessed_data_filename="easy_test_processed_with_questions" )