Skip to content

Commit c340292

Browse files
committed
Add README and comments for feedforward classification examples
1 parent c29d1c0 commit c340292

File tree

3 files changed

+101
-0
lines changed

3 files changed

+101
-0
lines changed

dl4j-examples/src/main/java/org/deeplearning4j/examples/quickstart/modeling/feedforward/classification/MNISTSingleLayer.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@
1717
* SPDX-License-Identifier: Apache-2.0
1818
******************************************************************************/
1919

20+
21+
// MNISTSingleLayer.java
22+
// Simple single-hidden-layer MLP for MNIST digit classification.
23+
// Demonstrates basic feedforward networks in DL4J.
24+
2025
package org.deeplearning4j.examples.quickstart.modeling.feedforward.classification;
2126

2227
import org.deeplearning4j.datasets.iterator.impl.MnistDataSetIterator;
@@ -72,6 +77,9 @@ public static void main(String[] args) throws Exception {
7277

7378

7479
log.info("Build model....");
80+
81+
// Build a single-hidden-layer MLP for MNIST (28x28 images flattened to 784 inputs)
82+
7583
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder()
7684
.seed(rngSeed) //include a random seed for reproducibility
7785
// use stochastic gradient descent as an optimization algorithm
@@ -100,6 +108,7 @@ public static void main(String[] args) throws Exception {
100108
log.info("Train model....");
101109
model.fit(mnistTrain, numEpochs);
102110

111+
// Evaluate the model on the MNIST test dataset
103112

104113
log.info("Evaluate model....");
105114
Evaluation eval = model.evaluate(mnistTest);

dl4j-examples/src/main/java/org/deeplearning4j/examples/quickstart/modeling/feedforward/classification/ModelXOR.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@
1717
* SPDX-License-Identifier: Apache-2.0
1818
******************************************************************************/
1919

20+
21+
// ModelXOR.java
22+
// Demonstrates solving the XOR problem using a small MLP.
23+
// XOR is not linearly separable -> requires hidden layers.
24+
2025
package org.deeplearning4j.examples.quickstart.modeling.feedforward.classification;
2126

2227
import org.deeplearning4j.nn.conf.MultiLayerConfiguration;
@@ -110,6 +115,9 @@ public static void main(String[] args) {
110115

111116
log.info("Network configuration and training...");
112117

118+
// Build a small 2-layer MLP for XOR classification
119+
120+
113121
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder()
114122
.updater(new Sgd(0.1))
115123
.seed(seed)
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
# Feedforward Neural Network Classification Examples – DeepLearning4J
2+
3+
This folder contains several feedforward neural network (MLP) classification examples using DeepLearning4J.
4+
They demonstrate how to train neural networks on classic datasets such as MNIST, Iris, XOR, and synthetic datasets.
5+
6+
---
7+
8+
## 🧠 MNISTSingleLayer.java
9+
A simple single-hidden-layer MLP for MNIST digit classification.
10+
11+
### What this example shows
12+
- Loading MNIST data
13+
- Building a minimal feedforward model
14+
- Backpropagation training
15+
- Evaluating test accuracy
16+
17+
---
18+
19+
## 🧠 MNISTDoubleLayer.java
20+
A deeper MLP with two hidden layers for MNIST.
21+
22+
### Why it's useful
23+
- Shows the impact of depth on accuracy
24+
- Good introduction to multi-layer feedforward networks
25+
26+
---
27+
28+
## 🌸 IrisClassifier.java
29+
A classifier for the Iris flower dataset.
30+
31+
### What you learn
32+
- Basic classification with a very small dataset
33+
- How to use evaluation metrics
34+
- Simple preprocessing
35+
36+
---
37+
38+
## 🧪 ModelXOR.java
39+
A classic MLP solving the XOR problem.
40+
41+
### Why XOR?
42+
- Not linearly separable
43+
- Demonstrates why deep networks are needed
44+
45+
---
46+
47+
## 🌙 MoonClassifier.java
48+
Binary classification on a synthetic two-moon dataset.
49+
50+
### Learnings
51+
- Handling noisy 2D datasets
52+
- Visualizing classification boundaries
53+
54+
---
55+
56+
## 🪐 SaturnClassifier.java
57+
Classification of Saturn (concentric circles) synthetic dataset.
58+
59+
### Shows
60+
- Decision boundaries
61+
- How MLPs learn non-linear patterns
62+
63+
---
64+
65+
## ✔ How to Run Any Example
66+
67+
Use the following command template:
68+
69+
70+
mvn -q exec:java -Dexec.mainClass="org.deeplearning4j.examples.quickstart.modeling.feedforward.classification.<ClassName>"
71+
72+
73+
Example:
74+
75+
76+
77+
mvn -q exec:java -Dexec.mainClass="org.deeplearning4j.examples.quickstart.modeling.feedforward.classification.MNISTSingleLayer"
78+
79+
80+
---
81+
82+
## 🙌 Why This README Helps
83+
These classification examples previously had no documentation.
84+
This README improves clarity, explains datasets, and helps beginners understand each example.

0 commit comments

Comments
 (0)