karpathy / micrograd

A tiny scalar-valued autograd engine and a neural net library on top of it with PyTorch-like API
MIT License
10.5k stars 1.52k forks source link

added tanh nonlinearity function to engine.py #74

Open Naren219 opened 4 months ago

Naren219 commented 4 months ago

i found out that tanh wasn't implemented in the repo so I copied Karpathy's code from the video to the value class as a method.

using this nonlinearity function should allow you to train better with negative numbers (found this out the hard way by trying to replicate the video dataset with relu instead and my loss was so high).

hope this helps! -naren

conscell commented 1 month ago

This implementation is numerically unstable. For large x e.g. x=1000 it will cause the following error: OverflowError: math range error