from dataHandler import DataHandler from boW import EOS_token RSEED = 50 SIZE = 10 NCLASS = 3 TFIDF = False NORMALIZE = False np.random.seed(RSEED) d = DataHandler() d.createDictionary() #prepare data data = d.readDataPreproc(pre=True)[1:] x = [d.askDictionary.seq2tensor(xi[1], tfidf=TFIDF) for xi in data] x = np.array(x) if NORMALIZE: x = preprocessing.normalize(x) if NCLASS == 3: y = [ 0 if yi[2] == "alegria" else 1 if yi[2] == "neutro" else 2 for yi in data ] else: y = [0 if yi[2] == "alegria" else 1 for yi in data] y = np.array(y)
output_sentence = ' '.join(output_words) print('<', output_sentence) print('') def evaluateAndShowAttention(self, input_sentence): output_words, attentions = self.evaluate(input_sentence) print('input =', input_sentence) print('output =', ' '.join(output_words)) showAttention(input_sentence, output_words, attentions) if __name__ == '__main__': d = DataHandler() d.createDictionary() pairs = d.readDataPreproc() s = Seq2Seq(d.askDictionary, d.ansDictionary) if isfile(PATH): s = torch.load(PATH) showPlot(s.plot_losses, title="Loss", axis=["Milhares de iterações", "loss"]) else: s.trainIters(pairs, 10000, print_every=5000) torch.save(s.state_dict(), "disc_" + PATH) torch.save(s, PATH) s.evaluateRandomly(pairs)