Editor’s note: Madhav Thaker and Chen Karako-Argaman are speakers for ODSC East this May 9th-11th. Be sure to check out their talk, “Generating Content-based Recommendations for Millions of Merchants and Products,” there!
Shopify is an all-in-one commerce platform that provides businesses the infrastructure to create and scale their own online store and sell products or services. It was founded in 2006 and has since grown to become one of the most popular commerce platforms in the world, with millions of businesses in more than 175 countries using it to sell their products. If you’ve shopped online over the last year, there’s a good chance it was from a store powered by Shopify.
Whether you are shopping for clothes, looking for a new restaurant, or trying to find a new song – recommendation engines are integral to a seamless user experience. In our case, we specialize in building algorithms that enable better product discovery, and content-based recommendations are central to the product discovery experience. As customers are browsing, it is crucial to show relevant alternatives in case the product they are looking at is not quite the right fit.
At Shopify, we build recommendation engines that are used by merchants across a wide variety of industries. It’s therefore important that we build models that are flexible and scalable. In the beginning of 2021, we spent time exploring various approaches for content-based recommendation engines that would not only provide high-quality recommendations across industries but would also scale as we expand the number of shops that receive these recommendations. We share more on our approach below.
How are recommendations surfaced today?
Our recommendations are surfaced on the product display page (PDP). Here is an example:
In this recommendation slider, we showcase both behavioral and content-based recommendations, which are interleaved as shown below. This allows to show customers recommendations targeting different intents, including both alternatives and complementary products.
Our content-based recommendation system is solely reliant on the text provided by merchants when describing their products. We can expect to leverage the text highlighted below.
Beyond what is shown on the product page, we also incorporate product metadata that is behind the scenes. Because we incorporate a wide variety of text input which varies in length and cohesiveness, we focused our attention on finding the appropriate sentence encoder for our use case. We went with the Universal Sentence Encoder.
What is the Universal Sentence Encoder?
The Universal Sentence Encoder (USE) is a sentence encoder built by Google that specializes in text classification, semantic similarity and clustering. The underlying architecture Google typically uses is a Dynamic Averaging Network. Let’s take a look at what’s under the hood:
Sentences are tokenized (as shown above) and each token is encoded. Those word embeddings are then averaged, and those embeddings are then passed through several feed forward networks. The main benefits of this encoder are:
- This is a simple and lightweight architecture that speeds things up when it comes to inference.
- The bag-of-words nature of the model inputs lends itself to handling unstructured text really well.
Why did we choose this when there are many other options?
Since Shopify has billions of products across our merchants’ catalog, the text our team deals with can be extremely messy and inconsistent. Each merchant has very different styles for creating product titles and descriptions, so we needed an encoder that was able to generate high-quality embeddings regardless of the input quality.
As mentioned above, the speed at model inference and ability to handle messy text was absolutely critical while exploring options. An added benefit is how simple it is to incorporate:
This allowed us to quickly prototype and experiment with this approach, and ultimately avoid overcomplicating our code base.
How did we scale?
Building high-quality embeddings was half the battle. We then had to efficiently encode hundreds of millions of products within a reasonable amount of time. We relied on Shopify’s ML platform to get the job done. Our ML platform is built upon Ray, which allowed us to scale easily. Some of the benefits of Ray are:
- Works with python code
- Easily integrates with many ML libraries
- Easy to parallelize ML workflows
These were crucial in helping minimize the effort required to get our prototype code production ready. Also helpful was the fact that our ML workflow didn’t require us to train on large portions of our data at once. Since each product is embedded separately, we were able to effectively parallelize our workflow.
Our data is broken up into thousands of partitions (a subset of our input dataset). In the chart above, each ML workflow would process a single partition which allowed us to have complete visibility into the workload that each Ray Cluster was processing. Our scaling approach required us to identify:
- The appropriate size of partitions in our upstream job
- The required memory in our Ray Clusters to process each partition
- The number of Ray Clusters needed to process hundreds of millions of products within an appropriate amount of time.
Another benefit we found is our ability to easily visualize how much memory within our Ray clusters is being utilized during the job.
By combining a lightweight content-based recommendation system and our Ray-based ML platform, we were able to make significant improvements to the coverage and quality of our recommendation systems.
Be sure to come by our presentation to learn more about why we chose USE over many options, how Ray works under the hood and to find out how this did in an online A/B test!
About the authors/ODSC East 2023 speakers:
Madhav Thaker is a Senior Data Scientist at Shopify where he focuses on building/evaluating recommendation systems. His role includes prototyping potential solutions and scaling them for production. Prior to Shopify, Madhav was a data science consultant where he focused on NLP projects for pharmaceutical companies. He then transitioned to Disney to develop personalized movie recommendations which sparked his passion for recommendation systems. In his free time, Madhav hosts free Q&A sessions for aspiring data scientists who are looking to get into this space.
Chen Karako-Argaman is a Senior Data Science Manager at Shopify, where she leads the Discovery Experience data team. Chen has focused on building search and discovery products using machine learning techniques, experimenting and running A/B tests to improve and measure feature impact, and collaborating with cross-disciplinary teams. She enjoys building high-impact data science teams and providing technical and strategic leadership. Aside from day-to-day work, Chen is also interested in fairness in AI and has published research in this domain. Prior to joining Shopify, Chen obtained an M.Sc. in astrophysics from McGill University, where she discovered 30 radio pulsars by developing signal-processing algorithms for telescope data.