Writing

Let's Build and Train a Perceptron in Pure Swift

How to build one of the most important foundations of modern AI in pure Swift.

The Perceptron is one of the most important building blocks of modern AI. Building one from scratch helped me to really understand how it - and many aspects of modern AI - actually work.

I will update this post soon, but for now I’d like to simply share three GitHub repos:

  • PerceptronViz is a SwiftUI macOS application that visualizes how a Perceptron works: Both the inference and training. It was created entirely by Claude Code and OpenAI Codex. Screenshot of PerceptronViz
  • PerceptronPlayground is an Xcode Playground that shows how to build and train a Perceptron in pure Swift.
  • PerceptronFace is a fun commandline Swift application that re-creates the original Perceptron application from the 1950s: Classifying a photo of a human face as either male or female. Screenshot of PerceptronFace

Have fun playing with these and I hope they help you to understand how a Perceptron works.