tensorflow / tensorflow/recommenders

Getting Less Top-k accuracy comparing to other Open source Recommendation systems

Open
#535 15 comments 0 reactions 1 assignee View on GitHub

@maciejkula is already working on this.

Since Sep 27, 2022.

Dominant language
Python
Stars
2k
Forks
300
PR merge metrics
No merged PRs in 30d

Description

We have done a comparison of TFRS with Lightfm (a open source library which is for recommendation system) and Result shows that Lightfm performs better than TFRS. Here we use the dataset which is available in amazon blog for evaluating recommendation system. The result is showed as follows. Is there any way we can improve the accuracy further?

Screenshot from 2022-08-24 10-31-18

Here i am attaching Train- Test Top-k visualisations

1
2
3
5
4

sample code

class UserModel(tf.keras.Model):

def __init__(self):
    super().__init__()

    emb_dim = 32    
    self.user_id_embedding = tf.keras.Sequential([
        tf.keras.layers.experimental.preprocessing.StringLookup(
            vocabulary=USER_ID_unique, mask_token=None),
        tf.keras.layers.Embedding(len(USER_ID_unique) + 1, emb_dim),
    ])
        
    self.cabin_type_embedding = tf.keras.Sequential([
        tf.keras.layers.experimental.preprocessing.StringLookup(
            vocabulary= CABIN_TYPE_unique, mask_token=None),  
        tf.keras.layers.Embedding(len(CABIN_TYPE_unique) + 1, emb_dim),
    ])

    self.user_residence_embedding = tf.keras.Sequential([
        tf.keras.layers.experimental.preprocessing.StringLookup(
            vocabulary=USER_RESIDENCE_unique, mask_token=None),
        tf.keras.layers.Embedding(len(USER_RESIDENCE_unique) + 1, emb_dim),
    ])
    

def call(self, user_interation_data):
    return tf.concat([                          
        self.user_id_embedding(user_interation_data["USER_ID"]), 
        self.cabin_type_embedding(user_interation_data["CABIN_TYPE"]), 
        self.user_residence_embedding(user_interation_data["USER_RESIDENCE"]),
    ], axis=1)

class ItemModel(tf.keras.Model):

def __init__(self):
    super().__init__()

    

    self.item_embedding = tf.keras.Sequential([
        tf.keras.layers.experimental.preprocessing.StringLookup(
            vocabulary=item_unique, mask_token=None),
        tf.keras.layers.Embedding(len(item_unique) + 1, 32),
    ])


def call(self, user_interation_data):

    return tf.concat([
        self.item_embedding(user_interation_data["ITEM_ID"])
        
        ], axis=1)

class TRFSRetrievalModel(tfrs.models.Model):

def __init__(self, UserModel,ItemModel, item_ds ):
    super().__init__()

    self.query_model = tf.keras.Sequential([#,UserModel()
      UserModel(),
      tf.keras.layers.Dense(32 , kernel_initializer= tf.keras.initializers.RandomNormal(seed=99)),   
    ])
    

    self.candidate_model = tf.keras.Sequential([
      ItemModel(),
      tf.keras.layers.Dense(32, kernel_initializer= tf.keras.initializers.RandomNormal(seed=1))
    ]) 
    
    
    self.task = tfrs.tasks.Retrieval(
        metrics=tfrs.metrics.FactorizedTopK(
        item_ds.map(self.candidate_model),
            ks= (3, 5, 10,15, 25))
    )
    
def compute_loss(self, features, training= True):

    item_features = {"ITEM_ID":features.pop("ITEM_ID") }
    query_embeddings = self.query_model(features)
    item_embeddings = self.candidate_model(item_features)

    return self.task(query_embeddings, 
    item_embeddings, 
    compute_metrics=True
    )

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.