Keras: How to concatenate over a subset of inputs

Viewed 1052

I am training a neural network using Keras and Theano, in which inputs have a format like:

[
   [Situation features],
   [Option 1 features],
   [Option 2 features],
]

I want to train a model to predict how often each option will be chosen, by making the model learn how to score each option, and how the situation makes differences in score more or less important.

My model looks like:

option_inputs = [Input(shape=(NUM_FEATURES,), name='situation_input'),
                  Input(shape=(NUM_FEATURES,), name='option_input_0'),
                  Input(shape=(NUM_FEATURES,), name='option_input_1')]
situation_input_processing = Dense(5, activation='relu', name='situation_input_processing')
option_input_processing = Dense(20, activation='relu', name='option_input_processing')
diversity_neuron = Dense(1, activation='softplus', name='diversity_neuron')
scoring_neuron = Dense(1, activation='linear', name='scoring_neuron')

diversity_output = diversity_neuron(situation_input_processing(journey_inputs[0]))
scoring_outputs = [scoring_neuron(option_input_processing(option_input)) for option_input in option_inputs[1:2]]

logit_outputs = [Multiply()([diversity_output, scoring_output]) for scoring_output in scoring_outputs]
probability_outputs = Activation('softmax')(keras.layers.concatenate(logit_outputs, axis=-1))

model = Model(inputs=option_inputs, outputs=probability_outputs)

When trying to get probability_outputs, I get the error:

ValueError: Concatenate layer should be called on a list of inputs

The error seems to be triggered because logit_outputs is not built iterating through all 3 input feature collections, only out of 2 of them.

Any idea how to work around this problem?

Once the model is trained, I want to observe the outputs of diversity_neuron and scoring_neuron to learn how to extrapolate the scoring for arbitrary number of options and understand what drives diversity.

1 Answers
Related