u/xerrs_

▲ 41 r/Zig

I wrote a PNG decompressor and neural network from scratch for MNIST

A year back, I read a lot about people implementing a NN from "scratch", and then using PyTorch or other tools along the way. Wondered, what it would be actually like to implement it from sticks and stones (zig). Well, there goes my sanity lmao.

I have attempted this a while back, and finished the PNG decompression part almost a year ago, but the neural network never worked properly, which is why I abruptly quit the project for good. Came back two days ago; hours of debugging later, my neural network finally trains correctly on MNIST.

Very proud about the fact that I built the entire stack myself in Zig:

PNG Decompression, MNIST PNG parsing, matrix implementation, feedforward, backpropagation, gradient descent (with heavy inspiration AND help from sebastian lague).

No ML libraries, no NumPy, no PyTorch.

Math was annoying, but a lot of the stuff (such as partial deriviatives) were taught to me in school during the time, so that was alright. other issues, such as tiny implementation bugs like

- weights not actually updating

- wrong indexing dimensions

- hidden layer gradients using incorrect inputs

-sigmoid saturation from bad initialization

were a lot more annoying.

At one point the network would appear to learn smth depending on RNG seed, which turned out to be a mix of actual bugs + terrible weight initialization (mostly still dependent on luck cuz Xavier Init resulted in NaN output values...).

After fixing the training pipeline, it now reliably learns all digits 0-9 from MNIST.

Zig was probably the hardest possible language choice for this, but also the reason I understand it now.

The code is open-source over here;

https://github.com/XerWoho/Triarch

There are not any docs in docs/. My brain back then was solely focused on learning PNGs as it appears lol. I would suggest reading through the code, though it is really old (0.14.0), because it was a big learning journey for me, and could be for you to. Though this is what would basically happen if you would execute it;

https://preview.redd.it/a87eob7gir1h1.png?width=833&format=png&auto=webp&s=74147f5b6a35b307264290798bf329858168bbf0

(correct guesses / total attempts). (ignore the fact that the correct guesses are larger than total attempts... I wrote / 100 instead of / 1000... gotta stop using magic numbers)

Would love feedback, as this was total work of about 7-8 months (excluding the long break), though be nice to me, as the PNG decompression code (as mentioned), is almost older than me.

reddit.com
u/xerrs_ — 4 days ago

Everyone says 'track everything'. So founders end up with dashboards full of:

> 40 charts

> retention curves

> funnels they dont act on

And somehow… still no clue why users leave.

I hit that wall myself. I tried the usual stack; event tracking, page views, heatmaps. Looked impressive, felt productive… but it didnt answer the only thing that mattered:

"What is this user actually trying to do?"

Thats what im trying to solve with KiteFlow.

Instead of tracking anonymous noise, I focused on identified users + intent signals. So I dont get; "User clicked button X", but; "This specific user is trying to onboard, gets stuck here, and never comes back."

Kinda changed a lot; stopped optimizing for vanity metrics, started spotting real drop-offs tied to real people, literally follow a users journey and see where things break.

Trying to answer a different question entirely: "Why are users doing what they’re doing?"

Thats what I built KiteFlow around. Early insight I didnt expect:

Most of my visitors hit the landing page… click 'Get Started'… and disappear.

Classic funnel tools would show a drop-off. I see who did it, what they did before, and patterns between them.

I’m not pretending this replaces everything. If you need deep aggregate analytics, tools like GA/PostHog are still solid.

But if you're early-stage and still figuring out user behavior, I think most people are overcomplicating it.

Curious if anyone else ran into this? Or am I just reinventing something that already exists?

If you want to check it out;

https://kiteflow.dev

reddit.com
u/xerrs_ — 25 days ago

Everyone says 'track everything'.

So founders end up with dashboards full of:

> 40 charts

> retention curves

> funnels they dont act on

And somehow… still no clue why users leave.

I hit that wall myself. I tried the usual stack; event tracking, page views, heatmaps. Looked impressive, felt productive… but it didnt answer the only thing that mattered:

"What is this user actually trying to do?"

So I am trying something different.

Instead of tracking anonymous noise, I focused on identified users + intent signals. So I dont get; "User clicked button X", but; "This specific user is trying to onboard, gets stuck here, and never comes back."

Kinda changed a lot; stopped optimizing for vanity metrics, started spotting real drop-offs tied to real people, literally follow a users journey and see where things break.

Trying to answer a different question entirely: "Why are users doing what they’re doing?"

Early insight I didnt expect:

Most of my visitors hit the landing page… click 'Get Started'… and disappear.

Classic funnel tools would show a drop-off. I see who did it, what they did before, and patterns between them.

I’m not pretending this replaces everything. If you need deep aggregate analytics, tools like GA/PostHog are still solid.

But if you're early-stage and still figuring out user behavior, I think most people are overcomplicating it.

Curious if anyone else ran into this? Or am I just reinventing something that already exists?

reddit.com
u/xerrs_ — 25 days ago