.serva byte streams without decoding, parsing, or reshaping them into images. The pipeline:
- Zero-pad raw bytes to the next power of 2
- Fast Walsh-Hadamard Transform (FWHT) — a fixed, orthogonal projection that preserves distances in high-dimensional byte space
- Truncate to the first 4 096 low-frequency coefficients
- MLP classifier with LayerNorm, GELU, and Dropout
.serva files live in a high-dimensional byte space where distance-preserving projections (Johnson-Lindenstrauss) retain class structure.
Before you start
Dependencies:torch only. No torchvision, no numpy at runtime. Use a GPU when available (CUDA on NVIDIA, MPS on Apple Silicon).
Dataset layout: one subfolder per class, with .serva files inside each:
.serva file is one training example. Repeat the same class folder names under train/ and val/ so label indices stay aligned.
To create .serva files, use the Serva web app, upload sources, encode, and download.
Every
.serva file may have a different byte length. The loader pads shorter files with zeros to the next power of 2 so every sample has the same feature dimension. No bytes are truncated.Load data: read .serva bytes into tensors
Feature extraction: Walsh-Hadamard transform
The Fast Walsh-Hadamard Transform is an orthogonal, distance-preserving projection — analogous to an FFT but over{+1, −1} basis vectors. It maps variable-length byte sequences into a fixed-size feature vector without learning any parameters.
Truncating to the first 4 096 coefficients keeps the lowest-frequency components of the Hadamard spectrum. This acts as dimensionality reduction while preserving the most informative structure. The truncation point was validated empirically — 4 096 is the sweet spot for this dataset size.
Model: MLP classifier
A two-hidden-layer MLP with LayerNorm on the input (the Hadamard coefficients have varying scale), GELU activations, and Dropout for regularization.pin_memory=True in the DataLoader is only useful with CUDA; on MPS (Apple GPU), omit it. running_corrects.float() in the training loop keeps accuracy math in float32, which works on CUDA, MPS, and CPU — .double() can error on MPS (no float64).Training loop
Same phase pattern as the standard PyTorch classification tutorial:train / val, model.train() / model.eval(), torch.set_grad_enabled, scheduler step after each train epoch, keep best val accuracy weights.

