Douwe Osinga's Blog: September 2016

Thursday, September 29, 2016

Semantics, Maps and Word2Vec

This week I published a new project: worldmapof. It uses Word2Vec to calculate the distance between a given word and the name of a country and then colors each of the countries according to that distance. The results are often what you expect with some interesting surprises thrown in. You want to see Colombia and Ethiopia light up for coffee, but wonder why Greenland also features prominently only to learn one Google search later that Greenlandic coffee is a thing.

Coffee projected on a map
Word2Vec analyses large amounts of text - in this case from Google News. By building a model to predict a word given a context, it associates a 300 dimensional vector with that word. The interesting thing about this vector is that it has some semantic meaning. If the distance between two vectors is small, the two words are related. So if the distance between the word Colombia and the word coffee is small, that means that Colombia and coffee are related and we can paint it in a brighter color green.

To make this work in an online situation, I imported the word2vec data into postgres. If you want to play with that yourself, you can find the code on github.

Since the underlying model is trained on a Google News archive, some biases shine through. There are some countries that don't appear often in the news - Chad, the Central African Republic and the Republic of Congo (not to be confused with the Democratic Republic of Congo) spring to mind. This makes the vectors of those countries unstable. One article about a guy who went walking in Chad and now Chad lights up for the word walk, even though it isn't particularly related.

The US has the opposite problem. American news talks about "the average American" or "in the US" when the subjects discussed aren't particularly American at all. So the US tends does well for day-to-day terms and maybe underscores a bit for international queries. I created a small spin-off thing, usmapof that uses the names of the US states instead. Comparing the maps for "Germany", "Sweden" and "Norway" gives you an idea where migrants from those countries ended up. Or if you want to know where hockey is popular:
Hockey lights up the north

It's fun to play with, but sometimes you see the limits of the model shine through. The data is somewhat old, so you can't use it well to illustrate current political events. Moreover, names of states are somewhat poor representations of the underlying entities. Washington usually does not mean the state. England makes New England light up for the US, but probably not because so many English settlers went there.

So I wonder if we can do better. What if instead of running a skip-gram algorithm over windows of words, we preprocessed the text into entities first? Then quite possibly the model would learn which entities have similar roles, rather than which words have similar roles. We might want to incorporate somehow even the roles of entities in sentences, which might allow the model to learn from a fragment like "Oil was found in Oklahoma" that oil is something that can be found and that Oklahoma is a place.

Maybe I should try SyntaxNet out for this and see what happens.

Tuesday, September 20, 2016

Project: Offline Movie Reviews

I used my first week of freedom to write a little toy-app: Offline Movie Reviews.

Airplanes don't fly faster than they did 40 years ago, nor do they provide us with more legroom. But we did make a lot of progress when it comes to personal entertainment on board. Most airlines these days will provide you with your own screen and a selection of movies to while the time away. They'll also usually insist that all their movies are just great. And while most will improve with each consumed Gin & Tonic, it still helps to pick one with a good base score. This is where the offline movie reviews app comes in.

It ships with the reviews of 15 000 of the most popular movies. Each usually has a thumbnail version of the movie poster and always the section from the wikipedia article describing the reception. This will typically contain the scores on rotten tomatoes, metacritic and/or the imdb and often comes with a quote or two from a movie critic. Enough to make a somewhat informed decision on how to spend the next two hours.

If you're not interested in how it technically works, you should download the app now, keep it on your phone for your next flight and stop reading.

Apart from the usefulness of the app, I wanted to accomplish two things: learn Swift and share with the world how at Triposo we process and massage data. When Swift came out, I liked some of the things, but was disappointed by how errors were handled and the lack of real garbage collection. Meanwhile, error handling has improved and overall I must say it is a very pleasant language to develop in (even more so if you compare it directly to Objective-C and all [its awkwardness]). The app is not very complicated - master/detail with a tiny bit of care to make sure it executes searches over the movies in smooth fashion.

The data processing builds on my wiki_import project. Wiki_import imports dumps of the Wikipedia, Wikidata and the Wikistats into a Postgres database, after which we can query things conveniently and fast. In this case we want to get our hands on all the movies from the wikipedia sorted by popularity. The wikipedia contains roughly a hundred thousand movies - including all of them would create a db of 700MB or so. We're shooting for roughly 100MB or 15 000 movies. The query to get these movies is then quite straightforward:

SELECT wikipedia.*, wikistats.viewcount 
FROM wikipedia JOIN wikistats ON wikipedia.title = wikistats.title WHERE wikipedia.infobox = 'film' 
ORDER BY wikistats.viewcount 
DESC limit 15000

For each movie, we collect a bunch of properties from the infobox using the mwparserfromhell package, an image and the critical reception of the movie. The properties have standard names, but their values can be formatted in a variety of ways, which requires some tedious stripping and normalizing - as always with wikipedia parsing. The image processing is quite straightforward. I crop and compress the image up to the pain limit to keep the size down. I switched to using Google's WebP which makes images a lot better at these high compression levels.

As you'd expect from user generated content, the critical reception section on the Wikipedia can hide under a number of headings. I might not have gotten all of them, but the great majority for sure. So we find the first of those headings and collect all the wikitext until we encounter a heading of the same or less indent. Feed that into mwparserfromhell wiki stripper and voilá: a text with the reception and only a minimum of wiki artifacts (some image attributes go awry it seems).

We then stick everything into a sqlite database with a full text search index on the title of the movie and the starring field, so we can search for both the name of a movie and who appears in it. That last bit isn't needed for when you decide which movie to watch, but I find myself often wondering, where did I see this actress before? Full text search on iOS works fast and well these days and even gives you prefix search for free.

You can find all the code on github.

Monday, September 12, 2016

Leaving Triposo

Wednesday, August 31 2016 was my last day as full time employee at Triposo, the travel guide company I started 5 years ago with my brothers and Jon Tirsen.

Triposo will continue to exist and will focus on delivering content and technology solutions for other companies. While I think that this is the best strategy for the company, it just isn't me. So Nishank Gopal will take over as CEO who has a lot more experience executing this sort of B2B strategy. I'll remain on the board and be involved as an adviser.

I'm taking some time off to think, write, code, learn and travel. With the company continuing, this isn't quite one of those Startup Post Mortems. I did want to share some thoughts on running travel companies though:

What worked and what didn't?

Triposo started out with a three pronged plan:
  • Build travel guides from targeted web crawls
  • Make the travel guides sticky by adding a travel log
  • Make money by selling tours and travel services on the go
The first prong worked rather well. We went from a few city guides that were basically mash ups of Wikipedia and Wikitravel to a travel guide that covered the world within the first year and kept improving the data quality from there on. I was especially proud when we launched the system that matched web pages automatically to our poi database and then ran opinion mining and fact extraction over those pages.

With this we could rank pois not just on one score, but on a variety of aspects - coffee, drinks, location, which in turn we could use for recommendations and personalization. On top of that we developed a nifty similarity measure for pois powering our "people that like this place, also like."

The second prong of adding a travel log, started promising. Being able to add photos and notes to entries in a travel guide and building a story that way, was fun. For us. Our users didn't use the feature very much though. They used Facebook for sharing their travel experiences. And so we were confronted with a choice: do we keep betting on two things, or do we focus on the thing that really works well, our core travel guide? We went with the last one and killed the travel log.

Sometimes I think we shouldn't have. 5 years ago, Facebook was the place to share this sort of thing, but I wonder if nowadays there would be room for a sharing platform specifically for travel. Breadtrip seems to do well in this space. But you know what they say, being too early is just as bad as being too late.

We didn't pay a lot of attention to our third prong in the first years. People spend a lot of money on travel and half of that is spent during the trip. We figured that once we had a large enough user base, they could start spending that through us. The conversion rates we got linking to web pages from our app were quite low and it seemed to us that just natifying those flows should do the trick.

It didn't. Or not enough. In our presentations we always talked about the shift from desktop to mobile and from booking before a trip to during a trip. This trend is real, but we still have a long way to go. People are happy to research a hotel on their phone, but when it is time to make a booking and enter those credit card details, they'll often quickly switch to the desktop browser, leaving your poor travel guide without its margin.

The other issue was that for tours and activities we had almost no options that had same day availability. When your model is based on telling people at the breakfast table what they should be doing that day in the city where they are, this is a problem. Again, I'm sure this will get better in the next few years, but it didn't in time for us.

What do you do when things don't work?

This is a question people in the start-up world don't talk about much. The general opinion is that when you have a start-up, you focus on that one thing that you do best. That's how you become successful, that's how Google and Facebook did it. Only when you are huge do you diversify.

That's all very well, but what if the one thing you are good at isn't enough? Initially we were doing great, our user base was growing exponentially. But that growth wasn't really viral, it was just Apple and Google sending us downloads. With the travel log shut down, we were seeing bad retention numbers. With our bookings on the go not really taking off, we didn't have a real ecommerce play either.

So what do you do? "Pivot" is a popular answer. But for every success story about pivots there are ten failures and to me it always seemed like spending the money of your investors on an idea they didn't invest in. So you start thinking about things you could add that would fix retention or fix conversion. 

City walks, mini guides, a chat room for triposo users in the location, printable posters, sponsored free wifi, audio guides, a chat bot that advises users about hotels and attractions, partly powered by a human - we built all these things and launched them. And then when the feature doesn't quite take off, you are faced with the choice of removing it and disappointing the users that enjoyed it, or have it clutter up an already complex app.

Maybe this is the right strategy. You try stuff until you hit it out of the park or run out of money. But often I think we should just have focused on building the best travel guide possible. Improve the data quality, the data coverage and the smartness. And if that's not enough, well, then there just wasn't enough a market for the original plan.

Can a travel planning app be a success?

A few month ago there was a popular blog post titled "Why you should never consider a travel planning startup." I was asked a few times about my opinion. Triposo was of course never a travel "planning" startup - we always focused on being helpful when you are on the road. But the arguments against it are very similar.

In short the article says: Getting lots of users for travel is hard, because people do it only once or twice a year. Getting people comfortable with something as complicated as a travel planning app is hard. Getting people to trust you enough to book through you rather than through an OTA they know is hard. Outbidding the site that pays you a commision for a hotel sale is hard.

This is all true and we've seen all of these things first hand at Triposo. But even though I'm writing a post about why Triposo as a consumer product hasn't taken off, I would still answer the question of whether a travel planning app can be a success with a yes.

First of all, these arguments are about all travel startups, not just the ones that do planning or help you while on the road. And yet using Kayak has become a habit. We actually succeeded in attracting a fair amount of users organically. And while we had trouble getting people to book through our app, Tripadvisor figured this out - I could read the reviews there and then go to Expedia to make my booking. And outbidding the guy who pays you a commission is the hallmark of the entire travel industry. How can outbid the hotels themselves on Google?

We focused on being a travel guide that is helpful when you are at the destination, because people don't like to plan. It seems inevitable that there will be an app that will let you have a perfect experience on your trip without you doing more planning than necessary. An app that has all the travel information in the world and knows who you are, where you are and your mood. Unfortunately it looks like it won't be Triposo.

So what's next?

I'm taking some time off to learn, write, code, read and travel. I think that when it comes to technology things have never been as interesting as they are now, so taking a bit of time to figure out what's next seems like the best approach. I'll be doing some smaller projects around stuff I want to try out. A first small one you can find here: - some scripts to import the wikipedia, wikidata and wikistats into postgres and make them searchable.

Triposo as a consumer product will continue and will remain "probably the best travel guide" in the app store. The engineering team will focus on data quality, coverage and smartness - in a way executing on the "focus on the one thing you're good at" strategy.  If you are interested in using the Triposo data and smartness for your own business, get in touch. There's some wonderful stuff there.