dialogy.types.intent package

Module contents

Intent Classification

Automatic categorization of texts into known classes. When solving SLU problems the objective is to answer What was meant? instead of “What was said?”.

For an example utterance “I lost my wallet” a bank’s support executives would understand that they must follow the operating procedure for blocking all transaction accounts. We want to train machines to have the ability to interpret these cues.

We call the classes of meaning as Intent.

We can obtain intents from XLMRMultiClass and MLPMultiClass plugin.

class Intent(*, name, score=0.0, alternative_index=None, parsers=NOTHING, slots=NOTHING)[source]

Bases: object

An instance of this class contains the name of the action associated with a body of text.

add_parser(plugin)[source]

Update parsers with the plugin name

This is to identify the progression in which the plugins were applied to an intent. This only helps in debugging and has no production utility.

Parameters

plugin (Plugin) – The class that modifies this instance. Preferably should be a plugin.

Returns

Calling instance with modifications to parsers attribute.

Return type

Intent

alternative_index: Optional[int]

Tells us the index of transcript that yeilds this intent. Since our featurizer concatenates all transcripts, we currently don’t have a use for it.

If we were to predict the intent for each transcript separately and vote, in those cases it would be helpful to log this property.

apply(rules)[source]

Create slots using rules.

An intent can hold different entities within associated slot-types. We parse rules that describe this mapping and create placeholders within an intent for holding entities found.

An example rule would look like:

rules = {
    "wake_up_alarm": {          # name of the intent.
        "datetime_slot": [      # "datetime_slot" is the only slot associated with this intent.
            "date",             # Only "date", "time", "datetime" entities can fill the "datetime_slot"
            "time",
            "datetime"
        ]
    },
    "ticket_booking": {         # name of the intent.
        "origin": [             # A slot that will fill only location type entities.
            "location"          # The entity types that can be filled in the slot.
        ],
        "destination": [        # Another slot that will fill only location type entities.
            "location"
        ],
        "start_date": [
            "date"
        ],
        "end_date": [
            "date"
        ],
        "passengers": [
            "people",
            "number"
        ],
        "budget": [
            "amount-of-money"
        ]
    }
}
Parameters

rules (Rule) – A configuration for slot names and entity types associated with this instance of Intent.

Returns

The calling Intent is modified to have Slots.

Return type

Intent

cleanup()[source]

Remove slots that were not filled.

Return type

None

fill_slot(entity, fill_multiple=False, expected_slots=None)[source]

Update slots[slot_type].values with a single entity.

We will explore the possibility of sharing/understanding the meaning of multiple entities in the same slot type.

There maybe cases where we want to fill multiple entities of the same type within a slot. In these cases fill_multiple should be set to True.

The RuleBasedSlotFillerPlugin has a detailed demo for this.

Parameters
  • entity (BaseEntity) – The entity to be checked for support in the calling intent’s slots.

  • fill_multiple (bool) –

Returns

The calling Intent with modifications to its slots.

Return type

Intent

json()[source]

Convert the object to a dictionary.

In [1]: from dialogy.types.intent import Intent

In [2]: intent = Intent(name="special", score=0.8)

In [3]: intent.json()
Out[3]: 
{'name': 'special',
 'alternative_index': None,
 'score': 0.8,
 'parsers': [],
 'slots': []}
Return type

Dict[str, Any]

name: str

The description of an intent separated by ‘_’

parsers: List[str]

Contains a list of plugins that have created, updated this Intent.

score: float

A positive real number that represents confidence of this intent being the meaning of an utterance. Higher is better.

Should be a value between 0 and 1.

slots: Dict[str, dialogy.types.slots.Slot]

Placeholders for entities that are relevant to this intent. More details are available in the doc for slots.