4.4. Global Transition

Exercise

  1. Draw a diagram describing the following dialogue flow.

  2. What is the role of MacroWhatElse?

transitions = {
    'state': 'start',
    '`Hi there, how are you doing today?`': {
        '[{good, fantastic}]': {
            'state': 'good',
            '`Glad to hear that.` #WHAT_ELSE': {
                '[#LEM(movie)]': 'movie',
                '[music]': 'music',
                'error': {
                    'state': 'goodbye',
                    '`Goodbye!`': 'end'
                }
            }
        },
        'error': 'goodbye'
    }
}

music_transitions = {
    'state': 'music',
    '`My favorite song is "Raining Tacos"! What\'s yours?`': {
        'error': 'good'
    }
}

movie_transitions = {
    'state': 'movie',
    '`My favorite movie is "Spider-Man: Homecoming"! What\'s yours?`': {
        'error': 'good'
    }
}

macros = {
    'WHAT_ELSE': MacroWhatElse()
}

class MacroWhatElse(Macro):
    def run(self, ngrams: Ngrams, vars: Dict[str, Any], args: List[Any]):
        vn = 'HAVE_TALK'
        if vn in vars and vars[vn]:
            return 'What else do you want to talk about?'
        else:
            vars[vn] = True
            return 'What do you want to talk about?'

df = DialogueFlow('start', end_state='end')
df.load_transitions(transitions)
df.load_transitions(music_transitions)
df.load_transitions(movie_transitions)
df.add_macros(macros)

Global Transitions

It is often the case that the user says something out of the topic that the system expects. One way of handling such occasions is by using global transitions that anticipate common cases:

  • #1-8: creates global transitions.

  • #10: adds the global transitions to the dialogue flow.

Notice that after prompting an output in the global transitions, it will direct to the good state defined in the regular transitions.

The global transitions are fired whenever the user content matches their conditions, which can cause multiple matching conditions as follow:

  • #5: matches the condition in the movie state.

Thus, it is recommended to put lower scores on the conditions in global transitions such that local transitions are prioritized over them:

Last updated

Was this helpful?