3.1-AIND-VUI-speech-recognition-project/sample_models.py
def final_model(input_dim, filters, kernel_size, conv_stride,
    conv_border_mode, units, output_dim=29, maxpool_sz=3, recur_layers=1, dropout_cnn=0.3, dropout_rnn=0.3):
    """ Build a deep network for speech 
    """
    # Main acoustic input
    input_data = Input(name='the_input', shape=(None, input_dim))
    # TODO: Specify the layers in your network
    # Add convolutional layer
    conv_1d = Conv1D(filters, kernel_size, 
                     strides=conv_stride, 
                     padding=conv_border_mode,
                     activation='relu',
                     name='conv1d')(input_data)
    
    # Add batch normalization & Dropout
    bn_cnn = BatchNormalization(name='bn_conv_1d')(conv_1d)
    drop_cnn = Dropout(dropout_cnn, name='dropout_cnn')(bn_cnn)
    # Add max pooling layer
    mxpool = MaxPooling1D(maxpool_sz, name='maxpool')(drop_cnn)
    
    # Add bi-directional recurrent layer(s)
    bidir_rnn = Bidirectional( LSTM(units, dropout=dropout_rnn, return_sequences=True, name='bidir_lstm1'),
                               merge_mode='concat')(mxpool)
    bn_rnn = BatchNormalization(name='bn_bidir_lstm1')(bidir_rnn)
    for ii in range(recur_layers-1):
        bidir_rnn = Bidirectional( LSTM(units, dropout=dropout_rnn, return_sequences=True, name='bidir_lstm'+str(ii+2)), 
                                   merge_mode='concat')(bn_rnn)
        bn_rnn = BatchNormalization(name='bn_bidir_lstm'+str(ii+2))(bidir_rnn)

    # TODO: Add a TimeDistributed(Dense(output_dim)) layer
    time_dense = TimeDistributed(Dense(output_dim))(bn_rnn)
    # Add softmax activation layer
    y_pred = Activation('softmax', name='softmax')(time_dense)
    # Specify the model
    model = Model(inputs=input_data, outputs=y_pred)
    # TODO: Specify model.output_length
    model.output_length = lambda x: cnn_output_length(
        x, kernel_size, conv_border_mode, conv_stride, poolsz=maxpool_sz)
    print(model.summary())
    return model
 Build a deep network for speech 
    
Build a deep network for speech
Build a deep network for speech
def final_model(input_dim, filters, kernel_size, conv_stride,
    conv_border_mode, units, output_dim=29, maxpool_sz=3, recur_layers=1, dropout_cnn=0.3, dropout_rnn=0.3):
    input_data = Input(name='the_input', shape=(None, input_dim))
    conv_1d = Conv1D(filters, kernel_size, 
                     strides=conv_stride, 
                     padding=conv_border_mode,
                     activation='relu',
                     name='conv1d')(input_data)
    bn_cnn = BatchNormalization(name='bn_conv_1d')(conv_1d)
    drop_cnn = Dropout(dropout_cnn, name='dropout_cnn')(bn_cnn)
    mxpool = MaxPooling1D(maxpool_sz, name='maxpool')(drop_cnn)
    bidir_rnn = Bidirectional( LSTM(units, dropout=dropout_rnn, return_sequences=True, name='bidir_lstm1'),
                               merge_mode='concat')(mxpool)
    bn_rnn = BatchNormalization(name='bn_bidir_lstm1')(bidir_rnn)
    for ii in range(recur_layers-1):
        bidir_rnn = Bidirectional( LSTM(units, dropout=dropout_rnn, return_sequences=True, name='bidir_lstm'+str(ii+2)), 
                                   merge_mode='concat')(bn_rnn)
        bn_rnn = BatchNormalization(name='bn_bidir_lstm'+str(ii+2))(bidir_rnn)
    time_dense = TimeDistributed(Dense(output_dim))(bn_rnn)
    y_pred = Activation('softmax', name='softmax')(time_dense)
    model = Model(inputs=input_data, outputs=y_pred)
    model.output_length = lambda x: cnn_output_length(
        x, kernel_size, conv_border_mode, conv_stride, poolsz=maxpool_sz)
    print(model.summary())
    return model
def final_model ( input_dim , filters , kernel_size , conv_stride , conv_border_mode , units , output_dim = 29 , maxpool_sz = 3 , recur_layers = 1 , dropout_cnn = 0.3 , dropout_rnn = 0.3 ) : input_data = Input ( name = 'the_input' , shape = ( None , input_dim ) ) conv_1d = Conv1D ( filters , kernel_size , strides = conv_stride , padding = conv_border_mode , activation = 'relu' , name = 'conv1d' ) ( input_data ) bn_cnn = BatchNormalization ( name = 'bn_conv_1d' ) ( conv_1d ) drop_cnn = Dropout ( dropout_cnn , name = 'dropout_cnn' ) ( bn_cnn ) mxpool = MaxPooling1D ( maxpool_sz , name = 'maxpool' ) ( drop_cnn ) bidir_rnn = Bidirectional ( LSTM ( units , dropout = dropout_rnn , return_sequences = True , name = 'bidir_lstm1' ) , merge_mode = 'concat' ) ( mxpool ) bn_rnn = BatchNormalization ( name = 'bn_bidir_lstm1' ) ( bidir_rnn ) for ii in range ( recur_layers - 1 ) : bidir_rnn = Bidirectional ( LSTM ( units , dropout = dropout_rnn , return_sequences = True , name = 'bidir_lstm' + str ( ii + 2 ) ) , merge_mode = 'concat' ) ( bn_rnn ) bn_rnn = BatchNormalization ( name = 'bn_bidir_lstm' + str ( ii + 2 ) ) ( bidir_rnn ) time_dense = TimeDistributed ( Dense ( output_dim ) ) ( bn_rnn ) y_pred = Activation ( 'softmax' , name = 'softmax' ) ( time_dense ) model = Model ( inputs = input_data , outputs = y_pred ) model . output_length = lambda x : cnn_output_length ( x , kernel_size , conv_border_mode , conv_stride , poolsz = maxpool_sz ) print ( model . summary ( ) ) return model
Build a deep network for speech
Build a deep network for speech
""" Build a deep network for speech 
    """ # Main acoustic input # TODO: Specify the layers in your network # Add convolutional layer # Add batch normalization & Dropout # Add max pooling layer # Add bi-directional recurrent layer(s) # TODO: Add a TimeDistributed(Dense(output_dim)) layer # Add softmax activation layer # Specify the model # TODO: Specify model.output_length
input_dim
filters
kernel_size
conv_stride
conv_border_mode
units
output_dim
maxpool_sz
recur_layers
dropout_cnn
dropout_rnn