Saturday, February 13, 2010

If you're searching remember your TF-IDF

Some people seem to be very good at searching the web, others seem to be very poor at it. What differentiates them? I think it's unconcious knowledge of something called TF-IDF (or term frequency-inverse document frequency).

If you clicked through to that Wikipedia link you were probably confronted by a bunch of mathematics, and since you are reading this you probably hit the back button as quickly as possible. But knowing about TF-IDF requires no mathematical knowledge at all. All you need is some common sense.

Put yourself in the shoes of a search engine. Sitting on the hard disks of its vast collection of computers are all the web pages in existence (or almost). Along comes a query from a human.

The first thing the search engine does is discard words that a too common. For example, if the search query contained the word 'the' there's almost no point using it to try to distinguish web pages. All the English ones almost certainly contain the word 'the' (just look at this one and count them).

With the common words removed the search engines goes looking for pages that match the remaining terms and ranks them in some useful order (a lot of Google's success is based on their ranking algorithm). One thing the search engine can take into account is how common the remaining words in the search query are.

For example, suppose the query was "the first imagineer". The search engine ignores 'the' and looks for pages containing "first imagineer". Obviously the results returned need to contain both words, but 'imagineer' is special: it's a rare word. And relatively rare words are a human's best searching friends.

A rare word allows the search engine to cut down the number of pages it needs to examine enormously, and that ends up giving the user better results. The ideal rare word is one that appears almost only on the sort of pages the end user is looking for, and appears in those pages frequently.

In nerdy terms 'appears in those pages frequently' is the TF (or term frequency), and 'almost only in the sort of pages end user is looking for' is the IDF (inverse document frequency).

Since 'imagineer' is a rare word, if the search engine finds a page on which that word occurs many times it's more likely to be relevant to the person searching that on a page where 'imagineer' appears only a few times.

Since 'first' is fairly common it's contribution to the search results is less clear. If 'first' appears many times on the page, but 'imagineer' only once then it's likely that the page is of lesser interest.

When you are searching give a few seconds thought to TF-IDF and ask yourself 'what words are most likely to appear only in the sort of pages I am looking for?' You'll likely get to where you wanted to go much faster that way.

PS If you find out who the first imagineer was, drop me a line.


quesne said...

"the first imagineer" returns a different resultset than "first imagineer", so the tokenizer is probably a bit more subtle.

marksany said...

Since imagineer is a Disney word, the first imagineer must have been Walt Disney.

Michael said...

Well, after doing a Google search on 'first imagineer', the 4th hit on the first page of results linked to a book Walt Disney’s Imagineering Legends. It states that the very first Imagineer was Walt himself.

I like the blog post. I've unconsciously done this ever since becoming wired to the Internet, but I've never known it had an actual name. Thanks for filling in a blank I didn't even know existed!

ColinD said...

First result for first engineer from Bing Roger E. Broggie

ColinD said...

Oh dear! ...first imagineer...wipes egg of face :]

J said...

As others have said, Walt Disney himself was technically the first Imagineer. The second was Harper Goff, an artist who is credited in the book "Disneyland: Then, Now, and Forever" as having created the first concept rendering of "Mickey Mouse Park" in 1951.