dialoguekit.nlg.nlg_template

NLG component.

Classes

TemplateNLG

Template-based NLG.

Module Contents

class dialoguekit.nlg.nlg_template.TemplateNLG(response_templates: Dict[dialoguekit.core.intent.Intent, 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(intent: dialoguekit.core.intent.Intent, 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:

  1. Responses to the desired ‘intent’ will be selected.

  2. Based on the list of ‘annotations’, only the possible responses are kept, i.e., filter out responses that are not usable.

  3. If ‘satisfaction’ is provided: Filter to the closest responses that are possible, and select a random one.

  4. If ‘satisfaction’ is not provided: Select a random one without looking at the satisfaction metric.

Parameters:
  • intent – The intent 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(intent: dialoguekit.core.intent.Intent) 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:

intent (Intent) – Intent of the desired responses.

Returns:

_description_

Return type:

List[Annotation]