I would like to ask you how many words should be taken as features in a ML program. For example, if I have 30000 distinct words to make a vocabulary, what would a good number be? I am currently removing stopwords, words with a few characters, numbers; applying lemmatisation; removing punctuation; analysing word frequency to keep the top 50 words. However I do not know if out of 30000 distinct words, 50 would be too low. What would be a good way to determine how many to keep or select?
It depends on many factors: number of instances, number of classes, token/type ratio, etc. A common basic technique in order to avoid having too many words is to discard the ones which appear rarely, for example by discarding all the words which appear in less than 3 documents. Selecting only the top $N$ most frequent words is unusual, even though it's a similar idea. There is a risk to end up mostly with words which appear frequently and don't have a good discriminative power.
The proper way to determine an optimal threshold, for example the minimum frequency $N$, is to run a training/testing experiment for every value of $N$ and select the value corresponding to maximum performance. Note that this experiment should use a validation set different from the final test set in order to avoid data leakage.