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
List[Intent]
sorted in descending order of confidence scores.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.
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.
Plugins that produce output must always produce a
List[Intent]
orList[BaseEntity]
. Say, returning a singleIntent
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.
- 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]]¶