Skip to main content

What it takes to create a news classification app?


Fooyo recently received a request to make a news classification app. It sounds quite challenging and interesting. We feel excited to solve hard problems. The request is a bit too urgent, but we managed to deliver it with good feedbacks from the client.

The requests is to crawl news data from various news sources, delete the duplications, classify the news into different categories and then display them on a mobile app.

It sounds quite straightforward, however, each module actually involves quite hard components that need deep knowledge/understanding to solve them.

In summary there are four components:
1. A web news crawler
2. A duplication deletion mechanism
3. A news classification mechanism
4. A mobile app which interacts with the server

A web crawler is used to crawl news list data and the corresponding page links. The web contents of the page links are then saved into the server. There are quite a few good open sourced crawler out there, e.g., scrapy.  Some sites may have anti-crawler feature which will block IPs when they crawl too much. Thus we may need different proxy servers to crawl the data when some are blocked by the news site.

A duplication deletion mechanism firstly need a good text parser which involves the following tasks:

1. Texts need to be tokenised into list of words(This step would be important for languages like Chinese).
2. Each word needs to be be stemmed(say ran, running and run are all stemmed into run).
3. Remove the stop words(a, to, the, and, etc)[may not be a necessary step], punctuations, lower case, lemmatising, etc.

After parsing the text data, we need to calculate the text similarity to remove the duplications: cosine similarity, Jaccard similarity coefficient, etc.

To categorize the news into different groups, we need to adopt suitable text classification algorithms, e.g., Naive Bayes , Tf-idf, etc. Some recommended python libraries includes: nltk, scikit-learn, etc.

To transfer the data into the client app, we also created a data storage mechanism which saves the crawled data into database and then gets retrieved according to category&page number.

The final app is like the following, with a news list tableview page and and a news detail page. The category tabs are displayed at the top scrollview, which makes the experience more user friendly.

There are a lot of challenges. One of the challenge occurs when we use our news duplication deletion algorithm, the complexity is high when we need to compare one article with every others(n^2). If the similarity comparison itself is not efficient enough, the whole thing would be very inefficient. Imagine there are 1,000 articles, then we'll need 1,000,000 comparisons. If every second can process 1000 comparisons, then it can take 17 minutes to process the whole thing. When it's less efficient, that would be a disaster. Initially, we compare the whole text body. It took so long time. We switched to compare title which is much more efficient. The result turns out to be OK.  A better strategy would be to process the text body to abstract the top N keywords and then compare the keywords instead of the whole article.

The urgent task was not confirmed until 3 days before the deadline. It looked like an impossible task to finish in such a short time at this complicity level. Thankfully, three out of four developers in our team learned NLP/Machine learning and we confirmed it doable. Our team worked really hard staying overnight and together we made it happen. Thanks for the help from many open source communities for providing very good NLP/Machine learning libraries. Also a special thank to a friend from Tencent who gave us nice guidances in the very early stage.

This article is a personal sharing and there may be some parts which are not academically rigorous, please feel free to point out the parts which you find anything improper. Thanks!




Comments

Popular posts from this blog

InnovFest 2015

I attended the innovFest 2015 event. It was quite eye opening. Besides the booth, some topics in the forums also interested me. The first topic I joined was the Kopi Chat with Yossi Vardi, a famous Israeli entrepreneur and investor. He is straightforward and humorous. When talking about the most important reason why people wake up with a great idea but ended up sleeping without executing anything, he collected answers from the audiences. One answer pretty much fitted his appetite-- "People fear about losing faces". He shared his opinion with the quotes from Theodore Roosevelt, “It is not the critic who counts; not the man who points out how the strong man stumbles, or where the doer of deeds could have done them better. The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood; who strives valiantly; who errs, who comes short again and again, because there is no effort without error and shortcoming; but who does actually st...

Time Goes By, So Fast

It's been a week since the last blog entry, time goes by so fast. This week's highlights: 1. Rethought about career development. http://www.douban.com/note/276145923/ 2. Treated my friends a traditional Shaoxing meal. 3. Started to learn Ruby on Rails. http://guides.rubyonrails.org/getting_started.html 4. Started to read the book "Simple and Usable Web, Mobile, and Interaction Design" by Giles Colborne. 5. Recorded some vocals. http://site.douban.com/shaohuan 6. Watched this Ted speech:  http://www.ted.com/talks/angela_lee_duckworth_the_key_to_success_grit.html 7. Followed Ahbei(founder of Douban) on Zhihu(Chinese version of Quora). 8. " 我认为世界上不存在一流的人才,世界上只有存在一流的人才一定是学习能力,谦虚,把自己当平凡的人" --马云(Jack Ma)

About Memory

Today, I went for an Evernote Sharing event in an incubator named Blk71. The event is more on user feedbacks and marketing. There are three thoughts to be highlighted. 1. Attending this kind of entrepreneur events is a very good approach for reaching out more contacts. Many people who have their own businesses or plan to build their own startups will come and attend this kind of events.There is one entrepreneur who shared his experience of how he used Evernote to design his own app. He got the chance to advertise his own app while sharing the experience. Another software developer shared how his company integrated Evernote's public API. He indeed shared a lot more on his own product rather than Evernote. During the break, I talked with two entrepreneurs. One is a NUS computer engineering alumni. He is now running his own retailing company on baby products. It works well as there weren't competitors in Singapore when he first started his business. Though there is no relations...