Fix for numerical instability in softmax function
Fix for numerical instability in softmax function

Before this commit, we used a naive implementation of the softmax
function which was prone to overflowing with large coefficients. This
was fixed the solution suggested in

http://stackoverflow.com/a/34969389

Thanks Trevor!

lwtnn/lwtnn,jwsmithers/lwtnn,jwsmithers/lwtnn,lwtnn/lwtnn,jwsmithers/lwtnn,lwtnn/lwtnn