Exemplo n.º 1
0
        current_batch_input.append(batch_input)
        current_batch_output.append(batch_output)

        read_sequences_count += 1
        # It is possible we don't complete a batch. In that case, this if won't execute and the result won't be added.
        if read_sequences_count == batch_size:
            result.append([ current_batch_input, current_batch_output ])
            current_batch_input = []
            current_batch_output = []
            read_sequences_count = 0
    
    return np.array(result)

#########################################################################

tf.logging.set_verbosity(tf.logging.ERROR)

text_processor = TextProcessor(data_dir, data_percentage)
text = text_processor.load_and_preprocess_text()

print('Creating computation graph...')
nn = NeuralNetwork()

summary_output_dir = '/output/e{}_b{}_rnn{}_rnnl{}_seq{}_lr{}_dp{}'.format(num_epochs, batch_size, rnn_size, rnn_layer_count, seq_length, learning_rate, data_percentage)
nn.build_model(text_processor.int_to_vocab, rnn_size, rnn_layer_count, summary_output_dir)
print('Computation graph created.')

print('Training...')
batches = get_batches(text_processor.int_text, batch_size, seq_length)
nn.train_model(batches, num_epochs, learning_rate, save_every, save_dir, test_every, prime_word, gen_length, text_processor, seq_length)