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.

Getting similar items

See original GitHub issue

Hi, not really an issue. I am new to LightFM. Before I used implicit for generating recommendations but there was no build-in option for passing in user- / item-features.

Implicit defines a function on the model for getting similar items. Does adapting this function to LightFM work? I think I’m missing the theoretical background to see for myself.

def similar_items(self, itemid, N=10):
    scores = self.item_factors.dot(self.item_factors[itemid]) / self.item_norms
    best = np.argpartition(scores, -N)[-N:]
    return sorted(zip(best, scores[best] / self.item_norms[itemid]), key=lambda x: -x[1])

https://github.com/benfred/implicit/blob/master/implicit/als.py

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:8

github_iconTop GitHub Comments

6reactions
EthanRosenthalcommented, Jan 4, 2018

I believe the following should work with LightFM. One thing to note is that the similarity function below ignores the item biases that LightFM learns, but I think it should be suitable for generating sensible recommendations.

def similar_items(item_id, item_features, model, N=10):
    item_representations = item_features.dot(model.item_embeddings)

    # Cosine similarity
    scores = item_representations.dot(item_representations[item_id, :])
    item_norms = np.linalg.norm(item_representations, axis=1)
    scores /= item_norms

    best = np.argpartition(scores, -N)[-N:]
    return sorted(zip(best, scores[best] / item_norms[item_id]), 
                  key=lambda x: -x[1])
3reactions
maciejkulacommented, Jan 4, 2018

This is correct. You can also use the get_<user/item>_representations methods to get the latent representations: http://lyst.github.io/lightfm/docs/lightfm.html#lightfm.LightFM.get_item_representations.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Similar items: Rich products feature on Google Images
The Similar items feature enables users to browse and shop inspirational fashion photography and find product info about items they're interested in. Try...
Read more >
Find Similar Products to Recommend to Users
Finding similar products based on machine learning is an effective way to get relatable products to use in marketing and in-app.
Read more >
Finding Similar Items - Zyte
This post describes an approach to the problem of finding similar items among crawled items and how this was implemented at Scrapinghub.
Read more >
Google Image Search app gets “similar items” shopping ...
The Google Image Search app for Android is getting a new “similar items” feature offering users a selection of products to buy related...
Read more >
How to Find Similar Items - YouTube
A short tutorial on how to find similar items within your DevonWay application. ... Get $300 PER DAY For FREE From AI Art...
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