I am trying to generate an intelligent model which can scan a set of words or strings and classify them as names, mobile numbers, addresses, cities, states, countries and other entities using machine learning or deep learning.

I had searched for approaches, but unfortunately I didn't find any approach to take. I had tried with bag of words model and glove word embedding to predict whether a string is name or city etc..

But, I didn't succeed with bag of words model and with GloVe there are a lot of names which are not covered in the embedding example :- lauren is present in Glove and laurena isn't

I did find this post here, which had a reasonable answer but I couldn't the approached used to solve that problem apart from the fact that NLP and SVM were used to solve it.

Any suggestions are appreciated

Thanks and Regards, Sai Charan Adurthi.

  • 4
    $\begingroup$ Not an answer, but this is called Named Entity Recognition. Searching with those terms may turn up helpful information. $\endgroup$
    – kbrose
    Mar 15, 2018 at 13:50
  • $\begingroup$ Thanks @kbrose, will look into Named Entity Recognition techniques. $\endgroup$ Mar 16, 2018 at 6:56

2 Answers 2


Applying common categorical labels to words is typically called Named-entity recognition (NER).

NER can be done by static rules (e.g., regular expressions) or learned rules (e.g., decision trees). These rules are often brittle and do not generalize. Conditional Random Fields (CRF) are often a better solution because they are able to model the latent states of languages. Current state-of-the-art performance in NER is done with a combination of Deep Learning models.

The Stanford Named Entity Recognizer and spaCy are packages to perform NER.

  • $\begingroup$ Thank you Dr. Brain ! .. but, I want to build a model which takes only a single word or a word of strings and predict whether it's a name, address, etc.. I had tried NER using openNLP by Apache in R. I didn't quite succeed in it. That needed paragraph of words bto make use of grammar and parts of speech, I want to have a model which can even understand things like postal codes, zip codes and state codes. Am going with the right approach here Dr brain ? $\endgroup$ Apr 10, 2018 at 19:51
  • $\begingroup$ You should not think of a having a single general model. You should build a model for each type of element. For example, most postal codes could be found with a regular expression. Also context is king, a model given a single word will do a poor job predicting NER. It is better to have large sections of text. $\endgroup$ Apr 11, 2018 at 1:24
  • $\begingroup$ Hi, @Dr. Brain, I had tried out with text2vec package for R, I had used Glove Word embeddings to check how similar are words. Ex: I have train data of 1000 rows with categories as name, city, state, country etc.., test data with different values. I used text2vec to construct TCM for both train, test data values, then fit glove model to those TCMs and check the similarity of each word in the test data to train data by category using cosine similarity function. But, I couldn't to achieve good accuracy and its even variable every time i generate glove models and check for similarity. $\endgroup$ Apr 11, 2018 at 10:18
  • $\begingroup$ Thanks, Dr.Brian it works if I use sentences to get the context and use NERs. But, I want to do it only using words and see if any model can learn patterns from the words. $\endgroup$ Sep 8, 2018 at 13:20
  • $\begingroup$ Hi Brain, I had used Apache Open NLP to use pre-trained NER models. And yes it works on words as well. $\endgroup$ Aug 27, 2019 at 18:45

You could apply character grams - Intuitively, there might be a huge difference in character set between a phone number and an email address. and then pass the character gram vector to SVM to make a prediction. You could implement this using in sklearn using the below feature extractors.

  1. TfIdfVectorizer(analyzer='character')

  2. CountVectorizer(analyzer='character')

Cross validate on the ngram range and slack variables of SVM to fine tune your model.

  • $\begingroup$ Thanks! @karthikbharadwaj. I am currently working using R, will look into sklearn and see if it works.. $\endgroup$ Apr 10, 2018 at 19:46
  • $\begingroup$ @Sai Charan Adurthi - Please upvote if you found it helpful and accept answers if you found them helpful. $\endgroup$ Apr 10, 2018 at 23:36
  • $\begingroup$ sure, will definitely do it once I check it in Python... $\endgroup$ Apr 11, 2018 at 2:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.