tensorflow / tensorflow/recommenders
Get similarity score/rank for a subset of N candidates
@maciejkula is already working on this.
Since Aug 6, 2021.
- Dominant language
- Python
- Stars
- 2k
- Forks
- 300
- PR merge metrics
- No merged PRs in 30d
Description
Context:
You have built your index using all of your candidate & query embeddings.
And now you want to get the similarity score between either:
- A single user (1021314) & a subset list of N candidates ['TopGun', 'Star Wars', 'The Titantic']
There is a requirement to do this fast so batch/vectorized predictions are required.
Aside: This is a pattern I've seen a need for several times so just flagging here in case it's helpful.
Question: What is the best way to do this?
Options considered
- Exclude all candidates except your N=3 candidates your concerned about:
for row in ratings.batch(300).take(1):
top_movies = brute_force.query_with_exclusions(row, exclusions=row['exclusions'])[1].numpy()
- Manually extract the user & candidate embeddings from the model and just handle this myself via simple dot products or cosine similarity between the embeddings *[errorr prone] *
- Just get the scores/rank for all of my candidates and filter results by index lookup after the fact [very slow]
Option 1 feels cleanest as it handles all vocabulary/index mappings and leaves less room for error.
The one downside is that when I have a large number of candidates (e.g. 500,000) it means I have to have a row in my dataset with (500,000 - N(3)) candidates to exclude for each row.
I guess I was wondering if it is possible to instead of specifying exclusions to actually specify a subset of candidates to consider/include for each row/prediction. This would help us out a huge amount with several models we have in production (e.g. Find the most similar "best fitting" sku size for a user for a given fashion item ----> subset of candidates is N=14 in this case rather than our entire inventory)
I hope this all makes sense!
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.