Tuesday, April 26, 2011

Yelp Coding Challenge



I really like this programming challenge from Yelp.  You know that "Search for" box on Yelp?  You do a search and then you get a bunch of review fragments.  The problem asks you to implement production level code to implement the algorithm that extracts the most meaningful fragment from a review (given the search terms) to display in search results - the yellow highlighted bits on the right.

What I love about this problem is that it asks for production level code, and the problem is much deeper than it might appear at first glance.  There are also many different ways to skin this cat and there is no "right answer".

When I implemented this, I had to see how my code compared with the production level code on Yelp, so in the source code (see link below), you'll see some test code that compares the two.  I ended up preferring the results that my code produced in a number of cases.  Here's one example.  What do you think?

Here is the original review in its entirety:
I've only been here once, but that one visit was enough for me to know that the pizza here is awesome. It's as good as it gets. It's just sad that they don't have a joint here in Cupertino, but then again I'd be willing to drive to SF from time to time just to enjoy their pizza. The time I went there, the restaurant was bursting with people. We had to wait for at least half an hour or even more, can't really recall. But let me tell you, it was worth the wait. We had the deep dish pizza, the thin crust pizza, the chicken wings and as we plow through the first round of pizzas, we realize that we want more, so there goes the second round. Another round of the deep dish spinach-feta cheese-mushroom pizza and other yummy stuff, we were good to go. I highly recommend the spinach-cheese-mushroom deep dish pizza.  I would definitely come back and try their other pizzas. Aaaaahhhhh who's down to go grab some little star pizzas with me right now!!! haha four thumbs up (including my two toes hahaha) That's how good this place is! Oh and make sure you go with the right company - that will make the experience a golden one =D
Here is the review fragment that Yelp currently produces:
can't really recall. But let me tell you, it was worth the wait. We had the deep dish pizza, the thin crust pizza, the chicken wings and as we plow through the first round of pizzas, we realize that
Here is the review fragment that my code produces:
We had the deep dish pizza, the thin crust pizza, the chicken wings and as we plow through the first round of pizzas, we realize that we want more, so there goes the second round. I highly recommend the spinach-cheese-mushroom deep dish pizza.
Which review fragment do you like better?

Download a ZIP containing the source code to my solution to this problem.


Here is the original problem statement:



For yelp search we need to highlight document snippets that match a query. For
example a yelp search for [deep dish pizza] returns documents that match the
query as well as highlights that try to show why the document is relevant.
(http://www.yelp.com/search?find_desc=deep+dish+pizza&ns=1&rpp=10&find_lo
c=San+Francisco%2C+CA ). Note that highlights (1) highlight all the words in
the query and (2) are not necessarily the full document (they are
instead only a relevant snippet).
For this question you will write a function that finds the most relevant snippet for
a document and highlights all the query terms that appear in the snippet
(basically the highlights you saw on the linked search page).
It is up to you to define what constitutes a good snippet and how big the snippets
will be.
Indicate highlights by surrounding the text to be highlighted with [[HIGHLIGHT]]
  .[[ENDHIGHLIGHT]] ...
For instance "Little star's deep dish pizza sure is fantastic." would look like "Little
star's [[HIGHLIGHT]]deep dish pizza[[ENDHIGHLIGHT]] sure is fantastic."
internally.
One highlighting example might be:
highlight_doc("I like fish. Little star's deep dish pizza sure is fantastic. Dogs are
funny.", "deep dish pizza") -> "Little star's [[HIGHLIGHT]]deep dish
pizza[[ENDHIGHLIGHT]] sure is fantastic."
Note that your highlighter doesn't have to have the exact same result on this
example, since *you* are defining what a good snippet is.
The solution can be in any language (but python is preferred). Attach your native
source files (.py, .java, .cpp, etc...). Hint: Write your code as if your peers may be
maintaining your code. Your code should be as if it were for a production
environment. And don't forget to include unit tests!
I would like a function with the signature similar to the following:
def highlight_doc(doc, query):
"""
 Args:
      doc - String that is a document to be highlighted
 query - String that contains the search query
 Returns:
 The the most relevant snippet with the query terms highlighted.
"""

24 comments:

  1. Hi, interesting problem, I saw your code but couldn't find MatchScore.java class. Can you please provide that.

    ReplyDelete
  2. This comment has been removed by the author.

    ReplyDelete
  3. There are also many different ways Buy Yelp Reviews to skin this cat and there is no "right answer".

    ReplyDelete
  4. Just loved your analysis , you coded in professional way bdw did you get offer from yelp or do you work work at yelp ? also please share other question if you have ??

    ReplyDelete
  5. This comment has been removed by the author.

    ReplyDelete
  6. While doing this, it is important to note that the end of your marketing plan cannot be determined the followers’ startup, since the more you buy followers, the additional boost you give to your twitter accounts and business.Buy Targeted Twitter Followers

    ReplyDelete
  7. Buy Google Reviews is a new era of advertising and service in which your business/brand is defined by those who experience it.Get Google Reviews & Rating

    ReplyDelete
  8. Over 90% of contributors claimed that online positive reviews influenced their purchasing decision, and 85% said their decision was influenced by minus reviews.Buy Google Reviews

    ReplyDelete
  9. Our challenge is in imitation of spread you page decennial by a helpful amount on Google accounts..Buy 5 star Google Reviews

    ReplyDelete
  10. Google reviews can either be positive or negative for your business, stores, office, restaurant, service or requirements. Google is the largest search engine, as well as the most efficient advertisement website.Buy 5 star Google Reviews

    ReplyDelete
  11. Google allows users to write reviews directly on the business’s Google or Google map listing. Since Google reviews are obviously favored by the search engine and show up upon every relevant result, the best place to start a business firm is getting involved with Google Reviews.
    Buy 5 star Google Reviews

    ReplyDelete
  12. The key features of this service are that all page reposts are permanent). Second, you’ll get 100% satisfaction assurances. The service delivery time is 10 hours. No programs, bots, or software are used in this service. When you buy this service, it’s a 100 %stable and safe account, with real high-class campaigns as well as 100 % safety and security, as well as customer satisfaction. With this service, you’ll save time and effort. You’ll experience improvements within 24 hours.
    Buying SoundCloud Plays

    ReplyDelete
  13. Google To FACEBOOK people are sharing their experiences on all, and what they say has a huge impact. Over 90% of contributors claimed that online positive reviews influenced their purchasing decision, and 85% said their decision was influenced by minus reviews.Buy Google Reviews

    ReplyDelete
  14. SoundCloud has given a significant career toward numerous new performers. It has given them a chance toward showcase their talent in all above the world.Buy SoundCloud Plays Cheap

    ReplyDelete
  15. One of the reasons why artists should buy SoundCloud plays is acquiring intrinsic inspiration.Buy Real SoundCloud Plays

    ReplyDelete
  16. Delivery time is ten hours before you know it your work is online waiting for likes and followers. There is nothing like wasting time unlike other social media. Buying Google reviews delivers the result very fast. Buy Google Star Reviews

    ReplyDelete
  17. Delivery time is ten hours before you know it your work is online waiting for likes and followers. There is nothing like wasting time unlike other social media. Buy Real Google Reviews

    ReplyDelete
  18. Top Promoter This is really a nice and informative, containing all information and also has a great impact on the new technology. Check it out here: SoundCloud Promotion

    ReplyDelete
  19. Top SEO Work Excellent information on your blog, thank you for taking the time to share with us. Amazing insight you have on this, it's nice to find a website that details so much information about different artists. Monthly SEO Service

    ReplyDelete
  20. I read that Post and got it fine and enlightening. If you don't mind share more like that... Buy SoundCloud Plays

    ReplyDelete
  21. Buy Soundcloud Service

    This is my first time i visit here. I discovered such a large number of fascinating stuff in your online journal particularly its dialog. From the huge amounts of remarks on your articles, I figure I am by all account not the only one having all the satisfaction here! keep doing awesome BUY GOOGLE PLUS REVIEWS

    ReplyDelete