(output_len, chars=None)
return model
Generate the model
Generate the model
Generate the model
def generate_model(output_len, chars=None):
    """Generate the model"""
    print('Build model...')
    chars = chars or CHARS
    model = Sequential()
    # "Encode" the input sequence using an RNN, producing an output of hidden_size
    # note: in a situation where your input sequences have a variable length,
    # use input_shape=(None, nb_feature).
    for layer_number in range(CONFIG.input_layers):
        model.add(recurrent.LSTM(CONFIG.hidden_size, input_shape=(None, len(chars)), kernel_initializer=CONFIG.initialization,
                                 return_sequences=layer_number + 1 < CONFIG.input_layers))
        model.add(Dropout(CONFIG.amount_of_dropout))
    # For the decoder's input, we repeat the encoded input for each time step
    model.add(RepeatVector(output_len))
    # The decoder RNN could be multiple layers stacked or a single layer
    for _ in range(CONFIG.output_layers):
        model.add(recurrent.LSTM(CONFIG.hidden_size, return_sequences=True, kernel_initializer=CONFIG.initialization))
        model.add(Dropout(CONFIG.amount_of_dropout))

    # For each of step of the output sequence, decide which character should be chosen
    model.add(TimeDistributed(Dense(len(chars), kernel_initializer=CONFIG.initialization)))
    model.add(Activation('softmax'))

    model.compile(loss='categorical_crossentropy', optimizer='adam', metrics=['accuracy'])
    return model
def generate_model ( output_len , chars = None ) : print ( 'Build model...' ) chars = chars or CHARS model = Sequential ( ) # "Encode" the input sequence using an RNN, producing an output of hidden_size # note: in a situation where your input sequences have a variable length, # use input_shape=(None, nb_feature). for layer_number in range ( CONFIG . input_layers ) : model . add ( recurrent . LSTM ( CONFIG . hidden_size , input_shape = ( None , len ( chars ) ) , kernel_initializer = CONFIG . initialization , return_sequences = layer_number + 1 < CONFIG . input_layers ) ) model . add ( Dropout ( CONFIG . amount_of_dropout ) ) # For the decoder's input, we repeat the encoded input for each time step model . add ( RepeatVector ( output_len ) ) # The decoder RNN could be multiple layers stacked or a single layer for _ in range ( CONFIG . output_layers ) : model . add ( recurrent . LSTM ( CONFIG . hidden_size , return_sequences = True , kernel_initializer = CONFIG . initialization ) ) model . add ( Dropout ( CONFIG . amount_of_dropout ) ) # For each of step of the output sequence, decide which character should be chosen model . add ( TimeDistributed ( Dense ( len ( chars ) , kernel_initializer = CONFIG . initialization ) ) ) model . add ( Activation ( 'softmax' ) ) model . compile ( loss = 'categorical_crossentropy' , optimizer = 'adam' , metrics = [ 'accuracy' ] ) return model