bonkerfield

A GPT2+BERT reddit reply bot in 20 minutes

There's a new subreddit called talkwithgpt2bots that's intended to let people interact with AI based comment bots. I got my tupperware-party bot working again on there, but it would be awesome to have a bunch of bots interacting there. To help others get started building comment bots, I figured I could simplify my previous GPT2-BERT tutorial to be even simpler to run.

I put all of the code, data, and models for tupperware-party in one place. Below I've written out a guide to run a duplicate of my bot explaining each of these steps:

  • 1. Make a reddit app so your bot has credentials
  • 2. Copy the data and notebooks into your Google Drive home directory
  • 3. Enter your credentials into the Google Colab notebooks
  • 4. Run the *step1.ipynb notebook and let it finish
  • 5. Run the *step2.ipynb notebook

Below, I'll go into those 5 steps in a little more detail.

Update 05/01: I've added a new bot script that doesn't just reply in place. The new script pulls a comment from another subreddit and adds it to our talkwithgpt2bots subreddit along with an AI generated reply.

1. Make a reddit app

Your bot will need credentials to post replies on reddit. Reddit apps are completely free to make. To get your app credentials set up you can follow the following directions (which I addapted from this page).

Go to your app preferences. Click the "Create app" or "Create another app" button. Fill out the form like so:

    name: My Example App
    App type: Choose the "script" option
    description: You can leave this blank
    about url: You can leave this blank
    redirect url: http://www.example.com/unused/redirect/uri (We won't be using this as a redirect)

Hit the "create app" button. Make note of the client ID and client secret. For the rest of this page, it will be assumed that:

2. Copy the data and all the code on Google Drive

I've put all the code, all the data you'll need, and the pretrained models into this shared folder on Google Drive. Open that and make save your own copy to your Google Drive.

Note: You need to save all of that into the top level folder of your Google Drive. The example code assumes that all of the necessary files are sitting in the top level (ie "My Drive" not a subfolder).

3. Enter your credentials

Once you have your own copies, you need to edit the two Google Colab notebooks (reddit_reply_bot_simple_step1.ipynb and reddit_reply_bot_simple_step1.ipynb) with the specific details for your reddit app from Step 1 above. All the changes should take place right at the top of the file.

You can change the name of the intermediate file (save_to_drive_csv_name = 'proposed_replies_testing.csv') to whatever you want.

4. Run reddit_reply_bot_simple_step1.ipynb

With your credentials you can now run the script that creates replies. There are two additional parameters that you can change, which will randomize the output message. If you leave these params the same, your bot will exactly match what tupperware-party says.

When you're ready, press the play button in the top left corner. It will spin for a while and a bunch of text will start to be outputed below. Eventually, the following prompt will appear.

Follow the link to mount your Google Drive into the Google Colab environment. This allows you to load the pretrained models.

After a bit longer the script will finish, and you'll have saved a bunch of candidate replies in the file save_to_drive_csv_name. Then you are ready to move onto step 2.

5. Run reddit_reply_bot_simple_step2.ipynb

Now open the step2 notebook, make sure the credentials are the same as from part 1. There are a few other parameters that you can edit here. They control how strongly you filter the replies. Edit them how you like, if you don't get any results make these filters less stringent.

Run the script by pressing the play button. More stuff will be printed out, and you'll need to mount your Google Drive just like in step 4. This one will take even longer to run. Eventually you will see some output that contains REPLYING NOW WITH: like the following.

When this is being printed, the bot should be submitting responses in real-time. You can log onto reddit and find the corresponding threads to see its response there. Or go to your bots home page (reddit.com/user/{your_bot_name}) to see all of its comments.

*Bonus: Generating posts from replies in other subreddits.

I've added two additional scripts in the Google Drive folder called reddit_post_bot_simple_step1.ipynb and reddit_post_bot_simple_step2.ipynb. As their names suggest, these bots will actually generate new posts on talkwithgpt2bots based off of comments from other subreddits. You can use them in exactly the same way as the above two scripts but they have a few extra features. I challenge you to figure out the details, but feel free to ask questions.

Questions?

If you run into any issues or if there's something confusing, please let me know. I'll be quickest to respond on Twitter or Mastodon. You can learn more about this project here or learn how to customize this bot on new input data here. Have fun with this, but please, think before you use it for something bad.


Discussion Around the Web


Join the Conversation