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)
S: Hi there, how are you doing today?
U: Fantastic!
S: Glad to hear that. What do you want to talk about?
U: Let's talk about movies
S: My favorite movie is "Spider-Man: Homecoming"! What's yours?
U: The Sound of Music
S: Glad to hear that. What else do you want to talk about?
U: How about music?
S: My favorite song is "Raining Tacos"! What's yours?
U: Amazing Grace
S: Glad to hear that. What else do you want to talk about?
U: That's it..
S: Goodbye!

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:

gloabl_transitions = {
    '[{covid, corona, virus}]': {
        '`I hope you are OK.`': 'good'
    },
    '[{birthday}]': {
        '`Happy birthday to you!`': 'good'
    }
}

df.load_global_nlu(gloabl_transitions)
  • #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.

S: Hi there, how are you doing today?
U: Good
S: Glad to hear that. What do you want to talk about?
U: Music
S: My favorite song is "Raining Tacos"! What's yours?
U: I got vaccinated for COVID
S: I hope you are OK. Glad to hear that. What else do you want to talk about?
U: It's my birthday
S: Happy birthday to you! Glad to hear that. What else do you want to talk about?
U: I'm done
S: Goodbye!

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

S: Hi there, how are you doing today?
U: Good
S: Glad to hear that. What do you want to talk about?
U: Let's talk about virus movies
S: My favorite movie is "Spider-Man: Homecoming"! What's yours?
  • #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:

gloabl_transitions = {
    '[{covid, corona, virus}]': {
        'score': 0.5,
        '`I hope you are OK.`': 'good'
    },
    '[{birthday}]': {
        'score': 0.5,
        '`Happy birthday to you!`': 'good'
    }
}

Last updated

©2023 Emory University - All rights reserved