Are you indulging in a toxic conversation?

Original article was published on Deep Learning on Medium

To start with, we assume that the reader is familiar with the basics of Deep Learning and Python. If not, here are some basics of Deep Learning and Python to start with.

DATASET USED

We tackled this problem in a supervised learning setup. The dataset used in this project is from Jigsaw/Conversation AI. The dataset consists of ~2m public comments from the Civic Comments platform. This dataset served as our training and validation set.

The data consists of the following toxicity attributes:

  • severe_toxicity
  • obscene
  • threat
  • insult
  • identity_attack
  • sexual_explicit

In this work, we do not classify the attributes of the toxic comments. Rather we tackle the problem in a binary fashion: Toxic or Non-Toxic.

NETWORK USED

For our task, we used XLM-ROBERTa (XLM-R), which is a powerful transformer-based unsupervised model. It is a cross-lingual sentence encoder network that obtains state-of-the-art results on many cross-lingual understanding benchmarks.

Source

XLM-R is trained on 2.5T filtered CommonCrawl data in 100 languages. More information can be found here and the official implementation is available here.

TRAINING

We trained our network on a single 12 GB Nvidia GPU. We also used Google Colab, to experiment with the TPUs settings. We trained our network for 2 epochs and achieved a validation accuracy of around 85%.

As the end goal of the project was to create a web application, the trained network weight was quite large. So we compressed the saved model and reduced it’s size from 3GB to 1GB. The final weight is provided here to download.

TESTING

As we have our trained model ready, we will now move on towards building our final application. In order to test our application, we scraped comments from various social media platforms, but we realized it might be unethical in some sense to release it publically.

So, we limited the scope of this project to YouTube comments only.

We scraped the user comments from a given YouTube video URL and pass it to our trained model. We output the predicted toxic/non-toxic metrics on our application homepage.

DEPLOYMENT

As our final goal is to host this project as a web application, we used Flask for hosting the app and HTML with CSS for web styling.

Flask is a web framework that provides tools, interfaces, libraries and technologies to build a web application.