there is a very nice introductory tutorial on GitHub : https://github.com/spro/practical-pytorch/blob/master/seq2seq-translation/seq2seq-translation.ipynb 21
You can also see a more efficient implementation of attention on the GitHub page of opennmt: https://github.com/OpenNMT/OpenNMT-py/blob/master/onmt/modules/GlobalAttention.py 21