[Showcase] SwiftNN: A Pure-Swift, Cross-Platform ML Library with Zero Dependencies
Hi everyone! ![]()
I'm mirrored-chameleon, a 13-year-old developer from Melbourne. For the past six months, I’ve been grinding on a problem: if you want to write machine learning code in Swift, you are almost always locked into heavy external dependencies or Apple-specific hardware acceleration.
I wanted a library that was 100% cross-platform, lightweight, and ran absolutely anywhere—from macOS to a standard Linux or Windows command line—using nothing but the Swift Standard Library.
So, I built it from scratch. Meet SwiftNN.
Check out the primary repositories here:
- Main Framework: GitHub - SwiftNN
- Transformer Experiment: GitHub - SwiftNN-Language-pre-release
Building this as a Year 7 student on a budget 2-in-1 laptop was an insane learning curve. Translating multi-layer algebra and backpropagation calculus into pure code without treating the network like a black box was tough. Because my hardware is lightweight, it forced me to focus entirely on software optimization. Discovering the swift run -c release flag was a complete lifesaver, turning on the high-level compiler optimizations needed to crunch heavy matrix math without my laptop fans screaming (even if I discovered it a bit late!).
Core Architecture
The architecture is built cleanly around feed-forward and matrix operations. I decided to abstract a full machine learning model into two modular pieces:
- The Talent: Handles encoding and decoding raw data into formats that are readable for both us and the machine.
- The Network: Handles the raw prediction layers. It sees nothing but the custom
Matrixtype I built from scratch for this library.
The core idea is modular versatility. You can write one powerful network model, then swap out its functionality using different Talents. This allows the same underlying engine to perform completely separate tasks—like classifying image data, and then swapping the Talent so it can predict language tokens.
Demos & Active Testing
Throughout development, I ran numerous benchmarks to verify the math engine:
- XOR Test: The classic benchmark to ensure the network successfully masters non-linear patterns. It passed!
- Space Invaders: A reinforcement learning experiment using SpriteKit where the model learned to play live.
- Bee Simulation: My biggest reinforcement learning environment where the model roleplays a bee earning points for navigating toward flowers and returning safely to its hive.
You can dig into the bee simulation code or view the live interactive terminal build here:
Simulation Code: GitHub - BeeNeuralNetSim
Live Web Demo: Bee Neural Net Terminal Simulator
I've also recently expanded into transformer functionality with SwiftNN Language. This brings modern multi-head self-attention layouts to the framework, letting the models parse data similarly to modern large language models.
Next Steps & Collaboration
This brings us to the launch of Version 1.0.0! My immediate next goals are implementing autonomous agents and expanding the modular model library to cover a wider range of edge-computing applications.
As I keep learning, I also want to eventually explore the intersection of code and organic systems, specifically wetware computing.
Since this is the initial V1 release, the codebase will definitely be prone to edge-case bugs. I am still mastering the advanced algebra and calculus behind the backpropagation gradients, so I would love for the community to look around the architecture!
Please feel free to test the code, suggest math optimizations, or drop a pull request if you spot an error. Thank you for checking it out! ![]()