I am looking to build a model for specific news and blog articles which merge fashion with patterns in biology. I have 35 websites that I read daily (it is exhausting). I am wondering how to approach creating such a model so that I can send articles to it daily and it can predict whether or not they deserve reading (ie relevant vs irrelevant). For example, in a perfect world I send it 230 articles of which 12 are returned as relevant based on previous training and testing articles. Assuming all 12 are relevant I save them to the training dir and recompile to strengthen the model.

After reading Deep Learning with Keras I was hoping Chapters 5 and 6 on Word Embeddings and RNNs(simple, LSTM, GRU) would point me to how to develop such a model. I was also reading how to implement a CNN for text classification but cannot seem to construct a basic conceptual framework for how to start with a few articles and adding to the training data every day to strengthen the model.

Is there a term for this type of strategy? Has it been done in some form on Kaggle, Github, etc?


1 Answer 1


In a broader sense, what you're referring to here is known as text mining. This is where information is extracted from text according to certain criteria in order to form specific patterns and meanings, etc.

How you would go about implementing this depends on the criteria you have in mind.

For instance, let's suppose you have a blog article in text format (let's call it filepath.txt for this example).

You decide that you wish to sort words into specific categories. For instance, you could categorise the keywords hotel, flights, countries, as travel, i.e. each incidence of the three words would be replaced with data. Let's assume data is a relevant category of interest. Any article that would fall under a travel category would be included in your articles of interest.

Using Python, you can then scan your file and use filedata.replace to replace your keywords with categories:

# Read file
with open('filepath.txt', 'r') as file :
filedata = file.read()

# Replace keyword
filedata = filedata.replace('How ', ' ')
filedata = filedata.replace('Why ', ' ')
filedata = filedata.replace('of ', ' ')
filedata = filedata.replace('to ', ' ')
filedata = filedata.replace('you ', ' ')
filedata = filedata.replace('all ', ' ')
filedata = filedata.replace('and ', ' ')
filedata = filedata.replace('be ', ' ')
filedata = filedata.replace(' a ', ' ')
filedata = filedata.replace(' for ', ' ')
filedata = filedata.replace(' in ', ' ')
filedata = filedata.replace(' is ', ' ')
filedata = filedata.replace(' the ', ' ')
filedata = filedata.replace(' about ', ' ')
filedata = filedata.replace(' an ', ' ')
filedata = filedata.replace('Data', ' data ')
filedata = filedata.replace('Python', ' data ')
filedata = filedata.replace('R', ' data ')
filedata = filedata.replace('machine', ' data ')
filedata = filedata.replace('Linux', ' data ')
filedata = filedata.replace('technology', ' data ')
filedata = filedata.replace('flights', 'travel')
filedata = filedata.replace('countries', 'travel')
filedata = filedata.replace('hotel', 'travel')
filedata = filedata.replace('analytics', 'data')
filedata=  filedata.replace('CNN', 'news')
filedata=  filedata.replace('weather', 'news')
filedata=  filedata.replace('Trump', 'news')
filedata=  filedata.replace('market', 'business')
filedata=  filedata.replace('entrepreneur', 'business')
filedata=  filedata.replace('financial', 'business')

# Write to file
with open('filepath2.txt', 'w') as file:

You could then use a library such as stringr in R to see how frequently the category (which would have the keywords replaced with the category) appears:

WordList <- str_split(readLines("filepath2.txt"), pattern = " ")

e.g. if the category appears X number of times or more, then the article is deemed relevant.

This is just one example of how you could use text mining. Again, much of it hinges on your specific criteria and how you would go about determining relevancy. But that's one way you could approach it.

  • $\begingroup$ +1 Thank you for your time on this! What I am more interested in is limiting feature engineering for multi layer perceptrons if possible via CNN or RNN: datascience.stackexchange.com/questions/1253/… $\endgroup$
    – Chris
    Commented Jun 1, 2017 at 19:09
  • $\begingroup$ @Chris: If you only have a few hundred examples of the kinds of articles you want to classify into read/skip, then you may not have enough data to pursue a CNN or RNN model. The deep models require a lot of data to train. There are other approaches than suggested in the answer - for instance a bag-of-words based simple classifier (SVM or logistic regression) might be a good start. $\endgroup$ Commented Jun 1, 2017 at 21:04
  • $\begingroup$ @NeilSlater thank you! I will absolutely look into those now. $\endgroup$
    – Chris
    Commented Jun 1, 2017 at 21:16

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.