0

I want to merge keras embeddings with normal models into one sequential model as in the notebook in this repository

from keras.layers import *
from keras.models import *

models = []

for categoical_var in categorical_vars :
    model = Sequential()
    model.reset_states( )
    no_of_unique_cat  = df[categoical_var].nunique()
    embedding_size = min(np.ceil((no_of_unique_cat)/2), 50 )
    embedding_size = int(embedding_size)
    model.add(  Embedding( no_of_unique_cat+1, embedding_size, input_length = 1 ) )
    model.add(Reshape(target_shape=(embedding_size,)))
    models.append( model )


model_rest = Sequential()
model_rest.add(Dense(  64 , input_dim = 6 ))
model_rest.reset_states( )
models.append(model_rest)

full_model = Sequential()
full_model.add(Merge(models, mode='concat'))

full_model.add(Dense(512))
full_model.add(Activation('sigmoid'))
full_model.add(Dropout(0.2))

full_model.add(Dense(32))
full_model.add(Activation('sigmoid'))
full_model.add(Dropout(0.2))

full_model.add(Dense(1))

full_model.compile(loss='mean_squared_error', optimizer='Adam',metrics=['mse','mape'])

The problem is new versions of keras doesn't use 'Merge' any more, I tried to use Concatenate, but it does not work with sequential models

Any help? I looked in to this, but it is a different problem

owise
  • 1,055
  • 16
  • 28

0 Answers0