Based on Anaya-In-Matrix## Wenlong Lyu’s jupyter notebook. The opt.zero_grad() was essential. Note batches were not used…this is a small  problem.
Also the translation from/to numpy was a pain in the ass!
Base in part on https://gist.github.com/santi-pdp/d0e9002afe74db04aa5bbff6d076e8fe 27