NeuroSplit is a deep learning binary classification framework and interactive decision boundary visualization engine built with PyTorch and deployed via Gradio on Hugging Face Spaces.
It learns complex, non-linear geometric decision boundaries across 2D continuous coordinate spaces on the classic Two Moons benchmark (sklearn.datasets.make_moons), achieving 99.5%+ verified test accuracy.
Try the deployed application live on Hugging Face Spaces:
π NeuroSplit Demo on Hugging Face Spaces
The neural network learns a smooth, non-linear crescent separation curve that isolates Class 0 (Red / Moon A) from Class 1 (Green / Moon B).
- Red Markers (Class 0): Upper crescent moon samples.
- Green Markers (Class 1): Lower interlocking crescent moon samples.
-
Black Solid Contour Line: The exact classification threshold where predicted sigmoid probability
$P(Y=1 \mid X) = 0.50$ . -
Background Color Field: Continuous probability landscape (
$P \to 0$ in warm red/peach,$P \to 1$ in pale green/mint).
The model is an optimized Multi-Layer Perceptron (MLP) with 16 hidden units per layer to capture the interlocking dual-crescent geometry:
graph LR
In[Input Layer<br/>2 Features: x, y] --> L1[Linear Layer 1<br/>2 -> 16]
L1 --> T1[Activation<br/>Tanh]
T1 --> L2[Linear Layer 2<br/>16 -> 16]
L2 --> T2[Activation<br/>Tanh]
T2 --> Out[Output Layer<br/>16 -> 1]
Out --> Sig[Sigmoid<br/>Logit -> Probability]
class Net(nn.Module):
def __init__(self):
super().__init__()
self.layer1 = nn.Linear(2, 16)
self.layer2 = nn.Linear(16, 16)
self.output = nn.Linear(16, 1)
def forward(self, x):
x = torch.tanh(self.layer1(x))
x = torch.tanh(self.layer2(x))
x = self.output(x)
return x-
Input Dimension: 2 continuous coordinates (
$x, y$ ). - Hidden Layers: 2 dense layers with 16 hidden units each.
-
Activation Functions: Hyperbolic Tangent (
$\tanh(z) = \frac{e^z - e^{-z}}{e^z + e^{-z}}$ ), providing zero-centered smooth non-linear gradients. -
Total Parameters: 321 trainable parameters (ultra-lightweight,
$< 5\text{ KB}$ footprint,$< 1\text{ ms}$ inference latency).
Training optimizes Binary Cross-Entropy with Logits:
Using nn.BCEWithLogitsLoss combines the Sigmoid layer and BCE loss into a single numerically stable formulation via the log-sum-exp trick, preventing floating-point overflow and gradient underflow.
-
Optimizer:
torch.optim.Adam -
Learning Rate:
$\eta = 0.01$ - Batch Size: 32 (mini-batch gradient descent with shuffling)
- Epochs: 100
To ensure peak generalization without covariate shift:
The training statistics model.pth so the Gradio app performs identical preprocessing during live inference.
| Dataset | Architecture | Epochs | Loss | Train Accuracy | Test Accuracy | Status |
|---|---|---|---|---|---|---|
| Two Moons (noise=0.1) | 16-16 MLP | 100 | 0.0001 | 100.00% | 99.50% | β State-of-the-art separation |
NeuroSplit/
β
βββ assets/
β βββ decision_boundary.png # High-resolution boundary plot
β
βββ neurosplit-demo/ # Hugging Face Spaces deployment directory
β βββ .gitattributes # Git LFS tracking configuration
β βββ .gitignore # Space build ignore rules
β βββ README.md # Space metadata YAML frontmatter
β βββ app.py # Complete Gradio web application
β βββ data.csv # Reference dataset points
β βββ model.pth # Exported PyTorch checkpoint (weights + mean/std)
β βββ requirements.txt # Dependencies for Hugging Face container
β
βββ data.csv # Two Moons dataset (1,000 samples)
βββ generate_asset.py # Script to reproduce publication-grade plots
βββ model.pth # Trained root model checkpoint
βββ splitter.ipynb # Interactive Jupyter exploration notebook
βββ train.py # Standalone PyTorch training & export pipeline
βββ README.md # Project documentation
git clone https://github.com/YourUsername/NeuroSplit.git
cd NeuroSplit# Create virtual environment
python -m venv venv
# Activate on Windows:
.\venv\Scripts\activate
# Activate on Linux/macOS:
source venv/bin/activatepip install torch torchvision numpy pandas matplotlib scikit-learn gradioRun the end-to-end training pipeline on the Moons dataset:
python train.pyTo test the web interface on your local machine:
python neurosplit-demo/app.pyOpen your browser at: http://127.0.0.1:7860
Navigate to neurosplit-demo and push to your Space repository:
cd neurosplit-demo
git add .
git commit -m "Deploy NeuroSplit 16-unit Moon model"
git push origin main-
CPU Basic (Free - Recommended): Under Space Settings
$\to$ Space Hardware, selectCPU basic. The model runs in$< 1\text{ ms}$ with zero queues and 24/7 uptime. -
ZeroGPU: If assigned to ZeroGPU, the app includes native
@spaces.GPUdecorators inapp.py.
This project is open-source and available under the MIT License.
