Which line of code uses the trained model?

Hi mentors and friends,
Hw: Improvise_a_Jazz_Solo_with_an_LSTM_Network_v4

Q1, after I made the djmodel the mode, then train it by using history = model.fit([X, a0, c0], list(Y), epochs=100, verbose = 0). Then, we use this trained model to generate the music, right ? can someone pinpoint which line of code is using this trained model (history )?

maybe one of the lines in the def music_inference_model?or this LSTM_cell inherited all trained parameters?

Q2. why do we use Dense instead of just the softmax layer? Are we doing something like deep RNN ? The figure shows the LSTM go to softmax directly, not a fully connected layer then softmax, right ?

thank you!

LSTM_cell is trained by djmodel(), and it is used for predictions by music_inference_model(). See it’s Step 2.

The “Softmax” block used in the LSTM lectures and the figure includes a Dense layer. See the C5 W1 video “Recurrent Neural Network Model” for details.

1 Like

thanks, TMosh, I am very close now. Allow me to double-check something here.

  1. djmodel() trained this LSTM_cell, since music_inference_model() uses this LSTM_cell, that’s how it inherited the trained parameters from djmodel(). my understanding is correct?

2 how about the “densor” which is in music_inference_model(LSTM_cell, densor, Ty=100) ? Does djmodel trained this densor as well ? In other words, LSTM_cell and densor are trained, then used by music_inference_model() ?

  1. In the code of history = model.fit([X, a0, c0], list(Y), epochs=100, verbose = 0), this history also includes the layers of dense and LSTM. right ? So, my question is, the dense and LSTM in the history are exactly the same as dense and LSTM_cell in my 1 and 2, is this correct ? In other words, we do can use those two from history, but for convenience, we use globe LSTM_cell and dense ?

  2. I don’t see dense layer in the lectures, but I found the similar one in deep RNN as below, is this what you mean? thank you again for your time!!!

  1. Yes. LSTM_cell is a shared resource. It includes the trained LSTM parameters.

  2. densor() references the Dense layer with softmax activation. It has the Dense parameters.

  3. Yes, LSTM_cell and densor() are shared between djmodel() and music_inference_model()

  4. Yes, the part you circled in yellow are the Dense layer and softmax activation.

thank you, very helpful!