def main(): dataloader = IMDB() model = VRAE(dataloader.word2idx, dataloader.idx2word) sess = tf.Session() sess.run(tf.global_variables_initializer()) for epoch in range(args.num_epoch): dataloader.update_word_dropout() print("\nWord Dropout") dataloader.shuffle() print("Data Shuffled", end='\n\n') for i, (enc_inp, dec_inp, dec_out) in enumerate(dataloader.next_batch()): log = model.train_session(sess, enc_inp, dec_inp, dec_out) if i % args.display_loss_step == 0: print("Step %d | [%d/%d] | [%d/%d]" % (log['step'], epoch+1, args.num_epoch, i, len(dataloader.enc_inp)//args.batch_size), end='') print(" | nll_loss:%.1f | kl_w:%.3f | kl_loss:%.2f \n" % (log['nll_loss'], log['kl_w'], log['kl_loss'])) model.reconstruct(sess, enc_inp[-1], dec_inp[-1]) #model.generate(sess) model.customized_reconstruct(sess, 'i love this film and i think it is one of the best films') model.customized_reconstruct(sess, 'this movie is a waste of time and there is no point to watch it') save_path = model.saver.save(sess, model.model_path) print("Model saved in file: %s" % save_path)
def main(): dataloader = IMDB() model = VRAE(dataloader.word2idx) sess = tf.Session() sess.run(tf.global_variables_initializer()) print("Loading trained model ...") model.saver.restore(sess, model.model_path) # lowercase, no punctuation, please model.customized_reconstruct(sess, 'i love this firm it is one of the best') model.customized_reconstruct( sess, 'i want to see this movie it seems interesting')
def main(): dataloader = IMDB() params = { 'vocab_size': len(dataloader.word2idx), 'word2idx': dataloader.word2idx, 'idx2word': dataloader.idx2word, } print('Vocab Size:', params['vocab_size']) model = VRAE(params) saver = tf.train.Saver() config = tf.ConfigProto(allow_soft_placement=True) config.gpu_options.allow_growth = True sess = tf.Session(config=config) sess.run(tf.global_variables_initializer()) for epoch in range(args.num_epoch): dataloader.update_word_dropout() print("\nWord Dropout") dataloader.shuffle() print("Data Shuffled", end='\n\n') for i, (enc_inp, dec_inp, dec_out) in enumerate(dataloader.next_batch()): log = model.train_session(sess, enc_inp, dec_inp, dec_out) if i % args.display_loss_step == 0: print("Step %d | [%d/%d] | [%d/%d]" % (log['step'], epoch + 1, args.num_epoch, i, len(dataloader.enc_inp) // args.batch_size), end='') print(" | nll_loss:%.1f | kl_w:%.3f | kl_loss:%.2f \n" % (log['nll_loss'], log['kl_w'], log['kl_loss'])) model.generate(sess) model.reconstruct(sess, enc_inp[-1], dec_inp[-1]) model.customized_reconstruct( sess, 'i love this film and i think it is one of the best films') model.customized_reconstruct( sess, 'this movie is a waste of time and there is no point to watch it') save_path = saver.save(sess, './saved/vrae.ckpt') print("Model saved in file: %s" % save_path)
def main(): dataloader = IMDB() model = VRAE(dataloader.word2idx, dataloader.idx2word) sess = tf.Session() sess.run(tf.global_variables_initializer()) print("Loading trained model ...") model.saver.restore(sess, model.model_path) # lowercase, no punctuation, please model.customized_reconstruct(sess, 'i love this firm and it is beyond my expectation') model.customized_reconstruct(sess, 'i want to watch this movie again because it is so interesting') model.customized_reconstruct(sess, 'the time taken to develop the characters is quite long') model.customized_reconstruct(sess, 'is there any point to make a bad movie like this') model.customized_reconstruct(sess, 'sorry but there is no point to watch this movie again') model.customized_reconstruct(sess, 'to be honest this movie is not worth my time and money')