0.7.0 • Published 1 year ago

detect-toxicy v0.7.0

Weekly downloads
-
License
ISC
Repository
-
Last release
1 year ago

Detect Toxicy 🔍

Detects toxicity in messages (strings) using Machine Learning systems. This module it's slightly simpler ad aptation of the TensorFlow package of the same goal, and that was used for the development of this; @tensorflow-models/toxicity

Detecta toxicidad en mensajes (strings) utilizando sistemas de Machine Learning. Este modulo es una adaptación un poco mas sencilla del paquete de TensorFlow del mismo objetivo, y el cual fue utilizado para el desarrollo de este; @tensorflow-models/toxicity

Install module / Instalar modulo 💾

npm install detect-toxicy

Guide / Guia 📃

Define and instantiates the model / Defines e instancias el modelo.
import Toxicy from "detect-toxicy";
let toxic = new Toxicy({ limit: 0.7 }); // 0.7 represents 70% of 100. This percentage determines detection. - 0.7 representa un 70% de 100. Este porcentaje determina la detección.

Also supports CommonJS / Tambien admite CommonJS

const Toxicy = require("detect-toxicy");
let toxic = new Toxicy({ limit: 0.7 }); // 0.7 represents 70% of 100. This percentage determines detection. - 0.7 representa un 70% de 100. Este porcentaje determina la detección.
Pass it the string you want to check and the filters you want to apply. / Pasale el string que quiera chequear y los filtros que quiera aplicar.
let detect = await toxic.detect("fuck you", ["insult"]);
Check if it returned true or false / Verifique si devolvio true o false.
if (detect.insult) {
  // If is true - Si es true
  console.log("Toxic message.");
} else {
  // If is false - Si es false
  console.log("No toxic message.");
}
Also mention that you can obtain the probabilities of detection in the following way / Tambien mencionar que puedes obtener las probabilidades de deteccion de la siguiente forma:
let probabilities = toxic.getProbabilities();

Complete example / Ejemplo completo 📋

import Toxicy from "detect-toxicy"; // It can also be - Tambien puede ser: const Toxicy = require("detect-toxicy");
let toxic = new Toxicy({ limit: 0.7 });

(async () => {
  let detect = await toxic.detect("fuck you", ["insult"]); // Returns an object - Retorna un Objeto
  if (detect.insult) {
    console.log("Toxic message."); // Yes is toxic - Si es toxico
  } else {
    console.log("No toxic message."); // No is toxic - No es toxico
  }
})();

Outputs 💻

Detect:

1️⃣ One example / Ejemplo uno:

let detect = await toxic.detect("fuck you", ["insult"]);
// Returns an object with the property "insult" (specified in the second parameter) - Devuelve un objeto con la propiedad "insulto" (especificado en el segundo parámetro).
{
  "insult": true
}

2️⃣ Two example / Ejemplo dos:

let detect = await toxic.detect("fuck you", [
  "insult",
  "obscene",
  "identity_attack",
]);
// Returns an object with the properties "insult", "obscene" and "identity attack" (specified in the second parameter) - Devuelve un objeto con las propiedades "insulto", "obsceno" y "ataque de identidad" (especificados en el segundo parámetro).
{
  "identity_attack": false,
  "insult": true,
  "obscene": true
}

3️⃣ Three example / Ejemplo tres:

let detect = await toxic.detect("fuck you", []);
// By leaving the Array empty, return an object with all existing properties - Al dejar el Array vacío, devuelve un objeto con todas las propiedades existentes.
{
  "identity_attack": false,
  "insult": true,
  "obscene": true,
  "severe_toxicity": false,
  "sexual_explicit": null,
  "threat": false,
  "toxicity": true
}

Properties / Propiedades 🔰

> identity_attack
> insult
> obscene
> severe_toxicity
> sexual_explicit
> threat
> toxicity

Get Probabilities

1️⃣ One example / Ejemplo uno:

let detect = await toxic.detect("fuck you", ["insult"]);
let probabilities = toxic.getProbabilities();
// It will get the probabilities of the properties you passed as the second parameter of the detect. In this case, of "insult" - Obtendra las probabilidades de las propiedades que pasaste como segundo parametro del detect. En este caso, de "insult".
  {
    "insult": Float32Array(2) [ 0.154839426279068, 0.8451605439186096 ]
  }

2️⃣ Two example / Ejemplo dos:

let detect = await toxic.detect("fuck you", []);
let probabilities = toxic.getProbabilities();

// Leaving the second parameter Array empty will return an object with the probabilities of all existing properties - Al dejar el Array del segundo parametro vacio, se retornara un objeto con las probabilidades de todas las propiedades existentes.
{
"identity_attack": Float32Array(2) [ 0.9122103452682495, 0.08778968453407288 ],
"insult": Float32Array(2) [ 0.154839426279068, 0.8451605439186096 ],
"obscene": Float32Array(2) [ 0.17617648839950562, 0.8238235712051392 ],
"severe_toxicity": Float32Array(2) [ 0.9907359480857849, 0.009264074265956879 ],
"sexual_explicit": Float32Array(2) [ 0.6495026350021362, 0.3504973351955414 ],
"threat": Float32Array(2) [ 0.874160647392273, 0.12583938241004944 ],
"toxicity": Float32Array(2) [ 0.0487336739897728, 0.951266348361969 ]
}

3️⃣ Three example / Ejemplo tres:

let probabilities = toxic.getProbabilities();
// Return an empty object since "detect" has not been used - Devolvera un objeto vacio ya que no se ha utilizado "detect".
{}

Note / Nota 📪

The module internally translates the Strings passed that are not in English. For this reason, the precision in languages ​​other than the one already mentioned, may get worse in some cases. However, the package will continue to work as it should.

El modulo de forma interna traduce los Strings pasados que no estan en Ingles. Por esto mismo, la precision en otros idiomas que no sean el ya mencionado, puede empeorar en algunos casos. No obstante, seguira funcionando el paquete como se debe.

Contact / Contacto 📞

If you found an error, detail or thing you want to report; or simply requires communicate with the developer of the module, you must do so by Discord.

Si encontro algun un bug, detalle o cosa que quiera reportar; o simplemente requiere comunicarse con el desarrollador del modulo, debera hacerlo mediante Discord.