Ejemplo n.º 1
0
"""
    Read the corpus and get unique characters from the corpus.
"""
text = helper.read_corpus(PATH_TO_CORPUS)
chars = helper.extract_characters(text)
"""
    Create sequences that will be used as the input to the network.
    Create next_chars array that will serve as the labels during the training.
"""
sequences, next_chars = helper.create_sequences(text, SEQUENCE_LENGTH,
                                                SEQUENCE_STEP)
char_to_index, indices_char = helper.get_chars_index_dicts(chars)
"""
    The network is not able to work with characters and strings, we need to vectorise.
"""
X, y = helper.vectorize(sequences, SEQUENCE_LENGTH, chars, char_to_index,
                        next_chars)
"""
    Define the structure of the model.
"""
model = helper.build_model(SEQUENCE_LENGTH, chars)
"""
    Train the model
"""

# model.fit(X, y, batch_size=128, nb_epoch=EPOCHS)
model = load_model(
    "final.h5")  # you can skip training by loading the trained weights

for diversity in [0.2, 0.5, 1.0, 1.2]:
    print()
    print('----- diversity:', diversity)
Ejemplo n.º 2
0
"""
text = helper.read_corpus(PATH_TO_CORPUS)
words = text.split()
unique_words = helper.extract_characters(words)
"""
    Create sequences that will be used as the input to the network.
    Create next_chars array that will serve as the labels during the training.
"""
word_sequences, next_words = helper.create_word_sequences(
    words, WORD_SEQUENCE_LENGTH, WORD_SEQUENCE_STEP)
word_to_index, indices_word = helper.get_chars_index_dicts(unique_words)

# """
#     The network is not able to work with characters and strings, we need to vectorise.
# """
X, y = helper.vectorize(word_sequences, WORD_SEQUENCE_LENGTH, unique_words,
                        word_to_index, next_words)

# """
#     Define the structure of the model.
# """
model = helper.build_model(WORD_SEQUENCE_LENGTH, unique_words)

# """
#     Train the model
# """

model.fit(X, y, batch_size=128, nb_epoch=EPOCHS)
# model = load_model("final.h5")  # you can skip training by loading the trained weights

for diversity in [0.2, 0.5, 1.0, 1.2]:
    print()