Ever since social media came, the amount of hate speech people experience has risen exponentially. Now, platforms like Twitter and Facebook are working around the clock to stop hate speech on their platform, but discord hasn't done much. Primarily because there are actual life moderators who watch over servers to ensure that all talk is safe, but this is a big problem for big servers. Big servers like Valorant and Genshin Impact have about 300,000 people online, but only 20 mods are online at a time. The vast inequality and the fact that mods don't spend all their time on discord to stop racist people make it worse. Mods sleep, and they have their own lives to live, so there isn't a sure-fire way to keep servers clean 24/7, which was why we came up with an idea to fix this issue.
What it does:
If someone says any hate speech, The Bot will kick them from the server and delete the message they sent. While it doesn't solve the problem 100 percent, it will help mitigate the situation we are tackling. Our code works best for 0 tolerance servers because it will keep these people from spreading hateful messages. It is online 24/7, so it will constantly be watching and waiting for people to say something harmful. We are on many different servers, and not one of them has a bot that can stop the use of hate speech.
How we built it
The basic Bot: We started with a basic bot tutorial that we found on YouTube. The Title was ‘Code a Discord Bot with Python - Host for Free in the Cloud’. The man who was making the video showed how to make a simple bot that sends encouraging messages. We took it and improved upon it, allowing our Bot to kick people using hate speech and delete their harmful messages.
We built the deep learning model using the power of the Tensorflow Framework. We created a one-dimensional Convolutional Neural Network trained on over 20 thousand tweets featuring words used in hate speech. Our model then learned to separate hate speech tweets from harmless tweets from each other with an accuracy of 89.75%. We then hosted the model on a free Heroku server so that our discord bot can call it whenever it sees a message that contains one of the words in our list of words that can appear in hate speech. If the server says that the message includes hate speech, our Bot will kick the user from the server and delete the hateful message.
Challenges we ran into
We ran into many challenges: some were simple errors like an indenting error or a missing colon. Others were much more cryptic and troublesome; we first found a list of racist and hateful language, which is much harder said than done, as most of the data was very unequal in hate speech and not hate speech text. It took us a day of searching to find the perfect data set. Then to use the AI portion of our Bot, we had to find a suitable model. We experimented with all kinds of different model architectures and we fine-tuned the models in many different ways until we decided on the best one. The biggest challenge we ran into was when we tried to integrate our model into our Bot. It turns out the Tensorflow library we needed to import is extremely large, and almost all servers we tried hosting on wouldn't allow importing an extensive library. First, we tried to experiment with pickling the model, but that only worked with basic machine learning algorithms, so we tried to make a Naive Bayes model that we could pickle, but it only had an accuracy of 79%, which was much worse than our deep learning model with an accuracy of 89.75%. Eventually, we found out about a smaller TensorFlow library called TensorFlow CPU, which Heroku would allow. Our problem turned out to be a blessing in disguise because once we hosted it onto Heroku, we created a rest API that anyone could use. Because of this problem we encountered, we could adapt and make our project more flexible and usable by others.
Accomplishments that we're proud of
Our biggest accomplishment has to be adding the deep learning model into our Bot. We are very proud of its accuracy and speed in detecting hate speech. Because we posted it up into its server and created our own rest API, we could reproduce this hate speech bot into any other chat platform.
What we learned
We learned some different lessons; Nilay learned how to create a basic discord bot and host it on a repl server using a flask. Dhruv learnt how to optimize data pipelines, make quick NLP models on the fly, experiment on them in different ways, integrate TensorFlow models into Heroku, and make functional APIs with python.
What's next for KAR/P
Now that our Bot is live, we hope to spread it to multiple servers and hopefully replicate it into different chat platforms like Slack. Since we made our model into an API that anybody can call for free, we hope others can also use our model to combat hate speech in their communities.
Few side notes:
The model is only trained on text that uses words that are found in hate speech, so it will not do so well on normal text that have no suspicious words. On text WITH the words in question, our model has an accuracy of 89.75%. That's why we made sure the bot would only ask the model if it detects one of the words in our list.
If you want to try out our model's api, type this into your searchbar: https://cnnhackathon.herokuapp.com/predict/?text=your text here (it only does good on text containing suspicious words that could be used in hate speech)
Log in or sign up for Devpost to join the conversation.