How to Detect Hate Speech from English Text in Ruby

Advances in Natural Language Processing have made it possible to perform functions that were previously out of scope, such as analysis of sentiment, obscenities, hate speech, and more in text. In this tutorial, we will be focusing on how you can use hate speech detection in particular to ensure a safe online environment for your users. The following API can be run in Ruby to analyze English text and determine if it contains hate speech language.

Installation of the Ruby client can be accomplished by adding the following to your Gemfile:

gem 'cloudmersive-nlp-api-client', '~> 3.0.3'

Once the installation is complete, you can call the hate speech analysis function:

# load the gem
require 'cloudmersive-nlp-api-client'
# setup authorization
CloudmersiveNlpApiClient.configure do |config|
# Configure API key authorization: Apikey
config.api_key['Apikey'] = 'YOUR API KEY'
# Uncomment the following line to set a prefix for the API key, e.g. 'Bearer' (defaults to nil)
#config.api_key_prefix['Apikey'] = 'Bearer'
api_instance = CloudmersiveNlpApiClient::AnalyticsApi.newinput = # HateSpeechAnalysisRequest | Input hate speech analysis requestbegin
#Perform Hate Speech Analysis and Detection on Text
result = api_instance.analytics_hate_speech(input)
p result
rescue CloudmersiveNlpApiClient::ApiError => e
puts "Exception when calling AnalyticsApi->analytics_hate_speech: #{e}"

There’s an API for that. Cloudmersive is a leader in Highly Scalable Cloud APIs.