dialoguekit.nlg.nlg_conditional¶
Conditional NLG.
Classes¶
Template-based NLG with support for conditional. |
Module Contents¶
- class dialoguekit.nlg.nlg_conditional.ConditionalNLG(response_templates: Dict[str, List[dialoguekit.core.annotated_utterance.AnnotatedUtterance]])¶
Bases:
dialoguekit.nlg.nlg_template.TemplateNLG
Template-based NLG with support for conditional.
- generate_utterance_text(dialogue_acts: List[dialoguekit.core.dialogue_act.DialogueAct], annotations: List[dialoguekit.core.annotation.Annotation] | None | None = None, force_annotation: bool | None = False) dialoguekit.core.annotated_utterance.AnnotatedUtterance ¶
Turns a structured utterance into a textual one.
This method does essentially the same as TemplateNLG.generate_utterance_text(), if you want to use the conditional you should rather use the method generate_utterance_text_conditional().
Note
If the template does not contain the desired intent, a fallback will be used. Stating “Sorry, I did not understand you.” The response will have the same ‘intent’.
Generating a response is a multi-step process:
Responses to the desired ‘intent’ will be selected.
Based on the list of ‘annotations’, only the possible responses are kept, i.e., filter out responses that are not usable.
If ‘satisfaction’ is provided: Filter to the closest responses that are possible, and select a random one.
If ‘satisfaction’ is not provided: Select a random one without looking at the satisfaction metric.
- Parameters:
dialogue_acts – The dialogue acts of the wanted Utterance.
annotations – The wanted annotations in the response Utterance.
force_annotation – if ‘True’ and ‘annotations’ are provided, responses without annotations will also be filtered out during step 2.
- Returns:
Generated response utterance using templates.
Note
Note: if the filtering after step 1 and 2 does not find any response that satisfies the criteria ‘ValueError’ will be raised.
- generate_utterance_text_conditional(dialogue_acts: List[dialoguekit.core.dialogue_act.DialogueAct], annotations: List[dialoguekit.core.annotation.Annotation] | None | None = None, conditional: str | None | None = None, conditional_value: numbers.Number | None | None = None, force_annotation: bool | None = False) dialoguekit.core.annotated_utterance.AnnotatedUtterance ¶
Turns a structured utterance into a textual one.
The conditional field has to be part of the AnnotatedUtterance metadata field and also a Number.
Note: If the template does not contain the desired intent, a fallback will be used. Stating “Sorry, I did not understand you.” The response will have the same ‘intent’.
- Generating a response is a multi-step process.
Responses to the desired ‘intent’ will be selected.
- Based on the list of ‘annotations’ only the possible responses,
are kept. e.g. Filter out responses that are not possible to use are removed.
If conditional is provided:
Filter to the closest responses that are possible to the conditional_value, and select a random one.
If conditional is not provided:
Select a random one without looking at the conditional_value.
- Parameters:
dialogue_acts – The dialogue acts of the wanted Utterance.
annotations – The wanted annotations in the response Utterance.
conditional – The desired metadata field to use as a conditional.
conditional_value – The desired conditional value score.
force_annotation – If ‘True’ and ‘annotations’ are provided, responses without annotations will also be filtered out during step 2.
- Returns:
Generated response utterance using templates.
Note
Note: if the filtering after step 1 and 2 does not find any response that satisfies the criteria ‘ValueError’ will be raised.