def __init__(self): self.path_train = config.path_train self.path_test = config.path_test self.path_dev = config.path_dev custom_vocab = vocab.create_vocab() custom_vocab.set_data(mode=config.all_mode) self.vocab_list = custom_vocab.vocab_list self.word_to_index = custom_vocab.word_to_index self.index_to_word = custom_vocab.index_to_word self.stop_words = stopwords.words('english') self.labels = config.labels self.label_to_index = { self.labels[0]: 0, self.labels[1]: 1, self.labels[2]: 2 }
def __init__(self): path = "./train_data.csv" vocab = v.create_vocab(path_csv=path) word_to_index = vocab.get_data() self.dataset = c.Custom_dataset(word_to_index, path) self.model = torch.load("./model.pth")
label = Variable(label.to(device)) sent = Variable(torch.stack(sent).to(device)) out = model(sent) _, pred = torch.max(out.data, 1) total += label.size(0) # batch size correct += (pred == label).sum() acc = 100 * (correct.cpu().numpy() / total) return acc if __name__ == "__main__": path_csv = config.path_csv # 데이터 처리 start = time.time() vocab = v.create_vocab(path_csv=path_csv) word_to_index = vocab.get_data() print("time vocab load : ", time.time() - start) start = time.time() dataset = custom_dataset.Custom_dataset(word_to_index, path_csv=path_csv) train_data = dataset.get_data() print("데이터 준비 완료") print("time data load : ", time.time() - start) print(len(train_data)) train_loader = DataLoader( train_data, batch_size=config.batch, shuffle=True,
label = Variable(label.to(device)) sent1 = Variable(torch.stack(sent1).to(device)) sent2 = Variable(torch.stack(sent2).to(device)) out = model(sent1, sent2) _, pred = torch.max(out.data, 1) total += label.size(0) # batch size correct += (pred == label).sum() acc = 100 * (correct.cpu().numpy() / total) return acc if __name__ == "__main__": # 데이터 처리 start = time.time() vocab = v.create_vocab(mode=config.vocab_mode) vocab_list, word_to_index = vocab.get_data() print("time vocab load : ", time.time() - start) start = time.time() glove = custom_glove() embedding = glove.get_data(vocab_list) print("time glove emb load : ", time.time() - start) start = time.time() dataset = custom_dataset.Custom_dataset(vocab_list, word_to_index) train_data, test_data, dev_data = dataset.get_data() print("time data load : ", time.time() - start) train_loader = DataLoader(train_data, batch_size=config.batch,