diff --git a/dl4j-examples/src/main/java/org/deeplearning4j/examples/advanced/modelling/charmodelling/melodl4j/README.md b/dl4j-examples/src/main/java/org/deeplearning4j/examples/advanced/modelling/charmodelling/melodl4j/README.md index e6887b62d1..8b00d8553f 100644 --- a/dl4j-examples/src/main/java/org/deeplearning4j/examples/advanced/modelling/charmodelling/melodl4j/README.md +++ b/dl4j-examples/src/main/java/org/deeplearning4j/examples/advanced/modelling/charmodelling/melodl4j/README.md @@ -27,6 +27,33 @@ To help judge the extent to which generated melodies mimic existing melodies in See http://www.asimovinstitute.org/analyzing-deep-learning-tools-music/, and https://github.com/tensorflow/magenta for some previous work in music generation via deep learning. I found out recently that MELODL4J is similar to magenta: both extract monophonic melodies from MIDI -- and both have a class named NoteSequence! -- but MELODL4J was developed independently and uses different techniques. * * * +## Prerequisites + +- Java 8 or later +- Maven installed +- Internet connection to download MIDI datasets +- Audio output enabled for melody playback +- Enough memory for training larger LSTM models + +## Quick Start + +1. Run `MidiMelodyExtractor.java` to extract melody strings from MIDI files. +2. Run `MelodyModelingExample.java` to train the LSTM network. +3. Listen to generated melodies after each epoch. +4. Review the generated melody output file after training. + +## Main Classes + +- `MidiMelodyExtractor.java` – Extracts symbolic melodies from MIDI files +- `MelodyModelingExample.java` – Trains the LSTM model +- `PlayMelodyStrings.java` – Converts melody strings back into MIDI and plays them +- `NoteSequence.java` – Represents note sequences internally + +## How to Run + +```bash +mvn -q exec:java -Dexec.mainClass="org.deeplearning4j.examples.advanced.modelling.charmodelling.melodl4j.MelodyModelingExample" + ### Overview of methodology, simplifications, and tricks 1. MidiMelodyExtractor.java parses MIDI files and outputs melodies in symbolic form. @@ -55,6 +82,15 @@ See http://www.asimovinstitute.org/analyzing-deep-learning-tools-music/, and htt * * * +## Expected Output + +During training, you should see: +- MIDI files being downloaded and extracted +- Melody extraction statistics +- Network training progress +- Generated melodies after each epoch +- Output file containing generated melodies + ### Possible directions for improvement 1. Represent durations numerically, not symbolically. Currently, both pitches and durations are represented symbolically (as characters), not numerically. This makes sense for pitches probably, since the qualitative feel of a C followed by a G is quite different from the qualitative feel of a C followed by a G#. Likewise, following a C, a G is more similar to a E than to a G#; both E and G are notes in a C major chord. But for tempos, a 32d note is more similar to a 16th note than to a quarter note, etc. diff --git a/nd4j-ndarray-examples/README.md b/nd4j-ndarray-examples/README.md index 03be227cf9..382a244419 100644 --- a/nd4j-ndarray-examples/README.md +++ b/nd4j-ndarray-examples/README.md @@ -1,3 +1,5 @@ + + ## Eclipse Deeplearning4j: ND4J NDArray Examples This project contains a set of examples that demonstrate how to manipulate NDArrays. The functionality of ND4J demonstrated here can be likened to NumPy. @@ -48,3 +50,114 @@ Create and fit a normalizer, and save and restore it. * [CustomOpsExamples.java](./src/main/java/org/nd4j/examples/advanced/operations/CustomOpsExamples.java) **Only relevant to the 1.0.0-beta6 release**. There are some operations that were implemented in C++ that had not been mapped to Java. This example demonstrates how to access them using ND4J's DynamicCustomOp. As of the beta7 release all maps have corresponding Java mappings. +# ND4J NDArray Examples + +This module contains simple examples that demonstrate how to use **ND4J** +(N-dimensional arrays for Java) — the core numerical computing library behind Deeplearning4j. + +ND4J provides fast tensor operations similar to NumPy, backed by optimized BLAS +implementations. + +These examples help new users understand: + +- What an `INDArray` is +- How to create arrays +- How to perform basic math +- How to reshape, slice, and combine arrays +- How to run the examples using Maven + +--- + +## 📌 What is an NDArray? + +An **NDArray** (N-dimensional array) is ND4J’s fundamental data structure. +It represents: + +- Scalars (0D) +- Vectors (1D) +- Matrices (2D) +- Higher dimensional tensors (3D, 4D, …) + +ND4J operations are *vectorized* and run efficiently on CPU or GPU (via CUDA backend). + +Example: + +```java +INDArray arr = Nd4j.create(new float[]{1, 2, 3}); +System.out.println(arr); // [1.00, 2.00, 3.00] +📘 Basic NDArray Operations +Create Arrays +java + +INDArray zeros = Nd4j.zeros(3, 3); +INDArray ones = Nd4j.ones(2, 2); +INDArray random = Nd4j.rand(1, 5); +INDArray arange = Nd4j.arange(1, 10); +Math Operations +java + +INDArray a = Nd4j.create(new float[]{1, 2, 3}); +INDArray b = Nd4j.create(new float[]{4, 5, 6}); + +System.out.println(a.add(b)); // elementwise add +System.out.println(a.mul(b)); // elementwise multiply +System.out.println(a.mmul(b.T())); // matrix multiplication +Reshape and Shape Ops + +INDArray m = Nd4j.linspace(1, 9, 9).reshape(3, 3); +System.out.println(m); + +System.out.println(m.transpose()); +System.out.println(m.permute(1, 0)); +▶️ How to Run These Examples +Make sure you have: + +Java 8 or later + +Maven installed + +Then run: + + +mvn -q exec:java -Dexec.mainClass="org.nd4j.examples.quickstart.BasicNDArrayExample" +Or run any other example under: + + + +src/main/java/org/nd4j/examples/ +Example: + + +mvn -q exec:java -Dexec.mainClass="org.nd4j.examples.advanced.SlicingExample" +📤 Expected Output (Sample) +Running a basic NDArray creation example: + + +Copy code +Zeros array: +[[0.00, 0.00, 0.00], + [0.00, 0.00, 0.00], + [0.00, 0.00, 0.00]] + +Random array: +[0.42, 0.91, 0.12, 0.55, 0.33] + +Vector add: +[5.00, 7.00, 9.00] +📁 Project Structure + +nd4j-ndarray-examples/ + ├── src/ + │ └── main/java/org/nd4j/examples/ + │ ├── advanced/ + │ ├── quickstart/ + │ ├── utils/ + │ └── resources/ + ├── pom.xml + └── README.md +📄 License +This project is part of the Eclipse Deeplearning4j examples collection +and is licensed under the Apache License 2.0. + +Happy coding with ND4J tensors! 🚀 +