tensorflow / tensorflow/recommenders

Get similarity score/rank for a subset of N candidates

Open
#344 5 comments 0 reactions 1 assignee View on GitHub

@maciejkula is already working on this.

Since Aug 6, 2021.

question
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

  1. 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()
  1. 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] *
  2. 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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.