def demo(): inputSentence = input("Enter your sentence: ") print("============" + p + "===================") print(type(p)) if config.GPU == True: ptrNet = PointerNetwork(config.HIDDEN_SIZE).cuda() else: ptrNet = PointerNetwork(config.HIDDEN_SIZE) evaluate(ptrNet, inputSentence)
def processSingle(path): if config.GPU == True: ptrNet = PointerNetwork(config.HIDDEN_SIZE).cuda() else: ptrNet = PointerNetwork(config.HIDDEN_SIZE) ptrNet.load_state_dict(torch.load(path)) nlp = spacy.load("en_core_web_sm") sentences = [ "this is definitely a difficult sentence", "your plan seems excellent", "it is really working", "let me start with a poem", "he is sure to pass the exam", "we meet every wednesday", "do plan to we it tomorrow", "i like working on brain", "development good is a this", "i am going to canada", "The script that I am describing here mainly for training and validation " ] if True: for origLine in sentences: print("") inputLine, outputLine = processSentence(nlp, ptrNet, origLine) print("Input Sentence: ", inputLine) print("Outpt Sentence: ", outputLine) print("Orig Sentence: ", origLine) else: lines = open("../data/englishSentences_test.dat").read().splitlines() for i in range(7): print("\n") origLine = random.choice(lines) inputLine, outputLine = processSentence(nlp, ptrNet, origLine) print("Input Sentence: ", inputLine) print("Outpt Sentence: ", outputLine) print("Orig Sentence: ", origLine)
def modelEvaluate(path): if config.GPU == True: ptrNet = PointerNetwork(config.HIDDEN_SIZE).cuda() else: ptrNet = PointerNetwork(config.HIDDEN_SIZE) ptrNet.load_state_dict(torch.load(path)) evaluateWordSort(ptrNet, 1)
def modelEvaluate(accuracyStats, path): if config.GPU == True: ptrNet = PointerNetwork(config.HIDDEN_SIZE).cuda() else: ptrNet = PointerNetwork(config.HIDDEN_SIZE) ptrNet.load_state_dict(torch.load(path)) for epoch in range(EPOCHS): evaluateWordSort(accuracyStats, ptrNet, 1) printAccStats(accuracyStats)
def modelEvaluate(accuracyStats, path): if config.GPU == True: ptrNet = PointerNetwork(config.HIDDEN_SIZE).cuda() else: ptrNet = PointerNetwork(config.HIDDEN_SIZE) ptrNet.load_state_dict(torch.load(path)) for sentenceLength in range(4, 11): print(sentenceLength) evaluateWordSort(accuracyStats, ptrNet, sentenceLength) printAccStats(accuracyStats)
def modelTrainAndSave(path): if config.GPU == True: ptrNet = PointerNetwork(config.HIDDEN_SIZE).cuda() else: ptrNet = PointerNetwork(config.HIDDEN_SIZE) optimizer = optim.Adam(ptrNet.parameters()) program_starts = time.time() for epoch in range(EPOCHS): train(ptrNet, optimizer, epoch + 1) evaluateWordSort(ptrNet, epoch + 1) torch.save(ptrNet.state_dict(), path) now = time.time() print("It has been {0} seconds since the loop started".format( now - program_starts))
for i in range(out.size(0)): print("=============================================") print( "yref", y_val[i], out[i], y_val[i] - out[i], ) xv = convertToWordSingle(x_val[i]) print("orig", xv) v = out[i].numpy() print("[", end="") for index in v: print(xv[index] + ", ", end="") print("]") ptrNet = PointerNetwork(config.HIDDEN_SIZE) optimizer = torch.optim.Adam(ptrNet.parameters()) program_starts = time.time() for epoch in range(EPOCHS): train(ptrNet, optimizer, epoch + 1) evaluateWordSort(ptrNet, epoch + 1) now = time.time() print("It has been {0} seconds since the loop started".format(now - program_starts))
out, _ = model(x_val, y_val, teacher_force_ratio=0.) out = out.permute(1, 0) for i in range(out.size(0)): print("=============================================") print("yref", y_val[i], out[i], y_val[i] - out[i]) print("orig", text_val[i]) v = torch.Tensor.cpu(out[i]).numpy() print("[", end="") for index in v: print(text_val[i][index] + " ", end="") print("]") if config.GPU == True: ptrNet = PointerNetwork(config.HIDDEN_SIZE).cuda() else: ptrNet = PointerNetwork(config.HIDDEN_SIZE) optimizer = optim.Adam(ptrNet.parameters()) program_starts = time.time() for epoch in range(EPOCHS): train(ptrNet, optimizer, epoch + 1) evaluateWordSort(ptrNet, epoch + 1) now = time.time() print("It has been {0} seconds since the loop started".format(now - program_starts))