Exemplo n.º 1
0
            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))
Exemplo n.º 2
0
                        metavar='MN',
                        help='name of model to save (default: '
                        ')')
    args = parser.parse_args()

    assert os.path.exists('saved_models/trained_RVAE_' + args.model_name), \
        'trained model not found'

    batch_loader = BatchLoader('')
    parameters = Parameters(batch_loader.max_word_len,
                            batch_loader.max_seq_len,
                            batch_loader.words_vocab_size,
                            batch_loader.chars_vocab_size)
    rvae = RVAE(parameters)
    rvae.load_state_dict(t.load('saved_models/trained_RVAE_' +
                                args.model_name))
    if args.use_cuda:
        rvae = rvae.cuda()

    with open(args.input_file) as f:
        source_phrases = f.readlines()
    source_phrases = [x.strip() for x in source_phrases]

    for input_phrase in source_phrases:
        # embed
        print('input: ', input_phrase)
        print('sampled: ')
        for iteration in range(args.num_sample):
            print(rvae.conditioned_sample(input_phrase, batch_loader, args))
            print()