Skip to content

Repository files navigation

Melody Generation using LSTM Project Overview This project focuses on generating musical melodies using a Long Short-Term Memory (LSTM) neural network. The model is trained on a dataset of melodies to learn sequences and generate new melodies based on the learned patterns.

Table of Contents Project Overview Installation Project Structure Dataset Model Architecture Training Usage Results Contributing License Installation Clone this repository:

bash Copy code git clone https://github.com/username/melody-generation-lstm.git cd melody-generation-lstm Install the required packages:

bash Copy code pip install -r requirements.txt Ensure you have the following dependencies installed:

TensorFlow Keras NumPy Music21 (for music processing) Matplotlib (for visualization) Project Structure bash Copy code melody-generation-lstm/ │ ├── dataset/ # Folder containing the training dataset ├── deutschl/ # Additional folder (could be renamed if needed) ├── Output/ # Folder where generated output will be stored ├── file_dataset/ # Another dataset-related folder ├── mapping.json # Mapping file for note encoding ├── melody_generator.py # Script to generate melodies using the trained model ├── model.h5 # Pre-trained LSTM model ├── preprocessing.py # Script to preprocess the dataset ├── train.py # Script to train the LSTM model └── tempCodeRunnerFile.py # Temporary file (not part of the main project) Dataset The model is trained on a dataset of melodies. The dataset should be placed in the dataset/ directory. It consists of MIDI files, and a mapping.json file is used to map notes to numerical representations for training.

Model Architecture The model uses a sequential LSTM network designed to handle musical sequences. The key layers of the architecture are:

LSTM layers for sequence processing. Dense layers for generating the next note in the sequence. Model summary:

python Copy code

  • Input Layer: LSTM with (sequence_length, 1) input shape
  • Hidden Layers: 2 LSTM layers with 128 units
  • Output Layer: Dense layer with softmax activation for generating note probabilities Training Preprocess the dataset by running:

bash Copy code python preprocessing.py Train the LSTM model:

bash Copy code python train.py Training configurations:

Batch size: 64 Epochs: 100 Optimizer: Adam The trained model will be saved as model.h5 in the project directory.

Usage To generate a melody using the trained model:

Run the melody generation script:

bash Copy code python melody_generator.py The generated melody will be saved in the Output/ folder as a MIDI file.

You can adjust parameters, such as the sequence length and temperature, in the melody_generator.py file.

Results After training the model, the generated melodies will be stored in the Output/ folder. Each melody is saved as a MIDI file, which can be played using any MIDI player.

Contributing Contributions are welcome! Please feel free to open an issue or submit a pull request.

About

Implemented Long Short-Term Memory (LSTM) networks for melody generation

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages