DEV Community

Cover image for Find “Toxicity/Profanity” of a comment using Google Perspective
Sandesh B Suvarna (Iconic.wtf)
Sandesh B Suvarna (Iconic.wtf)

Posted on

Find “Toxicity/Profanity” of a comment using Google Perspective

Social media has become a huge part of everyone’s lives. As of 2017, daily social media usage of global internet users amounted to 135 minutes per day. When it comes to extreme averages, teenagers take the prize. Their daily average time spent on social media is nine hours a day. That’s longer than most people spend sleeping or in school.

As we spend increasing amounts of time online, and new technologies allow us to connect further in the virtual world, the further we connect, the further we create online issues. One such major issue is online harassment.

In a survey of over 3,000 Americans, 47% reported experiencing some sort of online harassment or abuse. To curb this issue, one of the steps taken from Google is to come up with a technology which could help improve online conversations. Introducing Google Perspective.

Google Perspective:

Perspective is an API that makes it easier to host better conversations. The API uses machine learning models to score the perceived impact a comment might have on a conversation. Developers and publishers can use this score to give real-time feedback to commenters or help moderators do their job, or allow readers to more easily find relevant information. Perspective identifies whether a comment could be perceived as “toxic” to a discussion.

How to use Google Perspective?

  1. Well, first you need access to Google’s Perspective API. Which can be availed by getting whitelisted by the perspective team. Apply here

  2. Once you get whitelisted, go ahead & create a Google Cloud project.

  3. Search for ‘Perspective API’ from the list of Google API’s, then go to the Perspective API’s overview page and click Enable.

  4. To authenticate your requests, you’ll need to generate credentials for your project. Using an API key is the simplest option. Go to the API credentials page, click Create credentials, and choose “API Key”.

Now you have everything, except a nodejs client to find “Toxicity/Profanity” of a comment using Google Perspective.

Tada…. & here is your open source nodejs client for Google Perspective:
I, open sourced a nodejs client for Google perspective with a clear-cut documentation for a quick start. Click on the below link, use it & feel free to raise an issue if you find any.

GitHub logo sandeshbsuvarna / Comment-Toxicity-Profanity-Analyzer

Comment Toxicity/Profanity Analyzer, will help help increase empathy, participation and quality in online conversation at scale using Google's perspective api

Comment Toxicity/Profanity Analyzer | Nodejs, Google Perspective API

npm version node version

Comment Toxicity/Profanity Analyzer, will help help increase empathy, participation and quality in online conversation at scale. #ConversationAI #GooglePerspectiveAPI

Quick Start

  1. Get whitelisted to use perspective api To use the API, your you need to have your email address whitelisted. Apply here.

  2. Create a Google Cloud project. Go to the Google Cloud console to create a new project You can also use an existing project, if you have one.

  3. Enable the API. Once you've been whitelisted, you'll be able to enable the API in for your project. Go to the Perspective API's overview page and click Enable.

  4. Generate an API key. To authenticate your requests, you'll need to generate credentials for your project. Using an API key is the simplest option. Go to the API credentials page, click Create credentials, and choose "API Key".

  5. Make an AnalyzeComment request

                    The Internet Should Be a Good Place

Discussion (8)

Collapse
ben profile image
Ben Halpern

At DEV we use this as one of our signals to alert mods/admins of conversations which may need intervention.

Easy enough to get started with. Pretty happy so far.

Collapse
sandeshsuvarna profile image
Sandesh B Suvarna (Iconic.wtf) Author

Super cool. We are working on a similar tech for Celebrities though.

Collapse
stacy profile image
Stacy Montemayor

Pushshift.io is using Perspective to assign a toxicity score to their website that is tracking toxicity on Gab in realtime. This new project was only online briefly a couple of nights ago and it was actually shocking to see the hate people are posting over there. It's been offline since that first night, but hopefully, it will be back online soon. I love seeing us develop tools to address hate and hatespeech.

Collapse
deepu profile image
Deepu

Hey Sandesh, thanks for this.
Just want to know what’s the criterion for getting whitelisted by perspective team ?

Collapse
sandeshsuvarna profile image
Sandesh B Suvarna (Iconic.wtf) Author

I got it through easily. Just apply.

Collapse
sandeshsuvarna profile image
Sandesh B Suvarna (Iconic.wtf) Author
  1. Link: businessinsider.in/A-new-study-sug...

  2. Your "point 2" needs a Google perspective filter ;)