newcohospitality.com

Optimizing User Experiences with a Two-Tower Recommendation Model

Written on

Recommendation systems play a vital role in enhancing user experiences across various sectors by customizing services and products to individual preferences. In the realm of e-commerce, these systems provide tailored product suggestions, enriching shopping experiences and boosting sales. Streaming platforms also leverage these systems to curate personalized media content, ensuring users effortlessly discover what they enjoy without extensive searching. As businesses aim for more tailored interactions, recommendation systems are becoming increasingly sophisticated, with the two-tower model emerging as a significant innovation. This model excels in managing large datasets while delivering precise user-item recommendations.

What Are Recommendation Systems?

Recommendation systems are sophisticated algorithms designed to identify the most appropriate products, services, or information for users. They are particularly useful in environments where users face overwhelming choices, streamlining decision-making, enhancing user experience, and fostering engagement by personalizing recommendations based on user preferences and historical behavior.

Types of Recommendation Systems

  1. Content-Based Filtering: This approach recommends items by analyzing the features of the items themselves. For instance, if a user enjoys a specific book, the system may suggest works by the same author or within the same genre, based on the assumption that past preferences will guide future likes.
  2. Collaborative Filtering: This method relies on the collective behavior of users rather than item characteristics. There are two main approaches within collaborative filtering:
    • User-Based: This technique recommends items by identifying users with similar preferences, based on the premise that past agreements will continue in future preferences.
    • Item-Based: This strategy suggests items similar to those the user has previously liked, relying on the similarities among items based on user interactions (e.g., ratings).
  3. Hybrid Systems: Hybrid recommendation systems merge content-based and collaborative filtering methods to enhance accuracy. They may function by making predictions through both methods separately and integrating the results or by adding content-based capabilities to a collaborative filtering framework to address specific challenges like cold starts and scalability.

Importance of Personalization in Recommendation Systems

Personalization is essential in recommendation systems, directly influencing user satisfaction and engagement. Here’s why it matters:

  • Improved User Experience: Tailored recommendations help users find products or content they might not discover independently, enriching their engagement with the service.
  • Increased Engagement: By showcasing items that resonate with user preferences, recommendation systems boost the likelihood of user interaction, enhancing retention rates.
  • Efficiency in Decision-Making: Personalized suggestions minimize the time users spend searching for suitable products or content, facilitating quicker decision-making.
  • Boosts Business Value: For companies, personalized recommendations improve customer satisfaction, increase sales, and elevate revenue. They also enhance targeted marketing by comprehending user preferences and delivering more customized advertisements.

The Two-Tower Recommendation System

The two-tower model consists of two separate neural networks, or "towers." One tower processes user data, while the other handles item data. Each tower typically consists of multiple layers of neural networks that convert raw features into dense embeddings, representing users and items within a shared latent space where their interactions can be analyzed. The final recommendations are generated by calculating a similarity score (often through dot product or cosine similarity) between the embeddings from each tower.

How It Differs from Traditional Models

Traditional recommendation models, such as matrix factorization, treat the recommendation challenge as a matter of filling in missing entries in a user-item interaction matrix. These models generally learn to map users and items into a shared latent space, but they do so in a single model framework, which can lead to inefficiencies, especially when scaling to large datasets with complex features.

In contrast, the two-tower model distinctly separates user and item features into two networks, allowing each to specialize and learn detailed, feature-specific representations. This separation provides flexibility in training on different data subsets or types.

Benefits of Using a Two-Tower Architecture

  1. Enhanced Personalization through Separate Learning: By independently learning user and item features, the two-tower model captures intricate interactions, allowing for greater personalization.
  2. Scalability and Efficiency: The two-tower model efficiently manages large datasets, with each tower scaling its complexity according to its respective data, optimizing computational resources.
  3. Parallelization and Optimization: The separation of the towers allows for parallel training, reducing training time, which is advantageous in industrial applications where data is frequently updated.
  4. Flexible Feature Integration: This architecture supports the easy incorporation of diverse data types without forcing all information through a single pipeline, facilitating experimentation with various feature combinations.

Objective of Our Project

The main aim of our project is to improve the effectiveness and accuracy of our recommendation system by implementing a two-tower model. This dual neural network approach independently processes user queries and product data, fostering more relevant interactions. Our specific goals include:

  1. Implementing a Two-Tower Model: We aim to develop a model that processes user queries and product information separately, generating rich embeddings for enhanced understanding of their attributes and interactions.
  2. Training with Historical Data: To boost recommendation accuracy, we plan to train the model on a comprehensive dataset of historical user queries and product interactions.
  3. Evaluating Model Effectiveness: The model’s success will be assessed based on its ability to improve recommendation relevance and user satisfaction, comparing its performance with existing systems and analyzing user engagement metrics.

Through these objectives, our project seeks not only to deploy a sophisticated technical solution but also to achieve tangible enhancements in user experience and business results, showcasing the benefits of advanced machine learning in commercial applications.

Data

Data Collection

We have assembled a robust dataset from Amazon, encompassing user queries and related product recommendations. This dataset captures a wide range of user interactions and preferences, including query text, product identifiers, interaction data, and detailed product metadata.

Data Selection

We utilize the "Shopping Queries Data Set," a comprehensive collection designed to advance semantic matching between user queries and products. This dataset includes a challenging set of queries, each associated with up to 40 relevant product results, classified with ESCI relevance judgments (Exact, Substitute, Complement, Irrelevant).

The dataset features multilingual queries in English, Japanese, and Spanish, along with additional information for each query-product pair, supporting benchmarking of new ranking strategies.

The dataset facilitates three key tasks: 1. Query-Product Ranking: Enhancing the accuracy of product rankings in response to user queries. 2. Multi-class Product Classification: Classifying products into relevant categories based on query context. 3. Product Substitute Identification: Identifying substitute products for specific queries.

Data Description

To accommodate various research needs, we offer two versions of the dataset: - Reduced Version for Task 1: Contains 48,300 unique queries and 1,118,011 query-result pairs, filtering out "easy" queries for more challenging learning experiences. - Larger Version for Tasks 2 and 3: Features 130,652 unique queries and 2,621,738 query-result pairs, providing a comprehensive dataset for in-depth training and analysis.

Both versions include fields such as example_id, query, product_id, esci_label, and product details for effective testing and improvement of recommendation systems.

Data Preprocessing

Effective preprocessing is crucial for optimizing our recommendation system's performance. Below are the steps we followed to refine our dataset, ensuring clean, relevant, and accurately labeled data:

#### Exploratory Data Analysis (EDA) We began with EDA to examine the dataset’s characteristics, identifying and rectifying inconsistencies to establish a strong foundation for model accuracy.

#### Sentence Embeddings Creation Using the distilbert-base-uncased model from the Sentence Transformers library, we converted user queries and product titles into vector embeddings—32-dimensional for queries and 160-dimensional for product titles.

#### Dataset Construction We linked product embeddings with our shopping queries dataset, matching detailed product features with identifiers and aligning query embeddings with user queries.

#### Training Set Preparation Finally, we merged query and product embeddings with their respective ESCI labels, creating a comprehensive training dataset that includes input features and target labels, ready for model training.

This methodical preprocessing pipeline ensures our data is well-prepared for effective learning, enhancing the accuracy and reliability of product recommendations.

Modeling

Model Design

Our recommendation system utilizes a two-tower architecture, with each tower serving a distinct function: - Query Tower: Employs BERT to convert textual user queries into 32-dimensional vector embeddings, excelling in natural language understanding. - Product Tower: Similar to the Query Tower, but processes product metadata to generate 160-dimensional embeddings, capturing detailed product features.

Each tower comprises several linear layers for further refining embeddings.

Embedding and Retrieval

After embedding, outputs from both towers are aligned to a uniform dimensionality for effective comparison. We use the AnnoyIndex library for efficient handling of high-dimensional spaces, allowing rapid retrieval of the top K closest product matches based on cosine similarity.

Training and Tuning

During training, we fine-tune the weights of both BERT models and linear layers through backpropagation, exploring various hyperparameters (learning rates, batch sizes, number of epochs) to determine optimal model configuration, enhancing its accuracy in real-world applications.

Evaluation

To assess model performance, we will utilize precision and recall metrics, specifically gauging the accuracy and relevance of recommendations. Post-deployment, user satisfaction surveys will help evaluate real-world effectiveness, allowing for refinements based on feedback.

Streamlit UI Integration

We developed our recommendation system's user interface using Streamlit, seamlessly integrated with our backend FastAPI server. The interface is user-friendly, enabling quick input of shopping queries and prompt delivery of personalized product recommendations.

#### UI Workflow: - User Query Input: Users can enter their queries into a dedicated text box, making the system accessible. - Communication with FastAPI: Upon query submission, the Streamlit application requests the FastAPI server’s /search endpoint, compiling product recommendations. - Display Results: Recommended products are displayed along with relevant details, enhancing user interactivity.

The entire Streamlit application is containerized within a Docker container, ensuring consistency across deployment environments.

Deployment on Google Cloud

Dockerization and Artifact Registry

We encapsulated FastAPI and Streamlit components in Docker containers for isolated environments, ensuring consistency across development stages. The Docker images were uploaded to Google Cloud’s Artifact Registry, allowing for version control and streamlined updates.

Deployment on Google Kubernetes Engine (GKE)

Our application is deployed on GKE, with distinct clusters for FastAPI and Streamlit to optimize performance and management, enhancing scalability and service availability.

Deployment Steps

  • Cloud Shell: We used Google Cloud Shell to execute Docker commands for building our applications, streamlining the deployment process.
  • Register Images: After containerization, we registered Docker images with the Artifact Registry for secure storage and versioning.
  • Kubernetes Clusters: The images were deployed within configured Kubernetes clusters, facilitating seamless communication across the cloud environment.

This comprehensive deployment strategy leverages Google Cloud’s infrastructure, simplifying management and scaling from development to production.

Conclusion

The field of recommendation systems is rapidly advancing as machine learning and artificial intelligence evolve. Our exploration of the two-tower model highlights significant progress in personalizing user experiences at scale. By separating user and item data into distinct processing units, we can create more nuanced and contextually relevant interactions.

This approach not only enhances personalization but also optimizes operational efficiency, making it pivotal for industries reliant on dynamic data streams. The deployment of our model within a robust cloud infrastructure underscores the scalability and adaptability of sophisticated recommendation systems in real-world applications.

As we continue refining our system through iterative training and real-world insights, we anticipate ongoing improvements, ensuring our recommendation engine remains at the forefront of technology. User feedback loops and continuous performance evaluations will be essential in fine-tuning accuracy and satisfaction.

In summary, the development and implementation of the two-tower model represent a significant technical achievement and a strategic enhancement to customer engagement and retention. This project showcases the technical sophistication achievable with modern AI techniques and the tangible business impacts of effectively executed recommendation systems. The ongoing evolution of these systems promises even greater personalization, transforming user interactions across various sectors.