Algorithms for Matching Similar Articles – Logic and Implementation

algorithmslogic

I am creating a site where people can write on a niche topic. It is almost like a blog, however the area as I mentioned is a small niche with (hopefully) passionate users.

I want a functionality where once someone posts his article. People with similar experience can be notified, so that they can read about. Now my question is – how to determine similar articles? I know that tagging is a way – just like here in stackexchange and I will be implementing it. But suppose people do not tag, or tag incorrectly, the whole user experience will be hard to indulge in.

Does anyone have any pointers on how to match up articles other than the tagging method?

Best Answer

I am currently undertaking a similar (although more generic) project with my lab. As such, I want to warn you that this feature is a rabbit hole that can get very complicated very quickly. The first thing you need to do is think about your users and your goals and decide what's "good enough" or you will spend a lot of time developing a feature that, in the grand scheme of your site, might not be that important.

Basically you want some sort of information retrieval system. Think a mini-Google but not nearly as complex. First you need to decide how you will define similarity between articles (a metric). This will be handled in your preprocessing. Generally your actually comparison will be the same no matter what your metric (typically cossine similarity).

Defining a Metric

First, you need to decide what makes articles similar. There are two main approaches: looking for similarities in article topics or looking for similarities in article text. Topics will give better results but text is easier to implement.

Similarity by Topic

As mentioned several times, the easiest way to implement this system is allowing specify topics through author-specified tags. You would then search for articles with large overlaps in tags. If the tags are numerous and fine grained enough then this should give the best results.

The disadvantage is that you need to put a lot of thought into what the tags are to ensure you have coverage, clarity, and a lack of redundancy. If you take the Stack Exchange approach of letting users create their own tags then you can increase coverage but you need to moderate the tags to maintain the clarity/lack of redundancy. However, the greatest drawback of this approach is that you are trusting users to appropriately tag their posts. SE gets around this problem by letting other users edit and make suggestions for the tags.

You can get even better results if you tag topics at the sentence or paragraph level. It gives a better representation of which topics are more important in an article but it's more work. As the tagging scope gets smaller, the complexity of this task becomes exponentially more difficult.

What about an automated solution to take the work load off the users? Automatic Topic Identification is something that has been studied a lot. I'm not an expert at it but I suggest you read a few papers and decide if you feel these solutions are mature enough to give reliable results. My concern with this approach is that since you admit your domain is niche you might have a hard time finding an out-of-the-box solution and will need to implement the topic identifier yourself. At that point you might as well just do text-based similarity because it will be much easier and out-of-the-box solutions exist.

Similarity by Text

In this approach instead of comparing topic tags, you compare the actual words in the article. The advantage is that the preprocessing is much easier to accomplish. The disadvantage is that it assumes that similar text means a similar topic, which is not always the case.

Making it Work

In general, whichever metric you choose you will end up with a vector representing your articles. Maybe the vector is of word frequencies or of topic tags. You now need to compare the vectors for your articles to see which are similar.

The Stanford Natural Language Processing Course offered on coursera.com is a good introduction to Information Retrieval (specifically the Week 7 lectures). Keep in mind that the solutions presented in those lectures are relatively basic, but it's a good start.

I would heavily suggest trying to find an out-of-the-box implementation here. Failing that, using a toolkit like Apache Lucene will greatly simplify your development.

Now you need to test out a bunch of term weighting algorithms and see which one gives the best results for your data. TREC is a competition to find better and better weighting algorithms. Check the proceedings on their website to find discussions of newer, more accurate weighting algorithms.

Related Topic