tensorflow / tensorflow/recommenders
Getting Less Top-k accuracy comparing to other Open source Recommendation systems
Open
@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?

Here i am attaching Train- Test Top-k visualisations





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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.