Code Monkey home page Code Monkey logo

reddit-recommender's Introduction

Image of the reddit recommender

Introduction

Reddit Recommender is a tool to discover new subreddits. To use it, you can either enter a subreddit name in the search bar or click on a node in the graph. A list of similar subreddits will appear on the sidebar. Clicking any of the recommended subreddits will open it on a new tab. Using the button at the bottom of the sidebar will create a multi reddit with all the subreddits in the list.

NSFW subreddits are hidden by default, but can be toggled using the "Show NSFW content" button.

How it works

Generating subreddit relationships

The algorithm uses a content based approach to correlate subreddits. For this step, I used post data from June 2021 to May 2022 from Pushshift.

  1. Get the top posts for each subreddit.
  2. Feed the post titles through the all-MiniLM-L6-v2 sentence transformer to get a vector embedding for each post. The model used produces 384 dimensional embeddings.
  3. Calculate each subreddit's vector embedding by performing weighted average on its posts' embeddings. For the weight of each post embedding we use the karma score. This results in an embedding vector that represents the subreddit's subject matter.
  4. Calculate the weight of a connection between 2 subreddits using cosine distance. (Note: Smaller distance โ†’ Larger weight)
  5. Keep the top connections on each subreddit. Additionally, discard connections below a certain threshold.

Visualization

The full graph contains more than 132K subreddits, but we can only visualize about 40-50K nodes without hindering performance. I extracted the top 45K subreddits into a separate graph, and imported it into Gephi. I used the Leiden community detection algorithm to form clusters and the Circle Pack layout to position them.

On the front end, I used the ngraph package along w-gl to visualize my results.

Discussion

  • This project was initially inspired by Andrei Kashcha's Map of Reddit. I wanted to explore the effectiveness of sentence transformers, so I decided to adopt an ML approach to solve the problem of creating the subreddit graph. My content based technique seems to provide solid subreddit recommendations even on large subreddits, which is harder to do using a user overlap based approach (mainly due to reddit's old default subreddit policy).
  • One peculiarity of my approach is that the algorithm often creates strong connections between subreddits of vastly different sizes. This may or may not be welcome. For this reason, I have added the ability to provide recommendations by taking into account the size of each related subreddit, prioritizing connections with more popular subreddits.
  • Clustering can be performed in a number of ways. I chose to use the Leiden algorithm because it is very fast, it provides very good results, and doesn't require the number of clusters as input.
  • I decided to remove any connections between the SFW and NSFW subreddits that may be created by the algorithm. The SFW and NSFW are completely disjoint.

Acknowledgments

Final Note

This was my first time writing Javascript so I probably messed a few things up. However, I am pretty happy with how the website turned out :)

Licence

MIT

reddit-recommender's People

Contributors

arischristoforidis avatar

Stargazers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.