# Handling variable output units in MLP?

I am using Keras to build my architecture.

The regression problem I am trying to solve has outputs different for different training samples.

Suppose that I have very first two rows of y_train = [[16, 3], [6], ... ] corresponding to my very first two rows of X_train (input data). I would like to assign the output of the dense layer's unit to length of these y_train rows.

For example, for 1st training sample, I would like model.add(dense(2)) as y_train[0] has length 2, for 2nd training sample, I would like model.add(dense(1)) as y_train[0] has length 1, and so on.

I also think that I can call Lambda Layer instead of output dense layer and in that Lambda Layer I can wrap length of every row of y_train and assign it as output units by using output_shape argument of Lambda Layer. But, I don't know how can I access my y_train at training time of my model so that I can use y_train inside lambda layer to make this scenario happen either, nonetheless.

Can anybody help me on this variable length output problem?

• It is not clear what you want your final input to look like. Please post what your dataset should look like if you could make it happen. – grldsndrs Jul 31 '19 at 17:36