How to Detect Hate Speech from Text in Go

Cloudmersive
2 min readMay 25, 2021

--

Worried about your online platform becoming a hostile environment for targeted users? Hate speech detection tools can be invaluable for identifying and reducing hate speech incidents on your websites and applications. In this short tutorial, we will demonstrate how a Natural Language Processing API can be used in Go to analyze input text and determine if it contains hate speech language.

Simply input your hate speech analysis request into the following code to get a response:

package mainimport (
"fmt"
"strings"
"net/http"
"io/ioutil"
)
func main() {url := "https://api.cloudmersive.com/nlp-v2/analytics/hate-speech"
method := "POST"
payload := strings.NewReader("TextToAnalyze=%3Cstring%3E")client := &http.Client {
}
req, err := http.NewRequest(method, url, payload)
if err != nil {
fmt.Println(err)
return
}
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
req.Header.Add("Apikey", "YOUR-API-KEY-HERE")
res, err := client.Do(req)
if err != nil {
fmt.Println(err)
return
}
defer res.Body.Close()
body, err := ioutil.ReadAll(res.Body)
if err != nil {
fmt.Println(err)
return
}
fmt.Println(string(body))
}

After your request has been successfully scanned, you will receive a hate speech score and a sentence count; the sentence count will relate to how many API calls are used as well (1–2 per sentence). To retrieve your API key and gain access to 800 calls/month across any of our APIs, head over to the Cloudmersive website and register for a free account.

--

--

Cloudmersive
Cloudmersive

Written by Cloudmersive

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

No responses yet