My code for training AI to make music

This code works but not sure if its perfect.

Any advice or feedback on it?

I trained a model and the output it gives me so far are great.

Got 50 000 midi files but not sure if that code is optimal for such large data.