This study develops an automatic music generation model based on Long Short-Term Memory (LSTM) by utilizing MIDI data as a symbolic representation of classical piano music sequences. The approach is computational and experimental, with a workflow that includes extracting and converting MIDI files using music21, constructing note and chord tokens, forming input–output sequences, designing a three-layer LSTM architecture, and generating music in an autoregressive manner. The model is trained for 100 epochs with a batch size of 64 and evaluated using loss, accuracy, top-3 accuracy, and perplexity metrics to assess its predictive capability on unseen data. The experimental results show a consistent decrease in validation loss, with a final value of approximately 2.93 and a validation accuracy of 0.33, while the top-3 accuracy reaches 0.53, indicating that more than half of the correct predictions fall within the top three candidates. A perplexity value around 18 suggests that the model has a reasonably adequate sequence prediction ability for symbolic music data. Qualitatively, the model is able to generate simple melodies whose patterns remain coherent with the note distribution in the dataset, although some parts of the compositions still exhibit repetition and limited variation. An important contribution of this study is the provision of a systematic methodological documentation of the LSTM-based music generation pipeline, which can serve as a practical reference for future development and research in deep learning–based music generation.
Copyrights © 2026