Generate User and Product Embeddings for Recommendations
Build user and product embeddings by averaging review embeddings, and use their similarity to weakly predict ratings.
Why it matters
Leverage user and product embeddings derived from review data to predict review scores and enhance recommendation systems. This asset provides a novel signal that can improve existing recommendation models.
Outcomes
What it gets done
Calculate user and product embeddings by averaging review data.
Evaluate embedding similarity against review scores in a test set.
Visualize the correlation between embedding similarity and review scores.
Utilize embeddings as an additional feature for recommendation improvements.
Install
Add it to your toolbox
Run in your project directory:
curl -fsSL https://spark.entire.vc/get/oai-userandproductembeddings | bash Steps
Steps in the chain
Overview
User And Product Embeddings
An OpenAI Cookbook notebook that derives user and product embeddings by averaging review embeddings, then shows their cosine similarity weakly correlates with review scores. Use it as an additional signal alongside collaborative filtering, not a replacement. Most users and products in the sample dataset appear only once, limiting representation quality.
What it does
This notebook builds on the companion Get_embeddings_from_dataset notebook to calculate a user embedding and a product embedding for every user and product in the training set, simply by averaging the embeddings of all reviews that user wrote or that product received. It then evaluates whether these embeddings carry predictive signal by measuring, on an unseen test set, the cosine similarity between each review's user and product embedding.
When to use - and when NOT to
Use this when you already have review-level embeddings and want to derive per-user and per-product representations from them as an additional recommendation signal - it's a lightweight complement to collaborative filtering, not a replacement for it, since it captures a different kind of signal. Most users and products in the underlying 50k-review sample appear only once, which caps how much a single-user or single-product average can really represent.
Inputs and outputs
Cosine similarity between a review's user and product embedding is calculated for every test-set review, then normalized to a 0-1 percentile scale so scores are evenly distributed rather than clustered. Grouping these normalized similarity scores by the review's actual star rating and plotting the distribution reveals a weak but real trend: higher user-product embedding similarity correlates with higher review scores.
Integrations
Because this predictive signal comes purely from averaged review embeddings rather than explicit user-item interaction patterns, it works differently from standard collaborative filtering and can be layered on top of it as an extra feature to nudge performance on existing recommendation or rating-prediction problems, rather than needing to replace whatever collaborative-filtering approach is already in place.
Who it's for
Developers working on recommendation or review-scoring systems who want a simple, embeddings-based signal - derived from existing review embeddings, not new interaction data - to complement collaborative filtering.
Source README
User and product embeddings
We calculate user and product embeddings based on the training set, and evaluate the results on the unseen test set. We will evaluate the results by plotting the user and product similarity versus the review score. The dataset is created in the Get_embeddings_from_dataset Notebook.
1. Calculate user and product embeddings
We calculate these embeddings simply by averaging all the reviews about the same product or written by the same user within the training set.
We can see that most of the users and products appear within the 50k examples only once.
2. Evaluate the embeddings
To evaluate the recommendations, we look at the similarity of the user and product embeddings amongst the reviews in the unseen test set. We calculate the cosine distance between the user and product embeddings, which gives us a similarity score between 0 and 1. We then normalize the scores to be evenly split between 0 and 1, by calculating the percentile of the similarity score amongst all predicted scores.
2.1 Visualize cosine similarity by review score
We group the cosine similarity scores by the review score, and plot the distribution of cosine similarity scores for each review score.
We can observe a weak trend, showing that the higher the similarity score between the user and the product embedding, the higher the review score. Therefore, the user and product embeddings can weakly predict the review score - even before the user receives the product!
Because this signal works in a different way than the more commonly used collaborative filtering, it can act as an additional feature to slightly improve the performance on existing problems.
FAQ
Common questions
Discussion
Questions & comments · 0
Sign In Sign in to leave a comment.