Learn a vector for each listing from browsing sessions
That retrieval model starts from how guests browse.
One guest clicked L4, L9, L2, L7 and L5, in that order. Which listings pull L2's vector toward them?
An embedding is a short list of numbers, a vector, learned so that similar things end up close together. Airbnb's 2018 work learned one for each listing from how people browse. It works the way word2vec learns a vector for each word from the words around it in sentences.
Here a session is the sentence: the listings one guest clicked, in order. A gap of more than 30 minutes between two clicks starts a new session.
One guest's session clicked L4, L9, L2, L7 and L5, in that order. L2 is pulled toward its neighbors, L9 and L7, and a random listing from elsewhere is pushed away from it.
Two changes fit this method to a marketplace:
- The booked listing teaches the whole session. When a session ends in a booking, say of L8, the model predicts each listing's neighbors and also L8. So every listing in the session learns from where the session ended.
- Negatives come from the same city. A negative is an example the model learns to push away. Guests on travel sites usually search one market, the place they want to stay, so a listing's clicked neighbors mostly come from its own city. Random negatives come mostly from other cities, and the model learns geography and little else. So Airbnb added random negatives drawn from the same market as the listing being learned.
Each listing vector had 32 numbers. The authors call that a trade-off between offline quality and the memory needed to keep every vector in the RAM of the search machines. The team learned vectors for 4.5 million active listings from more than 800 million search sessions.
In the editor, write split_sessions(clicks), which cuts one guest's (minute, listing) clicks into sessions, and pairs(session, booked), the (listing, context) pairs the embedding trains on. A listing's context is each neighbor one place away, plus the booked listing when the session ended in a booking.
- 1
Write
split_sessions(clicks): a gap of more than 30 minutes between two clicks starts a new session. - 2
Write
pairs(session, booked): each listing with its neighbors one place away, and with the booked listing too when the session ended in a booking.
Run your code to check it. Output shows here.