Inspiration

Whenever you browse the internet you are bound to run into hateful messages or comments. The inspiration for this project came from the recent lawsuits against FaceBook due to their negligence in preventing hate on their site. This negligence played a part in the Jan. 6 riot at the Capitol and many other horrible events. I wanted to create a product that would make it easy for developers to prevent hate on their platforms. A simple profanity filter is not a great solution because while hate speech often contains profanity, they are not identical. Some developers may want to allow profanity on their site while still restricting hateful speech. There are also examples of hate speech that do not include profanity at all.

What it does

Using this Kaggle dataset, I trained a machine learning model to predict whether some given text is hate speech or not. I also created a Flask web server that uses this model to make predictions on incoming requests. Developers can simply make calls to this API to identify hate speech on their applications. The Github repo and API endpoint for the webserver are linked below. There is also a link to the demo page.

How we built it

First, I analyzed the data. I noticed that there were some malformed entries and that there were many more normal text examples than hate speech examples. I created a script to clean the data and also upsample the hate speech examples so that there was an equal number of positive and negative examples. I trained a classifier on this data using the sklearn library's stochastic gradient descent classifier (SGDClassifier). Then, I created a Flask web server that uses this model to respond to incoming requests. As of right now, the web server is hosted by Repl.

Challenges we ran into

Finding data for this hack was challenging. There were not many well-formed labeled datasets of hateful speech. I ended up using a dataset containing hateful (and not hateful) tweets to train my model. As I mentioned before, it took some work to clean and use the dataset. At first, I did not realize that the imbalance in example types was an issue for the model and spent a lot of time trying different types of classifiers. This was also my first time using Flask and creating a web server. It took me some time to learn how to handle uploading and downloading text from the webserver.

Accomplishments that we're proud of

I am proud that the model reached an accuracy of 93.1% and an f1 score of 93.4% on the test set. And, from my general testing, it seems to work well on all types of text even though it was only trained on tweets.

What we learned

The most valuable things I learned were how to use Flask and how to transfer JSON objects. I also learned a lot about the sklearn library and how to effectively use its tools.

What's next for EndHate

The most critical next step would be to move the web server onto a better hosting platform. Repl is definitely not the best option in terms of performance or maintenance. Another possibility is retraining the model on better data or creating a better model itself. It would be better if the model returned a probability rating instead of a binary output. Also, creating a way for clients to send labeled data back to the server would greatly increase the quantity and quality of the data. Right now, the model is probably overfitting the data because of the duplicate examples. Finally, we could start implementing EndHate on real platforms.

Built With

Share this project:

Updates