#AUTOGENERATED! DO NOT EDIT! File to edit: dev/model.ipynb (unless otherwise specified).

__all__ = ['build_wide_model', 'build_deep_model', 'build_ensemble_model']

#Cell
from keras.models import Sequential
from keras.layers import Embedding, Flatten, Dense, LSTM, Dropout, Bidirectional
from keras import layers
import keras

#Cell
def build_wide_model(input_dim = 50, outer_layer_dim = 25, inner_layer_dim = 256):

    variety_inputs = layers.Input(shape=(input_dim,))
    merged_layer = layers.Dense(inner_layer_dim, activation='relu')(variety_inputs)
    predictions = layers.Dense(outer_layer_dim)(merged_layer)
    wide_model = keras.Model(inputs=variety_inputs, outputs=predictions)

    wide_model.compile(loss='categorical_crossentropy', optimizer='adam', metrics=['accuracy'])

    return wide_model

#Cell
def build_deep_model(max_words, embedding_dim, maxlen, embedding_matrix, LSTM_units = 16):
    embedding_layer = Embedding(input_dim=max_words,
                                output_dim=embedding_dim,
                                input_length=maxlen,
                                weights=[embedding_matrix],
                                trainable=False,
                                name='embedding_layer')
    dropout_layer = Dropout(0.2)
    i = layers.Input(shape=(maxlen,), dtype='int32', name='main_input')
    x = embedding_layer(i)
    x = dropout_layer(x)
    x = Bidirectional(LSTM(units=LSTM_units, dropout=0.2, recurrent_dropout=0.2, input_shape=(max_words, embedding_dim)))(x)
    x = dropout_layer(x)
    # x = Flatten()(x)
    o = Dense(25, activation='softmax')(x)
    deep_model = keras.Model(inputs=i, outputs=o)
    deep_model.compile(loss='categorical_crossentropy', optimizer='adam', metrics=['accuracy'])

    return deep_model

#Cell
def build_ensemble_model(wide_model, deep_model):

    # Combine wide and deep into one model
    merged_out = layers.concatenate([wide_model.output, deep_model.output])
    merged_out = layers.Dense(25, activation='softmax')(merged_out)
    combined_model = keras.Model([wide_model.input] + [deep_model.input], merged_out)

    combined_model.compile(loss='categorical_crossentropy', optimizer='adam', metrics=['accuracy'])

    return combined_model