My current implementation is fairly similar to that, but I found that it dramatically slows down the time per batch to calculate all the sums individually during training. I am also concerned about stability when implementing softmax manually (is that an unnecessary concern?). Any suggestions on ways to optimize?