📜 ⬆️ ⬇️

Personal recommendations in ivi: Hydra

In the ivi online cinema tens of thousands of pieces of content and the task of “choosing what to watch” becomes nontrivial.


We wrote about the recommendation system in ivi, which deals with the selection of content based on user interests (the internal name is Hydra ) here and here . Much time has passed and the project code has changed significantly: the offline part has moved to Spark, the online part has adapted to high loads, Hydra has started using another recommender model - all these changes will be covered in the article.

Hydra Architecture


Back in 2014, Hydra was created as a Python application: the data for the recommender model was loaded by a separate script — the “offline part” —from external sources (Vertica, Mongo, Postgres). The script was preparing user-item matrix dimension m timesn, where m is the number of users in the training sample, and n is the size of the catalog (the number of unique content units), you can read more about item-based personal recommendations in articles by Sergey Nikolenko .

The history of viewing the user is a vector of dimension nin which for each content with which the user interacted (looked, rated), there are units, the remaining elements are zero. Since each user interacts with dozens of content units, and the size of the directory is thousands of units, we get a sparse row vector in which there are a lot of zeros and the user-item matrix consists of such vectors. The online cinema ivi collects rich feedback from users - content views, ratings (on a ten-point scale), onboarding results (binary preferences “like - dislike”, here is a presentation with an example from Netflix ) - the model is trained on this data.
')
The classic memory-based algorithm was used to issue recommendations - Hydra “memorized” the training sample and stored a matrix of user views (and ratings) in memory. With the growth of the service audience in proportion to the growth and size of the matrix user-item. The architecture of the reference service at the time looked like this:



Disadvantages of Hydra


As can be seen in the diagram, feedback from users (views, content ratings, onboarding marks) is stored in fast key-value repositories (MongoDB and Redis) and in Vertica - column data repository. Data is vertically fed incrementally using special ETL procedures.

The offline part is launched daily by crown: it downloads data, trains the model, saves it as textual and binary files (sparse matrices, python-objects in the .pkl format). The online part generates recommendations based on the model and history of the user's targeted actions — views, ratings, content purchases (read user feedback from Redis / Mongo). Recommendations are issued using dozens of python processes running on each server (there are a total of 8 servers in the Hydra cluster).

This architecture gave rise to several problems:


Hydra: revival


The system in this form (with constant modifications and improvements) survived until February 2017. Time to download data in offline parts grew algorithm of the model remained unchanged. At the beginning of 2017, we decided to move from a memory-based reference model to a more recent ALS algorithm (on the Coursera there is a video about this model ).

In short, the algorithm tries to present our huge sparse user-item matrix. Uin the form of a product of two "dense" matrices: user matrices and content matrices:

U=X timesYT;U inRm timesn,X inRm timesk;Y inRn timesk




ALS allows you to train for each user. uvector xudimensions k- so-called "Hidden factors" of the user. Each content unit imatches vector yithe same dimension, "hidden factors" of content. Wherein k<<m, the dimension of the space of hidden factors is much smaller than the size of the directory, each user describes a dense vector of low dimension (usually k<100).

The product of the vector of the user by the vector of the content is the relevance of the content to the user: the higher it is, the more chances the film has to get to the issue. The ALS exhaust is ground in the business rules grinder, because besides the “show content that a user will like” task, the recommender system has a number of tasks related to content monetization, service positioning, etc. Business rules slightly distort the vector of recommendations - this fact must be taken into account, for example, when conducting an offline assessment of the model.

New architecture


Much work has been done on redesigning the service, the results of which are as follows:




Conclusion


Hydra for the year has changed a lot both in architectural terms and in the algorithmic part. More details about these changes will be discussed in a series of articles.

Source: https://habr.com/ru/post/351176/


All Articles