# Distinguish randomly generated texts from reasonable for human texts [closed]

I have strings short texts of 2 types: '23jd2032n0d2mn', 'fn830n30rn83', 'fhui29n4ok', 'qn4foml', ... and 'sweetie23', 'king3prussia', 'maryjesus', 'lovedog4and_kitties', ...

Is there a way to distinguish one type from another?

I've tried to vectorize texts with word2vec and classify on these vectors with xgboost, but I didn't succeded to achieve got F1-score.

You could train a character-level language model, e.g. an LSTM, on the real short texts, and use the perplexity as the signal to know whether a piece of text is real or not.

In order to find an appropriate perplexity threshold, you can have a look at the distribution of perplexities over a validation holdout dataset.

UPDATE: There are multiple implementations of language models. For "classical" options, you can go for KenLM or if you have GPUs to train the model, you can use fairseq. Just remember to prepare your text to have character-level tokens (normally you just need to have a space between every letter).

• I'd defintely try this approach but first I need to learn it better. If u have any links to read on this topic, could u share with me, please – Marcel Mars Sep 22 at 16:53
• I added an update to the answer with a couple of suggestions about language model implementations. – ncasas Sep 22 at 17:00
• Also, if you found the answer useful, please consider marking is as correct. – ncasas Sep 22 at 17:00

Assuming that the "human readable" texts are more likely to contain actual words, you could count the number of dictionary words that occur in each.

You could use Wordnet for example.

The number or proportion of word hits, and their length, could be features for a model or maybe it would be enough with a simple cutoff rule.

You might want to restrict the word list to the most frequent words in the language you're working with.

• that might work, but 2nd type of texts may contain human readable words with mistakes, numbers, or words without wovels, or names with special characters without space, etc – Marcel Mars Sep 22 at 16:51

Try making features like vowel_count, consonant_count, digitcount , vowel_density(vowel_count/total_length_of_words)

Another wild thing -
split the strigns with numbers and _ using regex and try to see if they are english words or not, use a pretrained model like spacy.english or nltk.words to check, make a column representing english words count if any.


edit -

also find the vowel index from last vovel index(relative index) (after removing nonnumeric characters)and eg -
A) maryjesus -> a(1, because 1st index), e(5th index - index of a(1st index) = 4), u(2)

B)qn4foml-> o(4)


because in english words , vowels ties the consonant together to form words, therefore an english words vowel's relative distance should be quite less.

• This looks like an interesting project, what is this for ? I'd like to collaborate if you need help. – Madhur Yadav Sep 16 at 19:05
• You can also add an IS_NER column and check if the words after splitting are NERs or not. – Madhur Yadav Sep 16 at 19:10
• thanks for ideas, Madhur! I'll try and tell you the results – Marcel Mars Sep 16 at 19:21
• Character based heuristics helped. I succeded to reach 0.8 F1-score on cross validation. I've used both vectors and manually created features. But I will try LSTM-approach as well. – Marcel Mars Sep 18 at 10:18
• great, keep us posted, also if its a personal project then do share it in github – Madhur Yadav Sep 18 at 10:21