Implement Train and Tag. Fix a NaN bug and gradient
direction bug with tons of log statements and assertions.