Conversational AI Design and Practice
GitHubAuthor
  • Preface
    • Syllabus
    • Schedule
  • 0. Getting Started
    • 0.1. Environment Setup
    • 0.2. Quiz
  • 1. Exploration
    • 1.1. Overview
    • 1.2. Project Ideas
    • 1.3. Quiz
  • 2. Dialogue Graph
    • 2.1. Emora STDM
    • 2.2. State Transition
    • 2.3. Matching Strategy
    • 2.4. Multi-turn Dialogue
    • 2.5. Quiz
  • 3. Contextual Understanding
    • 3.1. Natex
    • 3.2. Ontology
    • 3.4. Regular Expression
    • 3.5. Macro
    • 3.5. Quiz
  • 4. Interaction Design
    • 4.1. State Referencing
    • 4.2. Advanced Interaction
    • 4.3. Compound States
    • 4.4. Global Transition
    • 4.5. Saving and Loading
    • 4.6. Quiz
  • 5. LM-based Matching
    • 5.1. Language Models
    • 5.2. Quickstart with GPT
    • 5.3. Information Extraction
    • 5.4. Quiz
  • 6. Conversational Analysis
    • 6.1. H2H vs. H2M
    • 6.2. Team Evaluation
    • 6.3. Quiz
  • Project
    • Projects
    • Proposal Guidelines
    • Final Report Guidelines
  • Supplements
    • LINC Course
    • Page 1
Powered by GitBook

©2023 Emory University - All rights reserved

On this page
  • Multiple Matching
  • Partial Matching
  • Nesting
  • Sequential Matching
  • Code Snippet

Was this helpful?

Export as PDF
  1. 2. Dialogue Graph

2.3. Matching Strategy

A taste of matching strategies provided in Emora STDM.

Previous2.2. State TransitionNext2.4. Multi-turn Dialogue

Last updated 2 years ago

Was this helpful?

Multiple Matching

There is more than one way of expressing "good" or "bad". Let us use a to match multiple expressions per condition by surrounding them with curly brackets:

transitions = {
    'state': 'start',
    '`Hello. How are you?`': {
        '{good, fantastic}': {
            '`Glad to hear that you are doing well :)`': 'end'
        },
        '{bad, could be better}': {
            '`I hope your day gets better soon :(`': 'end'
        },
        'error': {
            '`Sorry, I didn\'t understand you.`': 'end'
        }
    }
}
  • #4: matches the input with either 'good' or 'fantastic'.

  • #7: matches the input with either 'bad' or 'could be better'.

The above transitions can handle the following inputs (on top of the cases of good and bad):

S: Hello. How are you?
U: Fantastic!!
S: Glad to hear that you are doing well :)
S: Hello. How are you?
U: Could be better..
S: I hope your day gets better soon :(

A phrase can be used for matching, although it needs to match the entire input such that 'could be better' in #7 does not match an input like "It could be better".

Enter inputs such as "I'm good" or "Pretty bad" and see how the system responds.

It responds with the error statement because the string key (e.g., 'good', 'bad') does not match the entire input (e.g., "I'm good", "Pretty bad").

If you replace 'bad' in #7 with 'pretty bad', it matches the input "Pretty bad". However, it no longer matches the input "bad".

Currently, STDM does not allow you to insert a single quote (') in any condition such that if you replace 'good' in #4 with 'I\'m good', it will throw a runtime error. This bug will be fixed in the next version.

Partial Matching

transitions = {
    'state': 'start',
    '`Hello. How are you?`': {
        '[good]': {
            '`Glad to hear that you are doing well :)`': 'end'
        },
        '[could be better]': {
            '`I hope your day gets better soon :(`': 'end'
        },
        'error': {
            '`Sorry, I didn\'t understand you.`': 'end'
        },
    }
}
  • #4: the keyword 'good' is surrounded by the square brackets (good -> [good]), and matched to any word in the input.

  • #7: the keyphrase 'could be better' is surrounded by the square brackets, and matched to any phrase in the input.

S: Hello. How are you?
U: I'm good!!
S: Glad to hear that you are doing well :)
S: Hello. How are you?
U: It could be better..
S: I hope your day gets better soon :(

What are the differences between a set and a list in general data structures?

The above transitions yield the following dialogues:

Replace the condition in #4 with '[good, fantastic]'. Does it respond as expected?

All terms in a list must match some terms in the input sequentially. Thus, by replacing '[good]' with '[good, fantastic]', it no longer understands the inputs "good" or "fantastic":

S: Hello. How are you?
U: good
S: Sorry, I didn't understand you.
S: Hello. How are you?
U: fantastic
S: Sorry, I didn't understand you.

Instead, it understands the input "good and fantastic" by matching "good" first, then "fantastic" later:

S: Hello. How are you?
U: good and fantastic!
S: Glad to hear that you are doing well :)

Nesting

To allow partial matching of multiple expressions, a set can be put in a list:

transitions = {
    'state': 'start',
    '`Hello. How are you?`': {
        '[{good, fantastic}]': {
            '`Glad to hear that you are doing well :)`': 'end'
        },
        '[{bad, could be better}]': {
            '`I hope your day gets better soon :(`': 'end'
        },
        'error': {
            '`Sorry, I didn\'t understand you.`': 'end'
        },
    }
}
  • #4: the keywords 'good' and 'fantastic' are first put in a set for multiple matching and then in a list for partial matching.

  • #7: the keyword 'bad' and the keyphrase 'could be better' are first put in a set for multiple matching, then in a list for partial matching.

S: Hello. How are you?
U: I'm so good!
S: Glad to hear that you are doing well :)
S: Hello. How are you?
U: It's fantastic!!
S: Glad to hear that you are doing well :)
S: Hello. How are you?
U: Pretty bad..
S: I hope your day gets better soon :(
S: Hello. How are you?
U: It could be better.
S: I hope your day gets better soon :(

What are the meanings of nesting a set inside a list vs. a list inside a set?

What happens if '[{good, fantastic}]' in #4 is replaced with '{[good, fantastic]}'; in other words, put the keywords in a list first, then in a set?

It behaves the same way as the one in Exercise 2.

Sequential Matching

Keywords or keyphrases delimited by commas in a list are matched sequentially:

transitions = {
    'state': 'start',
    '`Hello. How are you?`': {
        '[{good, fantastic}]': {
            '`Glad to hear that you are doing well :)`': 'end'
        },
        '[{bad, could be better}]': {
            '`I hope your day gets better soon :(`': 'end'
        },
        '[how, you]': {
            '`I feel superb. Thank you!`': 'end'
        },
        'error': {
            '`Sorry, I didn\'t understand you.`': 'end'
        },
    }
}
  • #10: first matches 'how', then matches 'you' sequentially so that "how" must be followed by "you" in the input for this condition to be true.

S: Hello. How are you?
U: Fine. How are you doing?
S: I feel superb. Thank you!

All terms in the list must be matched sequentially such that the conditions are false for the following cases:

S: Hello. How are you?
U: Fine. How is it going?
S: Sorry, I didn't understand you.
S: Hello. How are you?
U: Fine, and you?
S: Sorry, I didn't understand you.

Let us replace 'how' with '{how, and}' and 'you' with '{you, going}' in #10:

transitions = {
    'state': 'start',
    '`Hello. How are you?`': {
        '[{good, fantastic}]': {
            '`Glad to hear that you are doing well :)`': 'end'
        },
        '[{bad, could be better}]': {
            '`I hope your day gets better soon :(`': 'end'
        },
        '[{how, and}, {you, going}]': {
            '`I feel superb. Thank you!`': 'end'
        },
        'error': {
            '`Sorry, I didn\'t understand you.`': 'end'
        },
    }
}
  • #10: first matches ('how' or 'and'), then matches ('you' or 'going') sequentially.

S: Hello. How are you?
U: Fine. How is it going?
S: I feel superb. Thank you!
S: Hello. How are you?
U: Fine, and you?
S: I feel superb. Thank you!

What other inputs does the condition in #10 match? Is there any consequence of matching that many expressions?

How does the system respond when the input is "Good, how are you"?

Since both the conditions in #5 and #11 match the input, it randomly chooses one of the responses such that it can nondeterministically generate either of the followings:

S: Hello. How are you?
U: Good, how are you?
S: Glad to hear that you are doing well :)
S: Hello. How are you?
U: Good, how are you?
S: I feel superb. Thank you!

Code Snippet

def matching_strategy() -> DialogueFlow:
    transitions = {
        'state': 'start',
        '`Hello. How are you?`': {
            '[{good, fantastic}]': {
                '`Glad to hear that you are doing well :)`': 'end'
            },
            '[{bad, could be better}]': {
                '`I hope your day gets better soon :(`': 'end'
            },
            '[{how, and}, {you, going}]': {
                '`I feel superb. Thank you!`': 'end'
            },
            'error': {
                '`Sorry, I didn\'t understand you.`': 'end'
            },
        }
    }

    df = DialogueFlow('start', end_state='end')
    df.load_transitions(transitions)
    return df

if __name__ == '__main__':
    matching_strategy().run()

Matching the entire input is often too restrictive. Let us use a to allow partial matching:

See for more details.

set
list
Sequential Matching