Inspired by Perspective API and its real-time comment moderation tools, this Nifty Assignment is about improving online conversations by implementing a decision tree data type for text classification.
Online abuse and harassment stops people from engaging in conversation. One area of focus is the study of negative online behaviors, such as toxic comments: user-written comments that are rude, disrespectful or otherwise likely to make someone leave a discussion. Platforms struggle to effectively facilitate conversations, leading many communities to limit or completely shut down user comments. In 2018, the Conversation AI team, a research initiative founded by Jigsaw and Google (both part of Alphabet), organized a public competition called the Toxic Comment Classification Challenge to build better machine learning systems for detecting different types of of toxicity like threats, obscenity, insults, and identity-based hate.
Machine learning models are trained on human-selected and human-generated datasets. Such models reproduce the bias inherent in the data. The included data representation algorithms also encode overly-simplistic assumptions about natural language by treating each occurrence of a word as independent from all other words in the text. Any usage of a word, no matter the context, is considered equally toxic. Don’t use this in a real system!
When the Conversation AI team first built toxicity models, they found that the models incorrectly learned to associate the names of frequently attacked identities with toxicity. In 2019, the Conversation AI team ran another competition about Unintended Bias in Toxicity Classification, focusing on building models that detect toxicity across a range of diverse conversations.
The provided datasets contain text that may be considered profane, vulgar, or offensive.
Toxic comment classification is a special case of a more general problem in machine learning known as text classification. Discussion forums use text classification to determine whether comments should be flagged as inappropriate. Email software uses text classification to determine whether incoming mail is sent to the inbox or filtered into the spam folder.1
jarfiles from the Smile project.
The simplest way to use the text classifier is through the web app. The first visit may take 30–60 seconds for the server to wake up and train the model.
The assignment specification (spec.mhtml) contains all of the information that students need to get started. To run the project locally, download the code from GitHub and implement (or stub) each required method in the
Compile and run the
Main class to compute the classifier’s training accuracy.
javac -cp ".:lib/*" Main.java && java -cp ".:lib/*" Main
Compile and run the
Server class to launch the Nifty Web App.
javac -cp ".:lib/*" Server.java && java -cp ".:lib/*" Server toxic.tsv
A JUnit 5
TextClassifierTest class is provided, though it requires a
GoodTextClassifier reference solution with a modified
Google Developers. Oct 1, 2018. Text classification. In Machine Learning Guides. https://developers.google.com/machine-learning/guides/text-classification ↩
Amy J. Ko, Alannah Oleson, Neil Ryan, Yim Register, Benjamin Xie, Mina Tari, Matthew Davidson, Stefania Druga, and Dastyni Loksa. 2020. It is time for more critical CS education. Commun. ACM 63, 11 (November 2020), 31–33. https://doi.org/10.1145/3424000 ↩ ↩2
Kevin Lin, Sumant Guha, Joe Spaniac, and Andy Zheng. 2020. Nifty Web Apps: Build a Web App for Any Text-Based Programming Assignment. In Proceedings of the 52nd ACM Technical Symposium on Computer Science Education (SIGCSE ‘21). https://doi.org/10.1145/3408877.3432580 ↩