In this blog post we would try to do a multilabel (6 target classes) NLP Toxic comment classification for a previously Kaggle hosted competition. Please see below the competition overview from the Kaggle page:
Discussing things you care about can be difficult. The threat of abuse and harassment online means that many people stop expressing themselves and give up on seeking different opinions. Platforms struggle to effectively facilitate conversations, leading many communities to limit or completely shut down user comments.
The Conversation AI team, a research initiative founded by Jigsaw and Google (both a part of Alphabet) are working on tools to help improve online conversation. One area of focus is the study of negative online behaviors, like toxic comments (i.e. comments that are rude, disrespectful or otherwise likely to make someone leave a discussion). So far they’ve built a range of publicly available models served through the Perspective API, including toxicity. But the current models still make errors, and they don’t allow users to select which types of toxicity they’re interested in finding (e.g. some platforms may be fine with profanity, but not with other types of toxic content).
In this competition, you’re challenged to build a multi-headed model that’s capable of detecting different types of of toxicity like threats, obscenity, insults, and identity-based hate better than Perspective’s current models. You’ll be using a dataset of comments from Wikipedia’s talk page edits. Improvements to the current model will hopefully help online discussion become more productive and respectful.
Disclaimer: the dataset for this competition contains text that may be considered profane, vulgar, or offensive
Toxic Comment Classification Challenge | Kaggle
In the below code walk through we will try to use an embedding layer along with LSTM layer and fully connected layer to form a neural network architecture which will be trained using pytorch lightning which makes the training steps much easier and cleaner. We will also use the torch text module which comes from pytorch itself which makes creation of vocabulary easier. Please follow the comments provided in the notebook itself to understand more about the code.
Please note this model architecture is not the optimal one, this is only for tutorial purpose. Try with different architectures, more epochs, different batch sizes to come up with better results.
Do like, share and comment if you have any questions.