One-hot encode before or after taking a small sample?
You should definitely one-hot encode the target before you take a smaller sample. Then it won't be a problem.
I'm working for the first time with a relatively large dataset (50gb). 
There are 30,000 classes, and 100,000 labels (skewed data).
I'm trying to train my CNN model on 10% of the data for testing. 
I have a problem for one hot encoding the labels.
The labels go from 0 to 29,999 (integers), so in my 10% dataset, I have an array of 10,000 labels with random values from 0 to 29,999. 
What happens is that keras to categorical creates a matrix of vectors with length = max(labels). 
For example, if in my 10% dataset, the largest label is 25,000 then the one encoding will result in a shape (10000, 250000) which is wrong. Because I only have 20 labels in this sub dataset.
How can I do to one hot encode this labels ?
I'm not sure if I was clear enough, first time working on large data got me a bit confused.