W1 - Assignment 3: Why do we recalculate the one-hot vectors and indices in predict_and_sample after we did it in music_inference_model?

In music_inference_model, we calculate the indices and one-hot vectors of the predicted value, but then we store the softmax output into the outputs list. And then we pass the outputs list into predict_and_sample, and recalculate the one-hot vectors and the indices. Wouldn’t it be more efficient to save the indices or one-hot vectors into the outputs, because we’re using them anyways? This would then eliminate the need for a predict_and_sample function.

(I apologize for all these questions about this assignment. I’ve been a little confused conceptually.)

Hi Harvey_Wang,

Here’s my two cents.

music_inference_model serves to create and return a model, and only that. The specifics of the model can next be set, as is done with the line:

inference_model = music_inference_model(LSTM_cell, densor, Ty = 50).

Next, predict_and_sample is used to generate a sequence of values for that particular model.

In principle the two functions and the line defining the specifics of the model could be fused, which may well be more efficient. It seems to me that the two functions and the line are kept separate for logical reasons.

1 Like

Thanks for the answer! I also had a similar suspicion, but didn’t want to assume.