MNIST Crystal

NeuralCrystal was built by Pete DeLaurentis with Shellcaster, an IDE for building complex projects with agents.

This model represents a physical crystal with 5 etched surfaces and 330K parameters that is trained to read handwritten digits with light. Nothing in the glass switches or draws power: the digit goes in as light, passes once through the block, and lights up one of ten squares.

Demo

Run this crystal in the optical simulator at NeuralCrystal.com: draw a digit and watch the crystal read it, and see the light travel through the glass.

The MNIST crystal in the optical simulator at NeuralCrystal.com: a handwritten 5 on the screen, the light through the crystal, and its answer

Input

The digit goes in as a 32 × 32 picture on a micromirror array, drawn white on black the way MNIST stores it, with each pixel's brightness setting how much light it sends. This is a handwritten 4 from the test set:

A handwritten 4 as the crystal sees it: a 32 × 32 picture on the micromirror array

Output

The light passes once through five etched surfaces and lands on the exit face. Ten squares there, laid out like a phone keypad, each collect the light for one digit, and the brightest square is the answer. Below, the squares are outlined in teal and the answer, 4, in white:

The light on the exit face for the handwritten 4: ten squares laid out like a keypad, the brightest (4) outlined in white

Results

Accuracy (higher is better):

Precision Test digits (10,000) Held-out writers (5,095 digits by people the crystal never saw)
32-bit 97.29 % 95.56 %
16-bit 97.29 % 95.56 %
8-bit 97.28 % 95.56 %

The three precisions read digits the same: 8-bit misses one more test digit out of 10,000.

Use it

Install the neuralcrystal Python package, which runs the crystal's light path in PyTorch. Its code and more examples are on GitHub at neuralcrystal/neuralcrystal.

pip install neuralcrystal
import numpy as np
from PIL import Image
import neuralcrystal as nc
from neuralcrystal import mnist

crystal = nc.load("mnist-crystal.safetensors")

# 28 × 28, white ink on black
img = np.array(Image.open("digit.png").convert("L"))
digit, scores = mnist.classify(crystal, img)
print(int(digit[0]))

Files

File Size What it holds
mnist-crystal.safetensors 5.2 MB the five phase surfaces, fp32 radians
mnist-crystal-16bit.safetensors 0.7 MB phase wrapped to one turn, 16 bits a sample, cropped to the lit window
mnist-crystal-8bit.safetensors 0.3 MB the same at 8 bits

The crystal

Part Details
Light 617 nm, coherent, one pass
Glass fused silica, n = 1.4607
Surfaces 5, each 512 × 512 samples at 1 µm, 1.21 mm apart
Lit window 256 µm square
Input the digit on a 32 × 32 frame, as amplitudes on a micromirror array
Output ten squares on the exit face in a phone-pad pattern; the brightest is the digit

The simulation is scalar diffraction (band-limited angular spectrum) between thin phase surfaces, the same forward pass the crystal was trained with.

Training

Trained in simulation on handwritten digits, in steps:

  1. Digits: the QMNIST training set (Yadav & Bottou, 2019), drawn on the micromirror array.
  2. People it never saw: whole writers held out, to score how well it reads new handwriting.
  3. Schedule: 100 passes over the data, with the learning rate easing off on a cosine curve.

Credits

The crystal was trained on handwritten digits from MNIST and QMNIST (Yadav & Bottou, 2019; BSD license).

License

The crystal is CC BY-NC 4.0: free to use, share and adapt for non-commercial purposes, with credit. For commercial use, contact TextJam, Inc.

The neuralcrystal code is MIT.

© 2026 TextJam, Inc.

Downloads last month

-

Downloads are not tracked for this model. How to track
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support

Dataset used to train neuralcrystal/mnist-crystal