W1 A3: We trained a model in Part 2, music_inference_model() in Part 3 creates "outputs" , why create a Model and do inference then?

I do not have intuition why we end up creating a Model in music_inference_model()

inference_model = Model(inputs=[x0, a0, c0], outputs=outputs)

in music_inference_model() we trigger the forward pass and generate the output. We then store these outputs in “outputs”.

Why would we have to trigger inference again with inference_model.predict([x_initializer, a_initializer, c_initializer])? Why don’t we just use music_inference_model() and then return the outputs?

In my mind we:

  • trained the model in part 2 (ltsm and densor)
  • we then use the trained model in music_inference_model() to create “outputs”
  • in music_inference_model() we then create a Model that is assigned those outputs (??? seems unnecessary, why are telling a Model what its output values are?)
  • then in predict_and_sample() we do inference_model.predict() (??? Didn’t we already run the inference in music_inference_model(), how does it even know that it is supposed to output 100 sequences?)

Is there some python/keras magic I do not understand? I do not see the link between music_inference_model() and inference_model.predict(). How does “inference_model.predict()” know it is meant to use a generated value as input to the next value?

It’s complicated, let me see if I understand it well enough to explain.

LSTM_cell and densor were trained using djmodel(). Its training was told to use “epochs=100”.

music_inference_model() uses LSTM_cell and densor to create the ‘outputs’ - these are new music samples that were created using what djmodel() learned. Step 3 then uses the inputs and outputs to create a new model.

It looks to me like that second model is only used by predict_and_sample() to convert the format of the samples that music_inference_model() created.

This is what I could understand from the code -
music_inference_model is a function to output a model.
inference_model is a model created using the above function, by inputting trained LSTM, densor and Ty = 50
Inference_model.predict - Inputting initialised values of x, c, a to predict whole sequence according to the above model.