dialoguekit.nlg.nlg_template¶
NLG component.
Classes¶
Template-based NLG. |
Module Contents¶
- class dialoguekit.nlg.nlg_template.TemplateNLG(response_templates: Dict[str, List[dialoguekit.core.annotated_utterance.AnnotatedUtterance]])¶
Bases:
dialoguekit.nlg.nlg_abstract.AbstractNLG
Template-based NLG.
To use this NLG component, one of the template extraction methods from template_from_training_data.py has to be used.
- Parameters:
response_templates – Response templates for NLG.
- 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.
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.
- dump_template(filepath: str) None ¶
Dump template to JSON.
- get_intent_annotation_specifications(dialogue_acts: List[dialoguekit.core.dialogue_act.DialogueAct]) Dict[str, Dict[str, Any]] ¶
Returns dictionary with the min and max annotated utterances.
The dictionary is structured as such:
{ "min":{ "amount": int "examples": List[AnnotatedUtterance] } "max":{ "amount": int "examples": List[AnnotatedUtterance] } }
This is useful if you want to look into which options the NLG has for a specific Intent and which annotations are needed.
- Parameters:
dialogue_acts – List of dialogue acts of the desired responses.
- Returns:
_description_
- Return type:
List[Annotation]