Esempio n. 1
0
    synth = RNN.synthesize(make_one_hot([char_to_ind['.']], K), 1000)
    text = ""
    for column in synth.T:
        text += ind_to_char[np.argmax(column)]
    print(text.encode('ascii', 'ignore').decode('ascii'))
    exit()

    losses = []
    f = open(
        'synthesized-' + str(
            datetime.datetime.fromtimestamp(
                time.time()).strftime('%Y-%m-%d %H:%M:%S')), 'w+')
    for epoch in range(n_epoch):
        print("\t\t---NEW EPOCH--- number: %d" % (epoch + last_epoch))
        RNN.h0 = np.zeros((m, 1))
        for X_seq, Y_seq in get_batch():
            step += 1
            loss = RNN.train(X_seq, Y_seq)
            smooth_loss = 0.999 * smooth_loss + 0.001 * loss if smooth_loss != -1 else loss
            losses.append(smooth_loss)

            if step % 500 == 0:
                f.write(
                    '\n\tSynthesized text at iteration: %d with smooth loss: %f\n'
                    % (step, smooth_loss))
                text = synthesize(X_seq)
                f.write(text.encode('ascii', 'ignore').decode('ascii'))
                f.write('\n')
                f.flush()
            elif step % 100 == 0: