def inference(): thandler = trainer.handler(args.process_command()) rt_data = rt() data = trainer.load_data(rt_data.data, data_type=rt_data.data_type) test_loader = data model_ = models.MLP(300, classes=2) #print(model_) total = sum(p.numel() for p in model_.parameters() if p.requires_grad) print('# of para: {}'.format(total)) model_name = 'MLP.pt' predicted = thandler.predict(model_, test_loader, model_name) print([np.argmax(np.array(i)) for i in predicted])
train_x = torch.LongTensor(self.process(train_x)) dev_x = torch.LongTensor(self.process(dev_x)) test_x = torch.LongTensor(self.process(test_x)) print(train_x.shape) print(dev_x.shape) print(test_x.shape) return (train_x, torch.LongTensor(train_y)), ( dev_x, torch.LongTensor(dev_y)), (test_x, torch.LongTensor(test_y)) if __name__ == '__main__': rt = rt() handler = trainer.handler() #data preprocess training, valid, testing = rt.simple_data() train_loader = handler.torch_data(training) valid_loader = handler.torch_data(valid) test_loader = handler.torch_data(testing) import model trial = handler.trial scores = [] for i in range(trial): #setting model_ = model.BertCls(BertModel, rt.weight, handler.trainable) model_name = 'model_' + str(i) + '.pt' model_path = handler.save + model_name
import args import rt_data as rt import sys import torch import torch_model as models import training_handler import util from tensorflow import keras from sklearn.svm import SVC from sklearn.metrics import accuracy_score thandler = training_handler.handler(args.process_command()) def RUN_SVC(data): print('SVC') (train_data, train_labels), (test_data, test_labels) = data clf = SVC(C=0.1, gamma='auto') clf.fit(util.padding(train_data), train_labels) y_pred = clf.predict(util.padding(test_data)) print('Accuracy: {}'.format(accuracy_score(test_labels, y_pred))) def data_loader(data_, data_type=[torch.LongTensor, torch.LongTensor]): (train_data, train_labels), (test_data, test_labels) = data_ train_size = int(len(train_data) * 0.1) valid_data = train_data[:train_size]