What loss function to use for imbalanced classes (using PyTorch)?
What kind of loss function would I use here?


Cross-entropy is the go-to loss function for classification tasks, either balanced or imbalanced. It is the first choice when no preference is built from domain knowledge yet.


  This would need to be weighted I suppose? How does that work in practice?


Yes. Weight of class $c$ is the size of largest class divided by the size of class $c$. 

For example, If class 1 has 900, class 2 has 15000, and class 3 has 800 samples, then their weights would be 16.67, 1.0, and 18.75 respectively. 

You can also use the smallest class as nominator, which gives 0.889, 0.053, and 1.0 respectively. This is only a re-scaling, the relative weights are the same.


  Is this the right approach to begin with or are there other / better
  methods I could use?


Yes, this is the right approach.

EDIT:

Thanks to @Muppet, we can also use class over-sampling, which is equivalent to using class weights. This is accomplished by WeightedRandomSampler in PyTorch, using the same aforementioned weights.