Inference (Usage)

Overview

After training a transformer-based recommender model it can be used to make recommendations in two ways, based on an interaction dictionary/JSON or directly based on the User ID.

When to Use User ID vs. Interaction JSON/Dictionary

User ID

  • Use Case: Best suited for static scenarios like e-commerce platforms or subscription services where the user's interaction history does not frequently change or only updates when the model is retrained.

  • Example: An e-commerce site where a user's purchase history is relatively stable over time. The recommendation system uses this stable set of interactions to suggest new products based on past purchases.

Interaction JSON/Dictionary

  • Use Case: Ideal for dynamic environments where user interactions are continuously changing, such as in social media applications or session-based recommendations.

  • Example: A social media platform where the user's interactions (likes, shares, comments) are constantly evolving. Using a real-time interaction JSON allows the system to recommend content that aligns with the user's latest activities, providing highly relevant and timely content suggestions.

Example Usage

Inference Based on User Interactions

In scenarios where specific user interactions are known, these can be used directly to make recommendations:

curl -X POST "https://demo-33fxfdfr.apps.pigeonsai.cloud/iid_recommend" \
    -H "Content-Type: application/json" \
    -d '{
          "user_interactions": {
            "21253": {"timestamp": 1704060026, "rating": 4.5},
            "21252": {"timestamp": 1704060026, "rating": 4.5},
            "21255": {"timestamp": 1704060026, "rating": 4.5}
          },
          "k": 10,
          "recommend_seen": false
        }'

Inference Based on User ID

For making recommendations based on a user ID:

curl -X POST "https://demo-33fxfdfr.apps.pigeonsai.cloud/uid_recommend" \
  -H "Content-Type: application/json" \
  -d '{
        "user_id": "QBZhgIPoAXeKU7xV3sJG5BXX5LJ3",
        "k": 5,
        "recommend_seen": true
      }'

Key Parameters

  • recommend_seen (bool): If set to True, the model will include items the user has previously interacted with in the recommendations.

  • k (int): The number of recommendations to return.

  • candidate_ids (list of str): Limits the recommendations to the specified item IDs. Items not present during training receive a score of zero.

Structure of User Interactions

The user_interactions parameter expects a dictionary where each key is an item ID and the value is another dictionary containing:

  • timestamp (int): The time of the interaction.

  • rating (float): The user's rating, which will be compared to the training threshold to determine if it's a positive interaction.

Understanding Recommendations Output

The output is a dictionary containing a list of recommended item IDs and their corresponding scores, indicating the likelihood that the user will value the recommended items.

Example output:

{'recommendations': [{'id': 21254, 'score': 0.8992305254936218}, 
{'id': 21108, 'score': 0.7892305254936218}, 
{'id': 56152, 'score': 0.684579336643219}, 
{'id': 63321, 'score': 0.5601753282546997}, 
{'id': 63324, 'score': 0.4200179719924927}], 
'message': None}

Last updated