Documentation
Contents
Introduction
Detox is a client-side library that detects toxic text messages using pre-trained AI models. It consists of two components:
The library to be imported into your client, and
The data file that contains weights and settings for the AI models.
After importing the Detox library and loading the data file, initialize the Moderator object. Then, simply pass each chat message through the Moderator to check if the message is toxic. See the Implementation section for further details.
What you do after detecting a toxic message is up to you. We recommend performing recipient-side filtering (i.e. checking and blocking toxic messages when received) as opposed to sender-side blocking (i.e. stopping toxic messages from being sent). This reduces the likelihood of filter evasion, where players intentionally try to get around the filters, and it gives your players the freedom to opt out of the feature should they wish to.
Implementation
The Moderator class is the entry point to Detox and should be initialized when the game client is launched. It has one required argument for initialization: the Detox data file.
While the game is running, Moderator has optional event listeners that can be triggered in reaction to in-game events. These events provide the Moderator with contextual information so it can more accurately identify toxicity in chat. See the sections below on Threat Level and New Player Protection for more information.
When a chat message is sent or received, use the isToxic method to analyze the message and output a Boolean for whether the message is considered toxic.
Loading Client
const Detox = require('./detox.js');
const fs = require('fs');
let detoxData = JSON.parse(fs.readFileSync('.../Detox_Data.json'));
// Initialize Moderator and set base filter strictness
var moderator = new Detox.Moderator(detoxData, Detox.Strictness.STRICT);
using Detox;
string detoxData = System.IO.File.ReadAllText(@".../Detox_Data.json");
// Initialize Moderator and set base filter strictness
Moderator moderator = new Moderator(detoxData, Strictness.STRICT);
import detox, json
detox_data = json.load(open('.../Detox_Data.json'))
# Initialize Moderator and set base filter strictness
moderator = detox.Moderator(detox_data, detox.Strictness.STRICT)
local Detox = require "detox"
-- See download page of the data file for sample code on loading JSON
local detoxData = json.decode(readall('.../Detox_Data.json'))
-- Initialize Moderator and set base filter strictness
moderator = Detox.Moderator.new(detoxData, Detox.Strictness.STRICT)
Game Events
// For new players, provide greater protection against toxicity
moderator.newPlayerProtection(true);
// Stricter filter during heightened times (e.g. player death)
moderator.increaseThreat();
// For new players, provide greater protection against toxicity
moderator.NewPlayerProtection(true);
// Stricter filter during heightened times (e.g. player death)
moderator.IncreaseThreat();
# For new players, provide greater protection against toxicity
moderator.new_player_protection(True)
# Stricter filter during heightened times (e.g. player death)
moderator.increase_threat()
-- For new players, provide greater protection against toxicity
moderator:newPlayerProtection(true)
-- Stricter filter during heightened times (e.g. player death)
moderator:increaseThreat()
Chat Messages
function messageReceivedCallback(message) {
let messageToxic = moderator.isToxic(message);
if (messageToxic) {
// Do something, e.g. don’t show the message
}
}
private void MessageReceivedCallback(string message) {
bool messageToxic = moderator.IsToxic(message);
if (messageToxic) {
// Do something, e.g. don’t show the message
}
}
def message_received_callback(message):
message_toxic = moderator.is_toxic(message)
if message_toxic:
# Do something, e.g. don’t show the message
pass
local function messageReceivedCallback(message)
local messageToxic = moderator:isToxic(message)
if messageToxic then
-- Do something, e.g. don’t show the message
end
end
Filter Strictness
The Detox filter can be set at three levels of strictness: LENIENT, STRICT, and VERY_STRICT. A stricter filter identifies a greater number of toxic messages, but at the cost of being more restrictive for players.
LENIENT: Only strongly demeaning messages or profanity-laden text are considered to be toxic. Most suitable for mature games.
STRICT: Insults and aggressive language are considered to be toxic. Suitable for a general audience.
VERY_STRICT: Messages with profanities or negativity are considered to be toxic. Suitable as an overly cautious approach for a young audience.
The strictness level is provided as the second argument when initializing the Moderator using values from the Detox.Strictness class.
// Optional second argument defaults to Detox.Strictness.LENIENT
var lenientModerator = new Detox.Moderator(detoxData);
// Specify strictness level when initializing Moderator
var strictModerator = new Detox.Moderator(detoxData, Detox.Strictness.STRICT);
// Optional second argument defaults to Strictness.LENIENT
Moderator lenientModerator = new Moderator(detoxData);
// Specify strictness level when initializing Moderator
Moderator strictModerator = new Moderator(detoxData, Strictness.STRICT);
# Optional second argument defaults to detox.Strictness.LENIENT
lenient_moderator = new detox.Moderator(detox_data)
# Specify strictness level when initializing Moderator
strict_moderator = new detox.Moderator(detox_data, detox.Strictness.STRICT)
-- Optional second argument defaults to Detox.Strictness.LENIENT
lenientModerator = Detox.Moderator.new(detoxData)
-- Specify strictness level when initializing Moderator
strictModerator = Detox.Moderator.new(detoxData, Detox.Strictness.STRICT)
Threat Level
Set threat level to reflect the imminent threat of players being toxic due to in-game events, such as deaths, losses, and other occurrences that increase tension between players. Threat dynamically changes the filter strictness, allowing you to tighten the reins to proactively stop a flame war and prevent toxicity from compounding.
Starting from level zero, threat can be increased up to level five.
// Increase threat level by one
moderator.increaseThreat();
// Increase threat level by another three, so threat level is four
moderator.increaseThreat(3);
// Decrease threat level by one, threat level back down to three
moderator.decreaseThreat();
// Reset threat level to zero when a match ends or after a certain time
moderator.resetThreat();
// Increase threat level by one
moderator.IncreaseThreat();
// Increase threat level by another three, so threat level is four
moderator.IncreaseThreat(3);
// Decrease threat level by one, threat level back down to three
moderator.DecreaseThreat();
// Reset threat level to zero when a match ends or after a certain time
moderator.ResetThreat();
# Increase threat level by one
moderator.increase_threat()
# Increase threat level by another three, so threat level is four
moderator.increase_threat(3)
# Decrease threat level by one, threat level back down to three
moderator.decrease_threat()
# Reset threat level to zero when a match ends or after a certain time
moderator.reset_threat()
-- Increase threat level by one
moderator:increaseThreat()
-- Increase threat level by another three, so threat level is four
moderator:increaseThreat(3)
-- Decrease threat level by one, threat level back down to three
moderator:decreaseThreat()
-- Reset threat level to zero when a match ends or after a certain time
moderator:resetThreat()
New Player Protection (NPP)
Protect new players by increasing the base threat level, which makes the Moderator more sensitive to toxicity. New players are more likely to be socially anxious in game, as they worry about making mistakes and getting critiqued by other players. NPP lets players pick up a new game without the anxiety of receiving hateful messages while still learning the game.
N.B. New player protection should only be enabled when implementing recipient-side filtering (see Introduction).
// Enable new player protection
moderator.newPlayerProtection(true);
// Disable new player protection, e.g. after player completes tutorial
moderator.newPlayerProtection(false);
// Enable new player protection
moderator.NewPlayerProtection(true);
// Disable new player protection, e.g. after player completes tutorial
moderator.NewPlayerProtection(false);
# Enable new player protection
moderator.new_player_protection(True)
# Disable new player protection, e.g. after player completes tutorial
moderator.new_player_protection(False)
-- Enable new player protection
moderator:newPlayerProtection(true)
-- Disable new player protection, e.g. after player completes tutorial
moderator:newPlayerProtection(false)