Bayes Categorization

23 September 2016

  • Release 9.128 - added.
bayes (Commands)
TypeCorrade progressive command
Commandbayes
DescriptionCorrade bundles a Bayes categorization module, for each configured group, that is capable of being trained and manipulated to match chunks of texts and return their most likely category.
Permissionsdatabase
Parametersgroup, password
Last ChangesRelease 9.128 - added.

Corrade bundles a Bayes categorization module, for each configured group, that is capable of being trained and manipulated to match chunks of texts and return their most likely category.

Command Required Parameters Required Corrade Permissions Example
bayes group, password database
llInstantMessage(CORRADE,
    wasKeyValueEncode(
        [
            // Train Corrade to categorize a quote
            // by Abraham Lincoln under the "abe" tag.
            "command", "bayes",
            "group", wasURLEscape(GROUP),
            "password", wasURLEscape(PASSWORD),
            "action", "train",
            "category", "abe",
            "data", "In the end, it's not the years in your life that count. It's the life in your years.",
            "callback", wasURLEscape(URL)
        ]
    )
);
Parameter Possible Value Required Parameter Description
action train category Train Corrade to recognize the string passed to data as being part of the string passed to category.
data
classify data Return the categories (previously trained) that match the string passed to data as a CSV list of category by probability (1 being certain).
list List all categories.
merge source Merge two categories together.
target
untrain category Remove the string passed to data from the category passed to the category parameter
data
import data Import a JSON encoded string of trained data.
export Export the trained data to a JSON encoded string.
remove category Remove a category.
add category Add a category (but do not train).
rename source Rename the category passed to the source parameter to the string passed to the target parameter.
target

Short Tutorial

The Bayes classifier can be used to identify text. In order to do that, you need to first train your classifier by issuing a bayes command with the action parameter set to train as well as pass an identifier (a name) and the sample text.

For instance, the following call:

llInstantMessage(CORRADE,
    wasKeyValueEncode(
        [
            "command", "bayes",
            "group", wasURLEscape(GROUP),
            "password", wasURLEscape(PASSWORD),
            "action", "train",
            "category", "abe",
            "data", "In the end, it's not the years in your life that count. It's the life in your years.",
            "callback", wasURLEscape(URL)
        ]
    )
);

will make Corrade analyse the string passed to the data key and then file it under the abe category.

The more you train Corrade, the more accurate Corrade's guess will be on which category fits the passed data. Following the example, you can issue a follow-up command:

llInstantMessage(CORRADE,
    wasKeyValueEncode(
        [
            "command", "bayes",
            "group", wasURLEscape(GROUP),
            "password", wasURLEscape(PASSWORD),
            "action", "train",
            "category", "abe",
            "data", "Character is like a tree and reputation like a shadow. The shadow is what we think of it; the tree is the real thing.",
            "callback", wasURLEscape(URL)
        ]
    )
);

which will make Corrade analyse another quote and file it under the abe category. Ideally, you should pass as much data as you can that belongs in a given category such that Corrade will be able to make accurate guesses. Conversely, you should never pass data to Corrade that does not belong in a category - for instance, were you to pass a Benjamin Franklin quote and file it under abe, the data will be contaminated.

Corrade does not require an exclusive learning phase (by contrast to some E-Mail filters) such that even with a few phrases, you can issue a command to have Corrade return an educated guess about which category a chunk of data belongs to. This is performed by passing classify to the action parameter of the bayes command:

llInstantMessage(CORRADE,
    wasKeyValueEncode(
        [
            "command", "bayes",
            "group", wasURLEscape(GROUP),
            "password", wasURLEscape(PASSWORD),
            "action", "classify",
            "data", "In the end, it's not the years in your life that count. It's the life in your years.",
            "callback", wasURLEscape(URL)
        ]
    )
);

Corrade will then return a list of probabilities and their corresponding categories as part of the value of the returned data key.

Practical Applications

  • One idea would have to sample typical group spam from in-world group chat and train Corrade to recognize that data under a spam category. Similarly, to make the guess stronger, you would additionally collect normal group chat and file that under a ham category. After that, you could bind to the group chat notification and pass an eject or ban command to remove members depending on a threshold you desire.

Notes

  • The group chat notification by default returns the most likely matching category in case the group for which the notification is bound has trained Corrade's filter.
  • All groups have their own private filter.

secondlife/scripted_agents/corrade/api/progressive/commands/bayes.txt ยท Last modified: 2017/02/22 18:29 (external edit)

Access website using Tor


For the copyright, license, warranty and privacy terms for the usage of this website please see the license and privacy pages.