question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

loaded scann index can not use k param

See original GitHub issue

https://github.com/tensorflow/recommenders/blob/main/docs/examples/basic_retrieval.ipynb

# Export the query model.
with tempfile.TemporaryDirectory() as tmp:
  path = os.path.join(tmp, "model")

  # Save the index.
  index.save(path)

  # Load it back; can also be done in TensorFlow Serving.
  loaded = tf.keras.models.load_model(path)

  # Pass a user id in, get top predicted movie titles back.
  scores, titles = loaded(["42"])

  print(f"Recommendations: {titles[0][:3]}")

loaded object have not k param,so i can not return k(default 10) than 10 movies?

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:8

github_iconTop GitHub Comments

2reactions
alimirferdoscommented, Sep 8, 2021

@maciejkula I have two issues concerning the answer you gave above.

First, although I call the functions before creating concrete functions, it still requires me to pass input specs. I got some results using the following snippet but I don’t think it’s the right way to do so:

recom_10 = tf.function(lambda user_id: model(user_id, k=10))
_ = recom_10(tf.constant([812]))

signatures = {"k_10": recom_10.get_concrete_function(user_id=tf.constant([812]))}

My second issue was creating a concrete function for query_with_exclusions. I’ve used the following code:

excluded_recoms = tf.function(lambda user_id, exclusions:
                              index.query_with_exclusions(user_id, k=10, exclusions=exclusions))
_ = excluded_recoms(uid=tf.constant([812]), exclusions=tf.constant([[150]]))

signatures = {"excluded_recoms": excluded_recoms.get_concrete_function(uid=tf.constant([812]), exclusions=tf.constant([[150]]))}

This way I can save and load the index but I can only pass a single exclusion id because its shape is set to (1, 1).

Any idea on how to solve these two issues?

1reaction
sam-wattscommented, Dec 28, 2021

@maciejkula is there a reason why (other than it feeling like a bit of a hack…) you couldn’t just define the argument k in topK.query_with_exclusions as a tf.Tensor and then just extract the value from that? Would that allow you to define it via TensorSpec to get a concrete function that allows for multiple values of k at inference time?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Efficient serving with ScaNN for retrieval (Building ... - YouTube
In our earlier videos, we showed you how to use the brute force approach in your retrieval system. In this video, we are...
Read more >
Postgres not using index when index scan is much better option
I found out that the query plan does a seq scan on the large table email_activities (~10m rows) while I think using indexes...
Read more >
Index Seek scanning whole table dependent on parameter ...
When there is a mismatch between the data types of the column and variable, SQL Server cannot directly use the seeking ability of...
Read more >
Force use of index even when index value in where clause is
The optimizer cannot compare "JOHN" against the index entries, ... but since we re-load the entire data on certain fact tables, we cant...
Read more >
Indexing for Better Performance - JanusGraph Docs
Mixed indexes can be used for lookups on any combination of indexed keys and ... In the absence of an index, JanusGraph will...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found