cross_entropy = cross_entropy.data.cpu().numpy() kld = kld.data.cpu().numpy() print('\n') print('------------VALID-------------') print('--------CROSS-ENTROPY---------') print(cross_entropy) print('-------------KLD--------------') print(kld) print('------------------------------') ce_result += [cross_entropy] kld_result += [kld] if iteration % 20 == 0: seed = np.random.normal(size=[1, parameters.latent_variable_size]) sample = rvae.sample(batch_loader, 50, seed, args.use_cuda) print('\n') print('------------SAMPLE------------') print('------------------------------') print(sample) print('------------------------------') t.save(rvae.state_dict(), 'trained_RVAE') np.save('ce_result_{}.npy'.format(args.ce_result), np.array(ce_result)) np.save('kld_result_npy_{}'.format(args.kld_result), np.array(kld_result))
print('dropout = ', args.dropout) for i in range(3): target_sentence, predicted_sentence = validation_sample( args.use_cuda) print(' target : ', target_sentence) print('sample : ', predicted_sentence) print('------------------------------') ce_result += [cross_entropy] kld_result += [kld] # generate sample if iteration % 300 == 0: source = 'she should control the speed of her car' result = rvae.conditioned_sample(source, batch_loader, args) print('\n') print('------------SAMPLE------------') print('------------------------------') print('source : ', source) print('sample : ', result) print('------------------------------') # save model if iteration % 1000 == 0 or iteration == (args.num_iterations - 1): t.save(rvae.state_dict(), 'saved_models/trained_RVAE_' + args.model_name) np.save('saved_models/ce_result_{}.npy'.format(args.model_name), np.array(ce_result)) np.save('saved_models/kld_result_npy_{}'.format(args.model_name), np.array(kld_result))
print('-------------KLD--------------') print(kld) print('------------------------------') ce_result += [cross_entropy] kld_result += [kld] if iteration % 20 == 0: seed = np.random.normal(size=[1, parameters.latent_variable_size]) sample = rvae.sample(batch_loader, 50, seed, args.use_cuda) print('\n') print('------------SAMPLE------------') print('------------------------------') print(sample) print('------------------------------') if iteration % 25000 == 0: t.save( rvae.state_dict(), './trained_model/{}_trained_{}'.format(args.train_data, iteration)) t.save( optimizer.state_dict(), './trained_model/{}_trained_optimizer_{}'.format( args.train_data, iteration)) # np.save('ce_result_{}.npy'.format(args.ce_result), np.array(ce_result)) # np.save('kld_result_npy_{}'.format(args.kld_result), np.array(kld_result))
print('------------SAMPLE------------') print('------------------------------') print(f'original: {sentence.encode("utf-8")}') print(f'reference: {reference.encode("utf-8")}') print(f'generated: {result.encode("utf-8")}') print('------------------------------') bar.finish() if iteration % 10 == 0: print('\n') print('------------TRAIN-------------') print('----------ITERATION-----------') print(iteration) print('--------CROSS-ENTROPY---------') print(cross_entropy.data.cpu().numpy()) print('-------------KLD--------------') print(kld.data.cpu().numpy()) print('-----------KLD-coef-----------') print(coef) print('------------------------------') print("--------------------saving checkpoint-----------------------") t.save(rvae.state_dict(), 'trained_RVAE_checkpoint_para_out') print("--------------------saved checkpoint-----------------------") print("\n\n\n") t.save(rvae.state_dict(), 'trained_RVAE') np.save('ce_result_{}.npy'.format(args.ce_result), np.array(ce_result)) np.save('kld_result_npy_{}'.format(args.kld_result), np.array(kld_result))