I have coded a bit for your problem. Though it need little bit of tweaking, it works fine.

  
      
      GitHub
  
  
    

Goutam-Kelam/PytorchForum 50

PytorchForum - Contains my trials for answering the questions asked in the forum