dialogy.base.output package

Module contents

The Output class creates immutable instances that describe the output of a single turn of a conversation. The output contains

  1. List[Intent] sorted in descending order of confidence scores.

  2. List[BaseEntity] in an arbitrary order.

We don’t require the List[BaseEntity] apart from logging purposes. We fill relevant entities within slots of the predicted Intent. Currently this is done only for the Intent with the highest confidence score. That’s because currently, we only process a single trigger from the SLU API (at the dialog manager), which is an Intent.

Why do I see Input and Output as inputs to all Plugins?

It is a common pattern for all the plugins to require both as arguments. Since this could be confusing nomenclature, Input and Output bear meaning and even separation for the SLU API, not for Plugins.

Setting Output

Just like Input, Output is also an immutable class.

  1. Don’t change the attribute elements in place. It would work for now but even types like Intent and BaseEntity will soon become immutable as well.

  2. Plugins that produce output must always produce a List[Intent] or List[BaseEntity]. Say, returning a single Intent would break validations on the output class.

Serialization

If there is a need to represent an Input as a dict we can do the following:

In [1]: from dialogy.base import Output
   ...: from dialogy.types import Intent
   ...: 

In [2]: output = Output(intents=[Intent(name="_greeting_", score=1.0)])

In [3]: output.json()
Out[3]: 
{'intents': [{'name': '_greeting_',
   'alternative_index': None,
   'score': 1.0,
   'parsers': [],
   'slots': []}],
 'entities': [],
 'original_intent': {}}
class Output(*, intents=NOTHING, entities=NOTHING, original_intent=NOTHING)[source]

Bases: object

Represents output of the SLU API.

entities: List[dialogy.types.entity.base_entity.BaseEntity]

A list of entities. Produced by DucklingPlugin, ListEntityPlugin or ListSearchPlugin.

classmethod from_dict(d, reference=None)[source]

Create a new Output instance from a dictionary.

Parameters
  • d (Dict[str, Any]) – A dictionary such that keys are a subset of Output attributes.

  • reference (Optional[Output], optional) – An existing Output instance., defaults to None

Returns

A new Output instance.

Return type

Output

intents: List[dialogy.types.intent.Intent]

A list of intents. Produced by XLMRMultiClass or MLPMultiClass.

json()[source]

Serialize Output to a JSON-like dict.

Parameters

self (Output) – [description]

Returns

[description]

Return type

Dict[str, List[Dict[str, Any]]]

original_intent: Dict[str, Union[str, float]]