Detecting the sentiment, emotion and sarcasm of a message and replying with a suitable smily.

Image for post

smily-bot with my colleagues

Motivation

I have been reading a lot of paper articles lately, mostly on Deep Learning, RNN, CNN, LSTM[1], Transformer(Attention is all you need)[3], BERT etc. The list is only growing. But the best way to learn anything is to experience it. And also if I deploy a bot with my face, in my office server it can give proxy for me sometimes when I am busy reading. 😜 Just Kidding. As an experienced software developer its just an urge to implement the new knowledge acquired.

But there are some big hindrances. Where will I get so much data to train a Neural Net? Even if I manage data, I will need a machine with hi-fi configuration or at-least with a powerful GPU to train my model with the data. But,** if there is a will there is way**. 🤓 After a bit of research I found, DeepMoji 🧙🏻‍♂️. We can use pre trained models like DeepMoji to implement our bot. It’s a common practice now a days to work on a pre-trained model and make it better according to the need.

This is a perfect opportunity for me to make a BOT in discord(as my office communication is held in discord) and experience how a NLP process works using a varient of LSTM and attention mechanism. This BOT can listen to all the messages being received and react with emoticons.

DeepMoji

DeepMoji is a model built on Keras and the backend on Tensorflow. Deepmoji is based on this paper[2] developped by Bjarke Felbo, Alan Mislove, Anders Søgaard, Iyad Rahwan and Sune Lehmann.

This paper shows that by extending the distant supervision to a more diverse set of noisy labels, the models can learn richer representations. Through emoji prediction on a dataset of 1.2 billion tweets containing one of 64 common emojis they have obtained state-of-the-art performance on 8 benchmark datasets within sentiment, emotion and sarcasm detection using a single pretrained model.

TorchMoji

TorchMoji is a pyTorch implementation of the DeepMoji model built by huggingface. DeepMoji is built on python 2.7. So we will use TochMoji which is a implementation in python3. So we will use torchmoji for our implementation.

Setup

The most hectic part for me in this journey was the setup. Because I couldn’t find any proper example to implement torchMoji in a project. All the examples are the test cases used in jupyter notebook. But I am particularly interested in implementing it inside a project using my VS Code so that I can connect it with my discord BOT and send a response from there.

You can see my full code here:

https://github.com/anuragbhattacharjee/discord-nlp-smily-bot/

*** Giving ⭐️ Star on github repositories helps us both grow. You will get all the updates of the project and I will get the inspiration to update the project.

So Let’s Start.

1. Setting up Discord BOT

Setting up discord bot is straight forward. Navigate to application page. Create an application and then create a bot under your application.

After creating the BOT you will see their are several settings for the BOT. You will be needing your BOT Token under your Bot settings to connect it from your code.

If you go to the OAuth2 settings you can create a link with needed permission and by clicking the link a discord server owner can add the bot to their server. For testing purpose I created a server for myself and added the bot first before testing it in my office server.

At this point you should see the bot has joined in your server. But it’s offline. Because we are yet to connect it to our code to give it a life. 🤖❤

If you had any problem creating the discord bot, follow detail visual steps in the link below:

Creating a Bot Account - discord.py 1.4.0a documentation

In order to work with the library and the Discord API in general, we must first create a Discord Bot account. Creating…

discordpy.readthedocs.io

2. Setting up python environment

I spent a lot of time here. Because the torchMoji was saying to use Conda to brew the project. But I was facing a round of errors while trying to download all the dependencies.

Though you can use any of the environment management tool as you prefer (conda/venv), you just need to know how to use it. Conda is mostly preffered while using in data science because they set up all the environment packages needed in one go. Which is easier. But Venv is more flexible I think.

#lstm #deep-learning #naturallanguageprocessing #nlp #discord #deep learning

I created a Deep Learning powered Discord Bot to react with smily 😎
1.80 GEEK