Maybe take a look at @spro 's seq2seq
http://pytorch.org/tutorials/intermediate/seq2seq_translation_tutorial.html#training-and-evaluating 246
Teacher forcing and that kind of stuff is used a lot in seq2seq, I first learnt about it from, Wojciech Zaremba, Ilya Sutskever’s
Learning to Execute 69
If you’re comfortable with Torch, then I think you’d have a lot of fun playing around with that code, IT’S A CLASSIC 
https://github.com/wojciechz/learning_to_execute 83