How to get final recommendations (Tensorflow Recommenders) with multiple features?

19 Views Asked by At

I am following the Tensorflow Recommenders tutorial (https://www.tensorflow.org/recommenders/examples/context_features) and built a model with multiple features. When trying to get the final recommendations, I am just getting a bunch of Tensors:

b'Tensor("args_1:0", shape=(), dtype=string)', b'Tensor("args_1:0", shape=(), dtype=string)'

and not the actual values.

My code looks the following:

# Use brute-force search to set up retrieval using the trained representations
index = tfrs.layers.factorized_top_k.BruteForce(model.query_model, k=10)
index.index_from_dataset(
    test_interactions.batch(100).map(lambda features: (
        features['title_id'],
        model.candidate_model({
            'title_id': features['title_id'],
            'category': features['category'],
        })
    ))
)

# Get some recommendations
rec = test_interactions.batch(100).map(lambda features: index({
    'customer_id': features['customer_id'],
    'timestamp': features['timestamp'],
}))

# Evaluate the recommendations
for _, recommendations in rec:
    product_ids = [tensor.numpy() for tensor in recommendations]
    print(product_ids)

Ideally I would like to get the customer_id and a list of the top k products.

What am I doing wrong?

0

There are 0 best solutions below