# Get arguments print('Getting arguments...') args = get_args() # make a dataset print('Importing dataset...') data = SentimentDataset(data=args.train_path) # preprocess and save word encodings preprocessor = Preprocessor(max_vocab=args.max_vocab) data = preprocessor.fit_transform(dataset=data) preprocessor.save(args.prepro_save_path) # validation split data.split_data(validation_count=args.validation_count) train_ds, val_ds = data.to_dataset() # to dataLoaders train_set = DataLoader(train_ds, batch_size=args.batch_size, shuffle=True) val_set = DataLoader(val_ds, batch_size=args.batch_size, shuffle=False) print('Initializing model...') mod = SentimentModel( len(preprocessor.vocab2enc) + 3, args.embedding_dim, args.hidden_dim) opt = Adam(mod.parameters(), lr=args.lr) print('Training...') fit(training=train_set, model=mod, validation=val_set, optimizer=opt,
return parser.parse_args() if __name__ == '__main__': # Get arguments print('Getting arguments...') args = get_args() # make a dataset print('Importing dataset...') data = SentimentDataset(data=args.test_path) # preprocess and save word encodings preprocessor = Preprocessor(max_vocab=args.max_vocab) preprocessor.load() data = preprocessor.transform(dataset=data) # validation split test_ds, _ = data.to_dataset() # to dataLoaders test_set = DataLoader(test_ds, batch_size=16, shuffle=False) # load saved model print('Loading trained model...') model = torch.load(args.model_path) model.eval() test(test_set, model, val=False)