Skip to content

Implement NumPy neural network with MNIST training from scratch#1

Draft
Copilot wants to merge 3 commits intomainfrom
copilot/implement-neural-network-from-scratch
Draft

Implement NumPy neural network with MNIST training from scratch#1
Copilot wants to merge 3 commits intomainfrom
copilot/implement-neural-network-from-scratch

Conversation

Copy link
Copy Markdown

Copilot AI commented Apr 1, 2026

Adds a fully-connected neural network implemented entirely in NumPy, trained and evaluated on MNIST digit classification.

Core library (neural_network.py)

  • NeuralNetwork class with configurable layer sizes, He-initialized weights, and mini-batch gradient descent
  • Forward pass: ReLU hidden activations, numerically stable softmax output
  • Backward pass: analytical backpropagation with combined softmax + cross-entropy gradient
  • train() returns per-epoch loss/accuracy history; predict() / evaluate() for inference

Training script (train.py)

  • Loads MNIST via TensorFlow/Keras with scikit-learn fetch_openml as fallback
  • Default architecture: 784 → 128 → 64 → 10, 20 epochs, batch size 64, lr 0.1
  • Prints per-epoch loss + training accuracy; reports final test accuracy

Tests (test_neural_network.py)

  • 28 unit tests covering activations, loss, parameter init, forward/backward shapes
  • Numerical gradient check validates backprop correctness against finite differences
  • End-to-end training test on a toy dataset verifies loss decrease and accuracy above chance

Example

from neural_network import NeuralNetwork
import numpy as np

model = NeuralNetwork([784, 128, 64, 10], learning_rate=0.1)
model.train(X_train, Y_train, epochs=20, batch_size=64)
print(f"Test accuracy: {model.evaluate(X_test, Y_test):.4f}")
Original prompt

Implement a neural network from scratch in Python using NumPy, including forward propagation, backpropagation, and gradient descent. Train on MNIST dataset and evaluate accuracy.

Copilot AI and others added 2 commits April 1, 2026 14:04
…ssification

Agent-Logs-Url: https://github.com/Bitu-Singh-Rathoud/neural-network-numpy/sessions/2f9cae04-079e-450e-9133-bd27adca2411

Co-authored-by: Bitu-Singh-Rathoud <247644259+Bitu-Singh-Rathoud@users.noreply.github.com>
Agent-Logs-Url: https://github.com/Bitu-Singh-Rathoud/neural-network-numpy/sessions/2f9cae04-079e-450e-9133-bd27adca2411

Co-authored-by: Bitu-Singh-Rathoud <247644259+Bitu-Singh-Rathoud@users.noreply.github.com>
Copilot AI changed the title [WIP] Implement neural network with forward propagation and backpropagation Implement NumPy neural network with MNIST training from scratch Apr 1, 2026
Copilot AI requested a review from Bitu-Singh-Rathoud April 1, 2026 14:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants