yes, this is a good way to handle text loading.
You can also look at the torchtext package for more complex examples:

  
      
      GitHub
  
  
    

pytorch/text 202

Data loaders and abstractions for text and NLP. Contribute to pytorch/text development by creating an account on GitHub.