Weapon Detection is an optional capability that is made available as part of Sightengine's Text Moderation APIs. This capability is useful to detect if user-generated texts (comments, messages, posts, reviews, usernames, etc.) contain words related to weapons.
Other categories are also available through the Text Moderation API, for instance Extremism Detection, Drug Detection and Medical Drug Detection.
If you have images or videos, you might also want to use the Weapon Detection API for Visual content, to detect firearms and threatening knives in user photos and videos.
Detected text items are common names referring to weapons but also proper names like brands selling weapons or weapon models.
Here are a few examples of the names of weapons that are detected:
Type of words | Examples |
common nouns |
handgun, rifle, carabin... |
models |
AK-47, HK33, PT 1911... |
brands |
Imbel, Colt, Kalashnikov... |
The API is a lot stronger than simple word-based filters. It catches not only exact weapon-related terms but also all kinds of variations (millions of them) that might be used to evade filtering while smartly ignoring false positives.
Here are a few examples of the types of obfuscations that will be caught (not exhaustive):
Obfuscation | Example |
Repetitions | bereeeetta |
Insertions | c_ o - -l*t |
Obfuscation and Special characters | 🄶u̸ń |
Spelling mistakes and phonetic variations | onyks |
Leet speak | 1m|3€L |
Smart embeddings | usemyrifle but not trifle |
The Weapon category can be activated for all languages supported by the Text Moderation API. For most languages, detection will focus on international names of weapons that are known worldwide, and additional language-specific words and expressions are added for English.
The Weapon Category can be activated as part of Standard Text Moderation and Username Moderation. To activate this category, you need to add an extra request parameter named categories. This parameter is a comma-separated list of categories you want to activate. For weapon detection, its value would be weapon
Let's say you want to detect references to weapons in the following text item:
bringing my ka|@Sɧᾑikø\/
Simply send a POST request containing the UTF-8 formatted text along with the comma separated list of categories you want to detect and the ISO 639-1 language code (such as en for english). Here is an example:
curl -X POST 'https://api.sightengine.com/1.0/text/check.json' \
-F 'text=bringing my ka|@Sɧᾑikø\/' \
-F 'lang=en' \
-F 'categories=weapon' \
-F 'mode=rules' \
-F 'api_user={api_user}' \
-F 'api_secret={api_secret}'
# this example uses requests
import requests
import json
data = {
'text': 'bringing my ka|@Sɧᾑikø\/',
'mode': 'rules',
'lang': 'en',
'categories': 'weapon',
'api_user': '{api_user}',
'api_secret': '{api_secret}'
}
r = requests.post('https://api.sightengine.com/1.0/text/check.json', data=data)
output = json.loads(r.text)
$params = array(
'text' => 'bringing my ka|@Sɧᾑikø\/',
'lang' => 'en',
'categories' => 'weapon',
'mode' => 'rules',
'api_user' => '{api_user}',
'api_secret' => '{api_secret}',
);
// this example uses cURL
$ch = curl_init('https://api.sightengine.com/1.0/text/check.json');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
$response = curl_exec($ch);
curl_close($ch);
$output = json_decode($response, true);
// this example uses axios and form-data
const axios = require('axios');
const FormData = require('form-data');
data = new FormData();
data.append('text', 'bringing my ka|@Sɧᾑikø\/');
data.append('lang', 'en');
data.append('categories', 'weapon');
data.append('mode', 'rules');
data.append('api_user', '{api_user}');
data.append('api_secret', '{api_secret}');
axios({
url: 'https://api.sightengine.com/1.0/text/check.json',
method:'post',
data: data,
headers: data.getHeaders()
})
.then(function (response) {
// on success: handle response
console.log(response.data);
})
.catch(function (error) {
// handle error
if (error.response) console.log(error.response.data);
else console.log(error.message);
});
See request parameter description
Parameter | Type | Description |
text | string | UTF-8 encoded text to moderate |
mode | string | comma-separated list of modes. Modes are rules for the rule-based model or ml for ML models |
categories | string | comma-separated list of categories to check. Possible values: profanity, personal, link, drug, weapon, violence, self-harm, medical, extremism, spam, content-trade, money-transaction (optional) |
lang | string | comma-separated list of target languages |
opt_countries | string | comma-separated list of target countries for phone number detection (optional) |
list | string | id of a custom list to be used for rule-based moderation (optional) |
api_user | string | your API user id |
api_secret | string | your API secret |
The JSON response contains a description of profanities with positions within the text string.
{
"status": "success",
"request": {
"id": "req_c2mc7oJALbqQ1zbOeCnyo",
"timestamp": 1655368825.090044,
"operations": 1
},
"profanity": {
"matches": []
},
"personal": {
"matches": []
},
"link": {
"matches": []
},
"weapon": {
"matches": [
{
"type": "weapon",
"match": "kalashnikov",
"start": 0,
"end": 11
}
]
}
}
See our full list of Text models for details on other filters and checks you can run on your text content. You might also want to check our Image & Video models to moderate images and videos. This includes moderation of text in images/videos.
Was this page helpful?