Neural network trained to predict images in the MNIST database.
Find a file
2025-11-14 12:13:02 +01:00
.gitignore first commit 2025-10-16 09:03:50 +02:00
common.py first commit 2025-10-16 09:03:50 +02:00
data.sh first commit 2025-10-16 09:03:50 +02:00
LICENSE added LICENSE 2025-10-16 19:27:34 +02:00
README.md add README 2025-10-16 09:23:37 +02:00
requirements.txt first commit 2025-10-16 09:03:50 +02:00
test.py first commit 2025-10-16 09:03:50 +02:00
train.py increasing batch size makes the training process sensibly faster. 2025-11-14 12:13:02 +01:00

mnist

This is a neural network trained to predict images of the MNIST database. It's written in python without making use of ML libraries directly, using Apple's MLX to accelerate matrix computations with the GPU. This makes the scripts very fast on Apple Silicon machines since MLX makes great use of the SoC shared memory and lazy evaluation for efficiency. The code is commented in detail and quite simple to understand with basic understanding of neural networks.

Implementation

The network is structured to use 4 hidden layers of size 256x256. For activation of hidden layers ReLU is used and loss is calculated with cross-entropy. For optimization Adam is used (check the references section).

Running

To run the scripts you first need to download the dataset and the dependencies with

./data.sh
pip install -r requirements.txt

After that you can train the model by running the train.py script. To test the model you can run test.py instead. Accuracy should be around 97%.

References