Highly Imbalanced dataset fro classes more than 200 I have a text dataset where I need to train a classifier to classify the titles into categories. The dataset shape is more than 575000. There are 256 target classes here. The problem is the dataset is highly imbalanced. For target X1 it has 171793 records, X2 has 101575,........Xn-1 has 2, Xn has 2 records. Consider the target value counts are in decreasing order. 

To handle with the imbalanced dataset, oversampling and undersampling works for multiclass say 3 classes. But in my case, there are 256 classes. How do I sample my dataset in this situation? How do I sample the dataset in a way so my model is stable for all the targets? 

Do I have to remove the classes which have value counts 2 - 100 from this dataset? and apply undersampling/oversampling. Is there any approach to handle these type of situation?
The situation you describe is a few-shot learning problem: you have a lot of classes and only a few examples for some of them.

Similarity metric learning with siamese neural networks is well suited for this task. The idea is to learn a general similarity metric between examples, then classify new examples as belonging to the class of the "closest" sample from the training set. It seems a bit complex but it's probably the best way to learn "across" classes. 

The link I've shared above is applied to an NLP problem so should be able to reuse it fairly easily.