I'm pretty confused with the input/output/dense portion of an autoencoder.
So my data consists of a numpy array of a 9 categorical features which have all been one hot encoded.
So the input would look something like this [[0,1,....,1], [1,0...,1],....,[1,1,...,1]] where there are 9 total indices to the original array.
Now the input is a part of a larger array that consists of around 200,000 entries which makes up my dataset. Hopefully that makes sense.
When I create the autoencoder I start with the encoder as:
def _encoder(self): inputs = Input(shape=(self.x.shape)) #keras.layers.BatchNormalization() encoded = Dense(self.encoding_dim, activation='relu')(inputs) model = Model(inputs, encoded) self.encoder = model return model
From my understanding the encoding_dim is the number of features that the autoencoder is reducing the input down to? So something like 5 would work well?
Then, for the decoder:
def _decoder(self): inputs = Input(shape=(self.encoding_dim,)) decoded = Dense(self.x.shape)(inputs) model = Model(inputs, decoded) self.decoder = model return model
Now, in the decoder I get an error. Don't I want to receive the original dimensions of the input?? I get the following error:
File "<ipython-input-5-c3e9cae855b1>", line 138, in <module> ae.encoder_decoder() File "<ipython-input-5-c3e9cae855b1>", line 106, in encoder_decoder dc = self._decoder() File "<ipython-input-5-c3e9cae855b1>", line 99, in _decoder decoded = Dense(self.x.shape)(inputs) File "/home/nerp/miniconda3/lib/python3.6/site-packages/keras/engine/base_layer.py", line 431, in __call__ self.build(unpack_singleton(input_shapes)) File "/home/nerp/miniconda3/lib/python3.6/site-packages/keras/layers/core.py", line 866, in build constraint=self.kernel_constraint) File "/home/nerp/miniconda3/lib/python3.6/site-packages/keras/legacy/interfaces.py", line 91, in wrapper return func(*args, **kwargs) File "/home/nerp/miniconda3/lib/python3.6/site-packages/keras/engine/base_layer.py", line 249, in add_weight weight = K.variable(initializer(shape), File "/home/nerp/miniconda3/lib/python3.6/site-packages/keras/initializers.py", line 209, in __call__ scale /= max(1., float(fan_in + fan_out) / 2) TypeError: unsupported operand type(s) for +: 'int' and 'tuple'
To me this sounds like it is expecting a dimension that is just one integer (not a tuple/shape). So should I then put 9 since I want the 9 original features?
Related code since it's in the error:
def encoder_decoder(self): ec = self._encoder() dc = self._decoder() inputs = Input(shape=self.x.shape) ec_out = ec(inputs) dc_out = dc(ec_out) model = Model(inputs, dc_out) self.model = model return model
I would really appreciate the help! I'm also sorry if this is in the wrong place... please let me know if it is, or if more information is needed! Thanks.