arrow-left

Only this pageAll pages
gitbookPowered by GitBook
1 of 45

Conversational AI Design and Practice

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Project

Loading...

Loading...

Loading...

Supplements

Loading...

Loading...

1. Exploration

This chapter overviews dialogue systems, the technologies behind those systems, and their applications.

hashtag
Content

  1. Overview

hashtag
Resource

  • , Speech and Language Processing (3rd ed.), Jurafsky and Martin.

Schedule

Spring 2023

Date
Topic
Assignment
Discussion
Quiz
Chapter 24: Chatbots and Dialogue Systemsarrow-up-right

01/23

(Continue)

01/25

01/30

(Continue)

02/01

02/06

(Continue)

02/08

(Continue)

02/13

02/15

(Continue)

02/20

(Continue)

02/22

02/27

(Continue)

03/01

(Continue)

03/06

Spring Break

03/08

Spring Break

03/13

03/15

(Continue)

LINC 2

03/20

(Continue)

03/22

Review

03/27

(Continue)

03/29

(Continue)

04/03

04/05

(Continue)

04/10

(Continue)

04/12

04/17

(Continue)

04/19

(Continue)

Project

04/24

Live Demonstrations

LINC 3

01/11

0. Getting Started

Quiz 0

01/16

MLK Holiday

01/18

1. Exploration

Quiz 1
2. Dialogue Graph
Quiz 2
3. Contextual Understanding
Quiz 3
4. Interaction Design
Quiz 4
Project Proposals
Proposal
5. LM-based Matching
Quiz 5
6. Conversational Analysis
Quiz 6
Project Presentations

2. Dialogue Graph

This chapter provides how to build a simple dialogue graph using Emora STDM.

hashtag
Content

  1. Emora STDM

hashtag
Resource

  • Source code:

State Transition
Matching Strategy
Multi-turn Dialogue
Quiz
dialogue_graph.pyarrow-up-right

0.1. Environment Setup

Setup a Python programming environment with GitHub and PyCharm.

hashtag
Python

  • Install Python 3.11.xarrow-up-right.

  • Lower versions of Python may not be compatible with this course.

hashtag
GitHub

  1. Login to (create an account if you do not have one).

  2. Create a new repository called conversational-ai and make it private.

  3. From the [Settings]

hashtag
PyCharm

Install on your local machine:

  • The following instructions assume that you have "PyCharm 2022.3.x Professional Edition".

  • You can get the professional version by applying for an .

Configure your GitHub account:

  1. Go to [Preferences] - [Version Control] - [GitHub].

  2. Press [+], select Log in via GitHub, and follow the procedure.

Create a new project:

  1. Press the [Get from VCS] button on the Welcome prompt.

  2. Choose [GitHub] on the left menu, select the conversational-ai repository, and press [Clone] (make sure the directory name is conversational-ai).

Setup an interpreter:

  1. Go to [Preferences] - [Project: conversational-ai] - [Project Interpreter].

  2. Click Add Interpreter and select Add Local Interpreter.

Install packages:

  1. Open a terminal by clicking [Terminal] at the bottom (or go to [View] - [Terminal]).

  2. Upgrade (if necessary) by entering the following command into the terminal:

  3. Install the

menu, add the instructors as collaborators of this repository.
  • Jinho Choi: jdchoi77arrow-up-right

  • Talyn Fan: talynfanarrow-up-right

  • Benjamin Ascoli: bossbenarrow-up-right

  • Sichang Tu:

In the prompted window, choose [Virtualenv Environment] on the left menu, configure as follows, then press [OK]:
  • Environment: New

  • Location: LOCAL_PATH/conversational-ai/venv

  • Base interpreter: Python 3.11

(STDM) with the following command:
  • If the terminal prompts "Successfully installed ...", the packages are installed on your machine.

  • GitHubarrow-up-right
    PyCharmarrow-up-right
    academic licensearrow-up-right
    piparrow-up-right
    Emora State Transition Dialogue Managerarrow-up-right

    2.2. State Transition

    Create a dialogue flow using state transitions.

    hashtag
    Dialogue Flow

    Let us create a dictionary called transitions and name its initial state as start:

    • #1: transitions is a .

    Add transitions to conduct a single-turn dialogue:

    • #3: the system begins the dialogue by saying, "Hello. How are you?".

    • #4: the system matches the user input with 'good'.

    circle-info

    All keys and values must be in the type, where literals need to be surrounded by reversed primes (e.g., '`Hello. How are you?`').

    There are two ways to create a string in Python, using single quotes (e.g., 'Hello') and double quotes (e.g., "Hello"). When you use single quotes, any single quote inside the string needs to be escaped by a backslash (e.g., 'I\'m "good"!'). Similarly, when you use double quotes, any double quote needs to be escaped (e.g., "I'm \"good\"!").

    Create the dialogue flow df that expects the initial state start and the final state end, which must match the names of the initial and final states in transitions:

    • #1: the import statement should be on top of the source code (see ).

    • #2:

    Load the transitions to the dialogue flow df:

    Finally, run the dialogue flow:

    • #1:

    1. Enter inputs such as "good", "Good", or "Good!" (separately) and see how the system responds. Does the system respond differently?

    2. How does the system respond to inputs like "fantastic" or "bad"?

    hashtag
    Branching

    Let us add a transition such that it can also handle the input 'bad':

    • #7-9: a new transition for the 'bad' condition.

    When you load the new transitions and run the dialogue flow, it now gives proper responses to both 'good' and 'bad':

    hashtag
    Error Handling

    Even with branching, it still throws errors for other inputs. Let us add an error transition to set the default statement for all the other inputs:

    • #10-12: an error transition to generate the default response.

    circle-check

    Make sure to put a default error statement for every branching; otherwise, it will throw an exception during runtime, which can be detrimental.

    hashtag
    Code Snippet

    • #3: although Python is a dynamically-typed language, it allows you to indicate the type of a variable or a function using (since Python 3.5).

    2.5. Quiz

    Quiz 2: Dialogue Graph

    hashtag
    Overview

    You run a hair salon and recently adopted a dialogue system to take a call from a customer and book a service for the customer:

    Your salon provides three services: haircut, hair coloring, and perms. Your system should reject any other service request from the customer:

    Your system should understand the following dates:

    python -m pip install --upgrade pip
    pip install emora_stdm
    transitions = {'state': 'start'}
    SichangTuarrow-up-right
    #5: the system responds to the user with "Glad to hear that ..." and recognizes that it is the final state end.

    User inputs get automatically lowercased and tokenizedarrow-up-right before matching. Thus, the system gives the same response to those inputs.

  • If the input does not match 'good' exactly, the system throws an error because no exception is currently handled in our code.

  • S: Hello. How are you?
    U: Good!
    S: Glad to hear that you are doing well :)
    dictionaryarrow-up-right
    stringarrow-up-right
    dialogue_graph.pyarrow-up-right
    keyword vs. positional argumentsarrow-up-right
    top-level code environmentarrow-up-right
    typingarrow-up-right
    Monday
    ~
    Saturday
    . The time is always followed by the date with the following format:
    <number><space><AM|PM>
    :

    Only the following times and dates are available for the specific services:

    • Haircut:

      • Monday 10 AM, 1 PM, 2 PM

      • Tuesday: 2 PM

    • Hair coloring:

      • Wednesday: 10 AM, 11 AM, 1 PM

      • Thursday: 10 AM, 11 AM

    • Perms

      • Friday: 10 AM, 11 AM, 1 PM, 2 PM

      • Saturday: 10 AM, 2 PM

    Thus, your system should not schedule an appointment for any other slots:

    circle-check

    Make sure your system does not throw an exception in any situation.

    hashtag
    Task 1

    1. Create a python file quiz2.pyarrow-up-right under the quizarrow-up-right package and copy the code.

    2. Update the transitions to design a dialogue flow for the above dialogue system.

    hashtag
    Task 2

    • Create a PDF file quiz2.pdf that describes the limitations of your system.

    hashtag
    Submission

    1. Commit and push quiz2.py to your GitHub repository.

    2. Submit quiz2.pdf to Canvas.

    transitions = {
        'state': 'start',
        '`Hello. How are you?`': {
            'good': {
                '`Glad to hear that you are doing well :)`': 'end'
            }
        }
    }
    from emora_stdm import DialogueFlow
    df = DialogueFlow('start', end_state='end')
    df.load_transitions(transitions)
    if __name__ == '__main__':
        df.run()
    transitions = {
        'state': 'start',
        '`Hello. How are you?`': {
            'good': {
                '`Glad to hear that you are doing well :)`': 'end'
            },
            'bad': {
                '`I hope your day gets better soon :(`': 'end'
            }
        }
    }
    S: Hello. How are you?
    U: Good
    S: Glad to hear that you are doing well :)
    S: Hello. How are you?
    U: Bad
    S: I hope your day gets better soon :(
    transitions = {
        'state': 'start',
        '`Hello. How are you?`': {
            'good': {
                '`Glad to hear that you are doing well :)`': 'end'
            },
            'bad': {
                '`I hope your day gets better soon :(`': 'end'
            },
            'error': {
                '`Sorry, I didn\'t understand you.`': 'end'
            }
        }
    }
    S: Hello. How are you?
    U: It could be better.
    S: Sorry, I didn't understand you.
    from emora_stdm import DialogueFlow
    
    def state_transition() -> DialogueFlow:
        transitions = {
            'state': 'start',
            '`Hello. How are you?`': {
                'good': {
                    '`Glad to hear that you are doing well :)`': 'end'
                },
                'bad': {
                    '`I hope your day gets better soon :(`': 'end'
                },
                'error': {
                    '`Sorry, I didn\'t understand you.`': 'end'
                }
            }
        }
    
        df = DialogueFlow('start', end_state='end')
        df.load_transitions(transitions)
        return df
    
    if __name__ == '__main__':
        state_transition().run()
    S: Hello, how can I help you?
    U: Hi, I'd like to book a haircut.
    S: Sure. What date and time are you looking for?
    U: Tuesday at 2 PM.
    S: Your appointment is set. See you!
    S: Hello, how can I help you?
    U: Can I make an appointment for waxing?
    S: Sorry, we do not provide that service.
    U: OK then.
    S: Goodbye.
    S: Hello, how can I help you?
    U: Can I make an appointment for a perm?
    S: Sure. What date and time are you looking for?
    U: Saturday 10 AM.
    S: Your appointment is set. See you!
    S: Hello, how can I help you?
    U: Hi, I'd like to book a haircut.
    S: Sure. What date and time are you looking for?
    U: Saturday 10 AM.
    S: Sorry, that slot is not available for a haircut.
    U: OK.
    S: Goodbye.

    2.4. Multi-turn Dialogue

    Create a multi-turn dialogue flow.

    All examples in the previous session are single-turn dialogues, where users get to interact with the system only once. Let us design a multi-turn dialogue:

    • #5: after the system says "Glad to ...", it matches the input with those conditions.

    • #6: if the condition in #5 is true, the system responds with "I feel superb ...".

    The condition in #6 does not come with the default action indicated by an error transition. Let us create an error transition for it:

    • #10: prompts the error statement for any other inputs.

    3. Contextual Understanding

    This chapter explains how to improve contextual understanding using Natex.

    hashtag
    Content

    1. Natex

    hashtag
    Resource

    • Source code:

    4. Interaction Design

    hashtag
    Content

    transitions = {
        'state': 'start',
        '`Hello. How are you?`': {
            '[{good, fantastic}]': {
                '`Glad to hear that you are doing well :)`': {
                    '[{how, and}, {you, going}]': {
                        '`I feel superb. Thank you!`': 'end'
                    }
                }
            },
            'error': {
                '`Got it; thanks for sharing.`': 'end'
            },
        }
    }
    Ontology
    Regular Expression
    Macro
    Quiz
    contextual_understanding.pyarrow-up-right
    S: Hello. How are you?
    U: Good!
    S: Glad to hear that you are doing well :)
    U: How are you doing?
    S: I feel superb. Thank you!
    S: Hello. How are you?
    U: Fantastic
    S: Glad to hear that you are doing well :)
    U: Thank you!
    Traceback (most recent call last):
    ...
    def multiturn_dialogue() -> DialogueFlow:
        transitions = {
            'state': 'start',
            '`Hello. How are you?`': {
                '[{good, fantastic}]': {
                    '`Glad to hear that you are doing well :)`': {
                        '[{how, and}, {you, going}]': {
                            '`I feel superb. Thank you!`': 'end'
                        },
                        'error': {
                            '`You are the best!`': 'end'
                        }
                    }
                },
                'error': {
                    '`Got it; thanks for sharing.`': 'end'
                },
            }
        }
    
        df = DialogueFlow('start', end_state='end')
        df.load_transitions(transitions)
        return df
    
    
    if __name__ == '__main__':
        multiturn_dialogue().run()
    S: Hello. How are you?
    U: Fantastic!
    S: Glad to hear that you are doing well :)
    U: Thank you!
    S: You are the best!
  • hashtag
    Resource

    • Source code:

    State Referencing
    Advanced Interaction
    Compound States
    Global Transition
    Saving and Loading
    Quiz
    interaction_design.pyarrow-up-right

    5. LM-based Matching

    hashtag
    Content

    1. Language Models

    hashtag
    Resource

    • Source codes: , ,

    • Slides:

    Quickstart with GPT
    Information Extraction
    Quiz
    appointment.pyarrow-up-right
    regexutils.pyarrow-up-right
    utils.pyarrow-up-right
    linkarrow-up-right

    4.2. Advanced Interaction

    hashtag
    Built-in Macros

    Besides #ONT for checking an ontology, STDM provides several macros useful for dialogue design.

    hashtag
    #LEM

    The following example shows a use case of the macro #LEM that uses the to match lemmas of "raining tacos":

    • #5: maches the input with the lemma of "rain" or "rainy", then the lemma of "taco".

    hashtag
    #UNX

    The #UNX macro can be used as an alternative to the 'error' transition, which prepends a short acknowledgment phrase (e.g., "yeah", "sure") to the error statement:

    • #8: prepends an acknowledgment phrase to the error statement, "Thanks for sharing" in #8.

    • #3,5: add acknowledgment phrases given the user inputs.

    • #7: does not add an acknowledgment phrase when the user input is short.

    When the user input contains fewer than three tokens, #UNK does not add any acknowledgment.

    triangle-exclamation

    Seldomly, #UNKgets selected even when conditions in other transitions match the input (due to an STDM bug). If you notice this during testing, assign a very slow to the #UNK state to ensure it gets the lowest priority among other branches.

    hashtag
    #SET & #IF

    Let us update the above transitions so that it sometimes refuses to sing the same song:

    • #6: can be picked if the variable $RAINING_TACOS equals to the string 'True'.

    • #7: sets $RAINING_TACOS to 'True' after prompting the system output.

    circle-info

    Once $RAINING_TACOS is set to 'True', STDM randomly picks a statement in #6 or #7 as the system output.

    Notice that the #SET macro only assigns a string value to the variable. It is possible to write a macro to set any variable to an actual boolean value (e.g., True, False):

    • #3-4: checks if there are two arguments.

    • #6-8: retrieves the variable name.

    • #10-12

    Given MacroSetBool, the above transitions can be updated as follow:

    • #6: is selected if $RAINING_TACOS is True.

    • #0: sets the variable $RAINING_TACOS to the boolean value True.

    Currently, STDM randomly chooses the statements in #6 and #7 once $RAINING_TACOS becomes True. We can write another macro that prompts #7 only for the first time:

    • #3: the method in returns the value corresponding to the key, RAINING_TACOS if exists; otherwise, False.

    Given MacroPlayRainingTacos, the transitions can be updated as follow:

    • #7: is selected if the macro #PLAY_RAINING_TACOS returns True.

    • #17: adds #PLAY_RAINING_TACOS to the macro dictionary.

    hashtag
    Music

    It is possible to make our system actually sings instead of prompting the lyric. Let us first install the package:

    Then, import the package and update the MacroPlayRainingTacos macro to play the MP3 file, :

    • #1: imports the VLC package.

    • #6: creates a VLC media player and plays the specified MP3 file.

    When you run the above dialogue flow, it now plays the MP3 file and prompts the lyric.

    hashtag
    Time

    The transitions in prompt the same time (3PM) upon every request. Let us create a new macro that checks the current (system) time:

    • #1: imports the package.

    • #5: retrieves the current time in the specified format using the method.

    • #6

    The macro MacroTime can be called to generate the system output:

    • #11: calls the TIME macro to generate the system output displaying the current time.

    • #22: adds #TIME to the macro dictionary.

    hashtag
    Weather

    The transitions in prompt the same weather (sunny) upon every request. Let us retrieve the latitude and the longitude of the system using :

    Then, use a web API provided by the to retrieve the grid correlates to the coordinate:

    • Look for the forecast field under properties:

    Write a macro that retrieves the current weather for the grid using another web API:

    • #1: imports the package.

    • #2: imports the package.

    • #6

    Finally, update the transitions with the weather macro:

    • #15: calls the WEATHER macro to generate the system output displaying today's weather.

    • #22: adds #WEATHER to the macro dictionary.

    circle-info

    The time and the weather retrieved by the above macros are oriented to the system, not the user. It is possible to anticipate the users' location if one's IP address is provided; however, this is not possible unless the user uses a specific device (e.g., Amazon Echo, smartphone) and agrees to send one's private information to our system.

    : checks if the argument is a proper boolean value.
  • #14: stores the boolean value to the variable.

  • : returns the current time using the
    method.
    : specifies the forecast URL.
  • #7: retrieves the content from the URL in JSON.

  • #8: saves the JSON content to a dictionary.

  • #9: retrieves forecasts for all supported periods.

  • #10: retrieves the forecast for today.

  • #11: returns today's forecast.

  • S: What can I do for you?
    U: Play raining tacos
    S: It's raining tacos. From out of the sky ... What can I do for you?
    U: Play raining taco
    S: It's raining tacos. From out of the sky ... What can I do for you?
    U: Play rain taco
    S: It's raining tacos. From out of the sky ... What can I do for you?
    U: Play rainy taco
    S: It's raining tacos. From out of the sky ... What can I do for you?
    U: Bye
    S: Sorry, I didn't understand you.
    NLTK Lemmatizerarrow-up-right
    score
    get()arrow-up-right
    dictarrow-up-right
    VLCarrow-up-right
    resources/raining_tacos.mp3arrow-up-right
    Section 4.1
    timearrow-up-right
    strftimearrow-up-right
    Section 4.1
    Google Mapsarrow-up-right
    National Weather Servicearrow-up-right
    https://api.weather.gov/points/33.7904,-84.3266arrow-up-right
    https://api.weather.gov/gridpoints/FFC/52,88/forecastarrow-up-right
    jsonarrow-up-right
    requestsarrow-up-right
    Mathematics and Science Center at Emory University (400 Dowman Dr, Atlanta, GA, 30322)
    transitions = {
        'state': 'start',
        '`What can I do for you?`': {
            '[play, [!{#LEM(rain), rainy}, #LEM(taco)]]': {
                'state': 'play_raining_tacos',
                '`It\'s raining tacos. From out of the sky ...`': 'start'
            },
            'error': {
                '`Sorry, I didn\'t understand you.`': 'end'
            },
        }
    }
    transitions = {
        'state': 'start',
        '`What can I do for you?`': {
            '[play, [!{#LEM(rain), rainy}, #LEM(taco)]]': {
                'state': 'play_raining_tacos',
                '`It\'s raining tacos. From out of the sky ...`': 'start'
            },
            '#UNX': {
                '`Thanks for sharing.`': 'end'
            },
        }
    }
    S: What can I do for you?
    U: My name is Jinho
    S: Right. Thanks for sharing. What can I do for you?
    U: I am a professor
    S: Yeah. Thanks for sharing. What can I do for you?
    U: Hello world
    S:  Thanks for sharing. What can I do for you?
    U: Play raining tacos
    S: It's raining tacos. From out of the sky ...
    transitions = {
        'state': 'start',
        '`What can I do for you?`': {
            '[play, [!{#LEM(rain), rainy}, #LEM(taco)]]': {
                'state': 'play_raining_tacos',
                '#IF($RAINING_TACOS=True) `Don\'t make me sing this again!`': 'start',
                '`It\'s raining tacos. From out of the sky ...` #SET($RAINING_TACOS=True)': 'start',
            },
            '#UNX': {
                '`Thanks for sharing.`': 'start'
            },
        }
    }
    S: What can I do for you?
    U: Play raining tacos
    S: It's raining tacos. From out of the sky ...   What can I do for you?
    U: Play raining tacos
    S:  Don't make me sing this again! What can I do for you?
    ...
    class MacroSetBool(Macro):
        def run(self, ngrams: Ngrams, vars: Dict[str, Any], args: List[str]):
            if len(args) != 2:
                return False
    
            variable = args[0]
            if variable[0] == '$':
                variable = variable[1:]
    
            boolean = args[1].lower()
            if boolean not in {'true', 'false'}:
                return False
    
            vars[variable] = bool(boolean)
            return True
    transitions = {
        'state': 'start',
        '`What can I do for you?`': {
            '[play, [!{#LEM(rain), rainy}, #LEM(taco)]]': {
                'state': 'play_raining_tacos',
                '#IF($RAINING_TACOS) `Don\'t make me sing this again!`': 'start',
                '`It\'s raining tacos. From out of the sky ...` #SETBOOL(RAINING_TACOS, True)': 'start',
            },
            '#UNX': {
                '`Thanks for sharing.`': 'start'
            },
        }
    }
    
    macros = {
        'SETBOOL': MacroSetBool()
    }
    class MacroPlayRainingTacos(Macro):
        def run(self, ngrams: Ngrams, vars: Dict[str, Any], args: List[str]):
            return not vars.get('RAINING_TACOS', False)
    transitions = {
        'state': 'start',
        '`What can I do for you?`': {
            '[play, [!{#LEM(rain), rainy}, #LEM(taco)]]': {
                'state': 'play_raining_tacos',
                '#IF($RAINING_TACOS) `Don\'t make me sing this again!`': 'start',
                '#IF(#PLAY_RAINING_TACOS) `It\'s raining tacos. From out of the sky ...` #SETBOOL(RAINING_TACOS, True)': 'start',
            },
            '#UNX': {
                '`Thanks for sharing.`': 'start'
            },
        }
    }
    
    macros = {
        'SETBOOL': MacroSetBool(),
        'PLAY_RAINING_TACOS': MacroPlayRainingTacos()
    }
    
    df = DialogueFlow('start', end_state='end')
    df.load_transitions(transitions)
    df.add_macros(macros)
    df.run()
    S: What can I do for you?
    U: Play raining tacos
    S:  It's raining tacos. From out of the sky ...    What can I do for you?
    U: Play raining tacos
    S:  Don't make me sing this again! What can I do for you?
    U: Play raining tacos
    S:  Don't make me sing this again! What can I do for you?
    ...
    pip install python-vlc
    import vlc
    
    class MacroPlayRainingTacos(Macro):
        def run(self, ngrams: Ngrams, vars: Dict[str, Any], args: List[str]):
            if not vars.get('RAINING_TACOS', False):
                vlc.MediaPlayer("resources/raining_tacos.mp3").play()
                return True
            return False
    import time
    
    class MacroTime(Macro):
        def run(self, ngrams: Ngrams, vars: Dict[str, Any], args: List[str]):
            current_time = time.strftime("%H:%M")
            return "It's currently {}.".format(current_time)
    transitions = {
        'state': 'start',
        '`What can I do for you?`': {
            '[play, [!{#LEM(rain), rainy}, #LEM(taco)]]': {
                'state': 'play_raining_tacos',
                '#IF($RAINING_TACOS) `Don\'t make me sing this again!`': 'start',
                '#IF(#PLAY_RAINING_TACOS) `It\'s raining tacos. From out of the sky ...` #SETBOOL(RAINING_TACOS, True)': 'start',
            },
            '[{time, clock}]': {
                'state': 'time',
                '#TIME': 'end'
            },
            '#UNX': {
                '`Thanks for sharing.`': 'start'
            },
        }
    }
    
    macros = {
        'SETBOOL': MacroSetBool(),
        'PLAY_RAINING_TACOS': MacroPlayRainingTacos(),
        'TIME': MacroTime()
    }
    S: What can I do for you?
    U: What time is it now?
    S: It's currently 05:27.
    {
        ...,
        "properties": {
            "@id": "https://api.weather.gov/points/33.7904,-84.3266",
            ...,
            "forecast": "https://api.weather.gov/gridpoints/FFC/52,88/forecast",
            ...
        }
    }
    import json
    import requests
    
    class MacroWeather(Macro):
        def run(self, ngrams: Ngrams, vars: Dict[str, Any], args: List[Any]):
            url = 'https://api.weather.gov/gridpoints/FFC/52,88/forecast'
            r = requests.get(url)
            d = json.loads(r.text)
            periods = d['properties']['periods']
            today = periods[0]
            return today['detailedForecast']
    transitions = {
        'state': 'start',
        '`What can I do for you?`': {
            '[play, [!{#LEM(rain), rainy}, #LEM(taco)]]': {
                'state': 'play_raining_tacos',
                '#IF($RAINING_TACOS) `Don\'t make me sing this again!`': 'start',
                '#IF(#PLAY_RAINING_TACOS) `It\'s raining tacos. From out of the sky ...` #SETBOOL(RAINING_TACOS, True)': 'start',
            },
            '[{time, clock}]': {
                'state': 'time',
                '#TIME': 'end'
            },
            '[{weather, forecast}]': {
                'state': 'weather',
                '#WEATHER': 'end'
            },
            '#UNX': {
                '`Thanks for sharing.`': 'start'
            },
        }
    }
    
    macros = {
        'SETBOOL': MacroSetBool(),
        'PLAY_RAINING_TACOS': MacroPlayRainingTacos(),
        'TIME': MacroTime(),
        'WEATHER': MacroWeather()
    }
    S: What can I do for you?
    U: How is the weather today?
    S: A chance of rain showers. Cloudy, with a high near 68. South wind 0 to 5 mph. Chance of precipitation is 30%.
    str.formatarrow-up-right

    6. Conversational Analysis

    hashtag
    Content

    1. H2H vs. H2M

    Projects

    Spring 2023

    hashtag
    Project List

    1. English Premier League Chatbot: Guide to the World’s Most Exciting Football League (Team 1) : Cholyeon Cho, Hasong Cho, Changhyun Kim, Melinda Zhang : proposalarrow-up-right (slidesarrow-up-right, commentsarrow-up-right: 7), finalarrow-up-right (slidesarrow-up-right, commentsarrow-up-right: 8)

    2. SpeakEasy (Team 2) : Max Bagga, Yella Diekmann, Harry Jeon, Victoria Ploerer, Rhea Ramachandran : (, : 18), (, , : 33)

    3. KINDRED: Be the kindness you want to see (Team 3) : Microl Chen, Steve Li, Eugene Lim, Abbey Yuan : (, : 11), (, , : 16)

    4. Becca: Your Personal Stylist (Team 4) : Rebecca Gerber, Cole Katz, Amya Moore, Yousef Rajeh, Andy Sun : (, : 10), (, : 5)

    5. LEANNA: A Startup Business Model Chatbot (Team 5) : Yifei Gao, Yijun Liu, James Song, Jessie Wang, Eric Xue : (, : 17), (, , : 11)

    6. LorelAI: A Music Recommendation Chatbot (Team 6) : Hazel Cho, Claire Fenton, Safia Read, Christopher Roebuck, Dani Royburg : (, : 24), (, : 16)

    7. Interview Chatbot (Team 7) : Bilal Haider Zaidi, Ameer Husary, Rauf Iftikhar, Noah Okada : (, : 7), (, : 23)

    8. SDevJobs: Software Development Jobs (Team 8) : Billy Ge, Jason Liu, Latifa Tan, Feiyu Xiang : (, : 17), (, : 4)

    9. Revolutionizing Fashion with a Stylist Chatbot (Team 9) : Flora Chen, Nicole Cui, Siying Ren, Mark Si, Sammuel Yang : (, : 12), (, : 14)

    10. Kennedi: College Applications Mentor (Team 10) : Tierra Ablorh, Andrea Brink, Ethan Krein, Katya Kurchin : (, : 17), (, : 15)

    11. Fido: The Feelings Bot (Team 11) : Ezra Greidinger, Darin Kishore, Raphael Palacio, Eric Pina : (, : 11), (, : 13)

    12. GymBrOT (Team 12) : Sarah Bekele, Devin Gee, Kristen Gram, Harry He : (, : 9), (, , : 14)

    13. Dool-E (Team 13) : Ajay Karthik, Victoria Knieling, Hyungsuk Lee, Andrew Levy : (, : 4), (, : 8)

    14. LoLa: A League of Legends ChatBot (Team 14) : Jacob Choi, Sean Hong, Rishie Srivastava, Claude Zheng : (, : 10), (, : 3)

    hashtag
    Proposal Schedule

    • [02/22] 1, 3, 6, 9

    • [02/27] 4, 8, 10, 12, 14

    • [03/01] 2, 5, 7, 11, 13

    hashtag
    Proposal Ranking

    • 20+: 3 points (1 extra credit)

    • ≥ 17: 2 points

    • ≥ 9: 1 point

    hashtag
    Final Schedule

    • [04/12] 2, 5, 7, 11, 13

    • [04/17] 4, 8, 10, 12, 14

    • [04/19] 1, 3, 6, 9

    Proposal Guidelines

    Guidelines to prepare a team project proposal.

    hashtag
    Presentation

    • Every team is expected to give a 12 mins presentation.

    Your presentation must include key contents from each section in the report (see below).

    hashtag
    Proposal

    The proposal writing must be created in LaTex using this templatearrow-up-right.

    • LaTex Guidelinesarrow-up-right

    The proposal should be 6 - 8 pages, including figures and tables (excluding references). Your proposal must include the following:

    1. Write an abstract summarizing your proposal.

    2. What is the team vision of your dialogue system? What makes your system interesting and important? Is a dialogue system the best practice to pursue your vision?

    3. Who is your primary target audience? If your target audience is narrow, what is your strategy to engage the general audience in your system?

    4. Describe a high-level dialogue flow of your system. Additionally, provide sample dialogues that you expect your system to conduct.

    5. Describe your scientific approach in detail. What techniques and/or datasets will you use, and how do you plan to integrate them into your system?

    6. How will you evaluate your system? Be specific about what aspects you plan to assess and how you will conduct such evaluation in terms of metrics and demographics.

    7. What is novel about your system? Survey similar existing systems and compare them to show the uniqueness of your system.

    8. Provide a weekly timeline specifying which members will work on which parts.

    hashtag
    Submissions

    • Submit your presentation slides and the report in PDF to Canvas.

    < 9: 0 point
    proposalarrow-up-right
    slidesarrow-up-right
    commentsarrow-up-right
    finalarrow-up-right
    slidesarrow-up-right
    demoarrow-up-right
    commentsarrow-up-right
    proposalarrow-up-right
    slidesarrow-up-right
    commentsarrow-up-right
    finalarrow-up-right
    slidesarrow-up-right
    demoarrow-up-right
    commentsarrow-up-right
    proposalarrow-up-right
    slidesarrow-up-right
    commentsarrow-up-right
    finalarrow-up-right
    slidesarrow-up-right
    commentsarrow-up-right
    proposalarrow-up-right
    slidesarrow-up-right
    commentsarrow-up-right
    finalarrow-up-right
    slidesarrow-up-right
    demoarrow-up-right
    commentsarrow-up-right
    proposalarrow-up-right
    slidesarrow-up-right
    commentsarrow-up-right
    finalarrow-up-right
    slidesarrow-up-right
    commentsarrow-up-right
    proposalarrow-up-right
    slidesarrow-up-right
    commentsarrow-up-right
    finalarrow-up-right
    slidesarrow-up-right
    commentsarrow-up-right
    proposalarrow-up-right
    slidesarrow-up-right
    commentsarrow-up-right
    finalarrow-up-right
    slidesarrow-up-right
    commentsarrow-up-right
    proposalarrow-up-right
    slidesarrow-up-right
    commentsarrow-up-right
    finalarrow-up-right
    slidesarrow-up-right
    commentsarrow-up-right
    proposalarrow-up-right
    slidesarrow-up-right
    commentsarrow-up-right
    finalarrow-up-right
    slidesarrow-up-right
    commentsarrow-up-right
    proposalarrow-up-right
    slidesarrow-up-right
    commentsarrow-up-right
    finalarrow-up-right
    slidesarrow-up-right
    commentsarrow-up-right
    proposalarrow-up-right
    slidesarrow-up-right
    commentsarrow-up-right
    finalarrow-up-right
    slidesarrow-up-right
    demoarrow-up-right
    commentsarrow-up-right
    proposalarrow-up-right
    slidesarrow-up-right
    commentsarrow-up-right
    finalarrow-up-right
    slidesarrow-up-right
    commentsarrow-up-right
    proposalarrow-up-right
    slidesarrow-up-right
    commentsarrow-up-right
    finalarrow-up-right
    slidesarrow-up-right
    commentsarrow-up-right

    Preface

    Jinho D. Choi

    Artificial Intelligence (AI) has advanced to the point that it starts interacting with humans in natural language. This communication ability makes AI an integral part of human society as a collaborator and companion. Thus, it is essential to understand how AI can (and should) be designed to conduct meaningful conversations with humans. The main objectives of this course are:

    • To discover technical approaches to dialogue systems.

    • To conceive manifold use cases of dialogue systems.

    • To study effective ways of Human-Computer Interaction.

    • To develop a dialogue system using methods in Computational Linguistics.

    • To comprehend the limitations of your dialogue system through Statistical Analysis.

    Students will have individual assignments and work in groups to build end-to-end dialogue systems of their choice. Toward the end of the semester, all teams will present the dialogue systems with live demonstrations.

    hashtag
    LINC Course

    For Spring 2023, this is selected as a course. Thus, it will include collaborative work with students taking .

    0.2. Quiz

    Quiz 0: Getting Started

    hashtag
    Task

    1. Create a package called under the conversational-ai directory.

    circle-info

    1.2. Project Ideas

    Discuss project ideas in groups.

    hashtag
    Before Discussion

    Prepare your ideas about the questions in .

    hashtag

    1.1. Overview

    Explain components, properties, scopes, techniques, and assessments of dialogue systems.

    hashtag
    Components

    hashtag
    Genre

    1.3. Quiz

    Quiz 1: Exploration

    hashtag
    Task 1

    Create a PDF file quiz1.pdf that includes your ideas about the following questions:

    2.1. Emora STDM

    Introduce Emora State Transition Dialogue Manager.

    Emora State Transition Dialogue Manager (STDM) is a dialogue system development framework that seamlessly integrates intent classification, pattern recognition, state machine, and information state approaches to dialogue management and natural language understanding. It supports rapid prototyping and long-term team-based development workflows, catering to a wide range of developer expertise.

    circle-check

    Make sure you have the emora_stdm package installed from the .

    3.2. Ontology

    How to use ontologies for matching in Natex.

    hashtag
    Ontology

    Let us create a dialogue flow to talk about animals:

    3.4. Regular Expression

    How to use regular expressions for matching in Natex.

    Regular expressions provide powerful ways to match strings and beyond:

    • , Chapter 2.1, Speech and Language Processing (3rd ed.), Jurafsky and Martin.

    • , Python Documentation

    4.1. State Referencing

    hashtag
    Start State

    Let us create transitions for a virtual agent that handles time, weather, and playing music:

    • #5: shows the current time (although it is correct only twice a day at the moment).

    4.3. Compound States

    hashtag
    Multiple Topics

    A dialogue flow can be complex when you start adding multiple topics. In this case, you can create a separate transition dictionary for each topic.

    Let us create transitions talking about music and movies:

    5.1. Language Models

    hashtag
    Statistical

    • , Jurafsky and Martin, Chapter 3 in Speech and Language Processing (3rd ed.), 2023.

    5.4. Quiz

    Revisit your and improve its language understanding capability using the large language model such as GPT.

    • Use to figure out the right prompts.

    • Use your trial credits from OpenAI to test the APIs.

    5.3. Information Extraction

    Consider that you want to extract someone's call name(s) during a dialogue in real time:

    Design a prompt that extracts all call names provided by the user.

    In "My friends call me Pete, my students call me Dr. Parker, and my parents call me Peter.", how does the speaker want to be called? Respond in the following JSON format: {"call_names": ["Mike", "Michael"]}

    Let us write a function that takes the user input and returns the GPT output in the JSON format:

    5.2. Quickstart with GPT

    hashtag
    API Key

    Create an account for and log in to your account.

    Click your icon on the top-right corner and select "View API keys":

    Click the "+ Create new secret key" button and copy the API key:

    6.1. H2H vs. H2M

    hashtag
    Overview

    What is a conversational analysis, and why is it important?

    • Conversational Analysis is the study of how people communicate in everyday interactions.

    6.3. Quiz

    hashtag
    Task

    Your task is to evaluate your team chatbot given the following instructions:

    • This is an individual assignment. Each member must evaluate the team chatbot separately.

    Final Report Guidelines

    hashtag
    Presentation

    The presentation should include only the proposed project, not the LINC movie discussion:

    • Every team is expected to give a 12 mins presentation.

    Syllabus

    Spring 2023

    hashtag
    General

    • Book:

    0. Getting Started

    This chapter helps you set up the development environment for this course.

    hashtag
    Content

    2.3. Matching Strategy

    A taste of matching strategies provided in Emora STDM.

    hashtag
    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:

    3.5. Macro

    How to use macro functions for matching in Natex.

    The most powerful aspect of Natex is its ability to integrate pattern matching with arbitrary code. This allows you to integrate regular expressions, NLP models, or custom algorithms into Natex.

    hashtag
    Creation

    A macro can be defined by creating a class inheriting the Macro in STDM and the run method:

    3.1. Natex

    Several matching strategies built in Natex.

    Emora STDM supports several ways for interpreting the contexts of user inputs through Natex (Natural Langauge Expression), some of which you already experienced in .

    hashtag
    Literal

    A literal is what you intend the system to say. A literal is represented by reversed primes (`..`):

    3.5. Quiz

    Quiz 3: Contextual Understanding

    hashtag
    Overview

    Your goal is to create a chatbot that talks about movies. Here is a sample dialogue:

    Your chatbot aims to collect user information by asking the following:

    4.4. Global Transition

    hashtag
    Exercise

    1. Draw a diagram describing the following dialogue flow.

    4.6. Quiz

    hashtag
    Overview

    You aim to create a chatbot that makes a movie or a song recommendation. Your system should conduct dialogue including the following aspects:

    1. Greet with respect to the current time and/or weather.

    4.5. Saving and Loading

    hashtag
    Saving

    Let us create a simple transition that counts how many times the user visits:

    • #4: calls the macro #VISITS

    6.2. Team Evaluation

    hashtag
    Criteria

    hashtag
    Effective

    Page 1

    Give me 10 unique ways of me asking to make an appointment with professors for general purposes. Write as I would speak to the professor's secretary. Use "Prof.", "Dr.", or "Professor" to indicate professors.

    1. Hi there, could you please help me schedule a meeting with Prof. Smith?

    LINC Course

    Spring 2023

    hashtag
    IDS 385W - Translation: Who, What, How

    This seminar examines the realities of translation in multiple settings and contexts. Translation is embedded into our everyday lives, central to newsfeeds, religious texts, politics, Netflix and literature. Often, however, the phenomenon is unremarked, rendered invisible. Yet embedded within it are decisions with cultural, ethical and political ramifications. This course aims to make visible the people, issues and products involved: translators, subtitlers and interpreters; theories, strategies and methodologies; and the written and visual texts they produce. To that end, we will examine the history of translation via the Bible; study current issues in the field; and read work by several translators. Topics to include: translation and gender; bible translation; translation and race; LGBTQ issues in translation; subtitling; translators as social and political actors. Readings span fiction, memoir, theory, methodology, history, and journalism. Classes are discussion and workshop based and include numerous translation activities: comparing multiple versions of the same work, imitation pieces, translating genre and style, editing, and Oulipo activities. The course is taught in English, with no foreign language proficiency required.

    What kind of a dialogue system do you want to develop for your team project?
  • Who will benefit from your dialogue system in what way?

  • What is the novelty of your dialogue system?

  • What are the expected challenges in developing your dialogue system?

  • How do you plan to evaluate your dialogue system?

  • Provide your ideas in detail, about 100 words (or more) per question.

    hashtag
    Task 2

    Group a team of 3-4 members for your project.

    hashtag
    Submission

    1. Submit quiz1.pdf to Canvas.

    2. Go to [People → Team Projects] in Canvas and assign your team members to the same group.

    You need to evaluate at least 5 categories (e.g., team evaluation). Give a clear description of each category. You are welcome to discuss them with your team; however, your description must be original.

  • Create a static form to evaluate your chatbot. Your form should include a metric (e.g., Likert scale of 1 - 3) to evaluate each category and ask for reasons for the assessment.

  • Find a group of 10 people suitable to interact with your chatbot. Each interactor will evaluate your chatbot after one or more conversations using the static form.

  • hashtag
    Submission

    Submit quiz6.pdf summarizing your evaluation results, including:

    • Your evaluation categories and their descriptions.

    • Quantitative analysis of your chatbot using the metric.

    • Qualitative analysis of your chatbot using assessment reasoning.

    • Based on the analyses, potential improvements can (or should) be made.

    Your presentation must include key contents from each section in the report (see below).

    hashtag
    Report

    The proposal writing must be created in LaTex using this templatearrow-up-right.

    • LaTex Guidelinesarrow-up-right

    The report should be 8 - 10 pages, including figures and tables (excluding references). Your proposal must include the following:

    1. Abstract: Summarize the report, including the motivation, approach, and results.

    2. Vision: Explain what this project aims to accomplish and why that is beneficial to society.

    3. Challenges: Describe the main challenges of your project. Describe how your vision, approach, evaluation, etc. may have changed due to the challenges.

    4. Dialogue Flow: Describe the overall dialogue flow of your system. Additionally, provide sample dialogues that your system can conduct.

    5. Methodology: Illustrate specific methods used in your chatbot (other than the ones built-in STDM), including external APIs, datasets, macros, etc.

    6. Evaluation: Describe the demographics and statistics of the users who participated in assessing your chatbot. Explain in detail how you evaluate your chatbot.

    7. Novelty: Point out the main novelty of your chatbot against competitors. Survey on related systems similar to yours.

    8. Contributions: Depict the contribution of each team member throughout the course of the project and estimate the percentages of individual contributions so that they sum up to 100%.

    hashtag
    Submissions

    • Submit your presentation slides and the report in PDF to Canvas.

    Syllabus
    Schedule
    LINC (Learning through Inclusive Collaboration)arrow-up-right
    IDS 385W - Translation: Who, What, How
    hashtag
    Neural-based
    • Efficient Estimation of Word Representations in Vector Spacearrow-up-right, Mikolov et al., ICLR, 2013. <- Word2Vec

    • GloVe: Global Vectors for Word Representationarrow-up-right, Pennington et al., EMNLP, 2014.

    • Deep Contextualized Word Representationsarrow-up-right, Ppeters et al., NAACL, 2018. <- ELMo

    hashtag
    Transformers

    • Attention is All You Needarrow-up-right, Vaswani et al., NIPS, 2017. <- Transformer

    • Generating Wikipedia by Summarizing Long Sequencesarrow-up-right, Liu et al., ICLR, 2018.

    • BERT: Pre-training of Deep Bidirectional Transformers for Language Understandingarrow-up-right, Devlin et al., NAACL, 2018.

    hashtag
    Tokenization

    • Neural Machine Translation of Rare Words with Subword Unitsarrow-up-right, Sennrich et al., ACL, 2016. <- Byte-Pair Encoding (BPE)

    • Google’s Neural Machine Translation System: Bridging the Gap between Human and Machine Translationarrow-up-right, Wu et al., arXiv, 2016. <- WordPiece

    • SentencePiece: A simple and language independent subword tokenizer and detokenizer for Neural Text Processingarrow-up-right, Kudo and Richardson, EMNLP, 2018.

    hashtag
    GPT (Generative Pre-trained Transformer)

    • Improving Language Understanding by Generative Pre-Trainingarrow-up-right, Radford et al., OpenAI, 2018. <- GPT-1

    • Language Models are Unsupervised Multitask Learnersarrow-up-right, Radford et al., OpenAI, 2019. <- GPT-2

    • Language Models are Few-Shot Learnersarrow-up-right, Brown et al., NeurIPS, 2020. <- GPT-3

    N-gram Language Modelsarrow-up-right
    hashtag
    Task 1
    • Create a python file quiz5.pyarrow-up-right under the quizarrow-up-right package and copy the code.

    • Update the code to design a dialogue flow for the assigned dialogue system.

    • Create a PDF file quiz5.pdf that describes the approach (e.g., prompt engineering) and how the large language model improved over the limitations you described in Quiz 2.

    hashtag
    Task 2

    Answer the following questions in quiz5.py:

    1. What are the limitations of the Bag-of-Words representation?

    2. Describe the Chain Rule and Markov Assumption and how they are used to estimate the probability of a word sequence.

    3. Explain how the Word2Vec approach uses feed-forward neural networks to generate word embeddings. What are the advantages of the Word2Vec representation over the Bag-of-Words representation?

    4. Explain what patterns are learned in the multi-head attentions of a Transformer. What are the advantages of the Transformer embeddings over the Word2Vec embeddings?

    Quiz 2
    ChatGPTarrow-up-right
    Quiz
    Environment Setup
    hashtag
    References
    • Emora STDM: A Versatile Framework for Innovative Dialogue System Developmentarrow-up-right, James D. Finch and Jinho D. Choi, Proceedings of the Annual Meeting of the Special Interest Group on Discourse and Dialogue: System Demonstrations (SIGDIAL:DEMO), 2020.

    • Emora STDM GitHub Repositoryarrow-up-right

    Environment Setup
    Figure 1 from Finch and Choi, SIGDIAL 2020arrow-up-right.
    The degree to which the chatbot is able to achieve its intended goals and produce desirable outcomes for users.
    • Whether the advice provided helps the user feel more confident in their conversational abilities.

    • How well it provides mental health support to individuals with varying levels of stress.

    • Whether the user found the previous interaction helpful.

    • Whether the chatbot was able to successfully complete her goal with the help of the chatbot.

    • The user's rating of how much the chatbot helped them in their career path.

    • How users feel about its ability to prepare them for real interviews.

    hashtag
    Satisfactory

    The degree to which the chatbot meets users' expectations and provides a satisfactory experience.

    • Whether the insights, questions, and communication are well-balanced and whether the users feel comfortable with the ideal proportion.

    • How comfortable the user felt during the conversation.

    • Whether it understood the user's needs and provided personalization based on their style and preferences.

    • Whether the user felt a bit better after the interaction.

    • The pleasantness of the system persona and whether it meets users' expectations.

    hashtag
    Correctness

    The degree to which the chatbot provides accurate and correct information or recommendations to users.

    • How accurately it identifies the presence of stress and changes response style accordingly.

    • Whether the bot's suggestions were relevant to the user's personal taste, style, and preferences, and whether the user would wear everything suggested by the bot.

    • The accuracy of its performance metrics, such as the accuracy of style recommendations.

    • Whether it is successful in making accurate recommendations for the user.

    • The quality and specificity of the feedback users received from the system, and whether the feedback provided accurate and correct information.

    hashtag
    Interpretability

    The degree to which the chatbot's responses and actions can be understood and interpreted by users.

    • Whether users can understand what the chatbot is saying.

    • Whether users experience instances of missed messages, misunderstandings, or abrupt exits, and whether the chatbot's responses can be interpreted clearly by users.

    • Its ability to understand the context of users' inquiries and provide relevant responses that can be understood and interpreted by users.

    • Whether the chatbot can assess the user's level of knowledge and adjust its responses accordingly, whether it uses language that the user can understand, and whether the user feels engaged with the chatbot's insights.

    hashtag
    Coherent

    The degree to which the chatbot's responses and actions are logically consistent and connected with each other, and with the context of the conversation.

    • Whether it can recognize the topics mentioned by the user and provide relevant information that is logically connected with those topics.

    • Whether its responses are self-explanatory and related to each other in a logical and coherent manner.

    • Its level of consistency with actual interviews, i.e., whether its responses are logically consistent with the expectations and norms of real-life interviews.

    • Whether its suggestions are relevant and helpful for the given topic, and whether they are logically consistent with the context of the conversation.

    hashtag
    Natural

    The degree to which the chatbot's responses and actions resemble those of a human being, and are perceived as natural, fluent, and realistic by users.

    • How closely its responses resemble those of a human being, i.e., whether they are naturalistic in terms of language, syntax, grammar, tone, and other linguistic aspects.

    hashtag
    Ethical

    The degree to which the chatbot's responses and actions adhere to ethical principles and standards, and avoid causing harm or offense to users or other stakeholders.

    • Whether it contains any content or responses that are offensive or inappropriate, such as hate speech, discrimination, or harassment.

    hashtag
    Empathetic

    The degree to understand and respond to the emotions and feelings of users in a compassionate and sensitive manner, and to provide emotional support or encouragement when appropriate.

    • Whether it demonstrates an understanding of the user's emotions and concerns, and responds in a way that is supportive and validating.

    • Using appropriate language and tone, acknowledging the user's perspective, and offering words of encouragement or empathy.

    hashtag
    Informative

    The degree to provide accurate and useful information to users in response to their queries or requests for assistance.

    • Its ability to provide factual information about fitness, such as exercise techniques, workout routines, or nutrition advice.

    • Assessing the accuracy and relevance of the information provided, as well as the chatbot's ability to understand and respond appropriately to the user's specific needs and goals.

    hashtag
    Engaging

    The degree to capture and hold the user's attention, as well as to create a positive and enjoyable user experience.

    • The user's level of interest and involvement during the conversation.

    • Assessing the chatbot's ability to generate interesting and relevant topics of conversation, to respond in a timely and personalized manner, and to use engaging language and visual elements to create a more immersive and interactive experience.

    hashtag
    Personalization

    The degree to tailor its responses and recommendations to the individual user's preferences, needs, and past interactions.

    • Evaluate the chatbot's ability to personalize advice based on the user's preferences and past interactions.

    • Whether the chatbot can effectively use data about the user, such as their history, feedback, and stated preferences, to provide personalized responses and recommendations. The following example illustrates this concept:

    Evaluation Criteria, Team Projects, Spring 2023
    The latest movie that the user watched (#3-4).
  • A contextualized question regarding the latest movie (#5-6).

  • A question regarding the genre of the latest movie (#7-10).

  • Your chatbot should give an appropriate response to every user response. For this assignment, you must use all of the following:

    • An ontology covering common movie genres and a branch of movies that you target,

    • At least one macro,

    • At least one regular expression (can be used inside a macro).

    hashtag
    Task 1

    1. Create a Python file quiz3.pyarrow-up-right under the quizarrow-up-right package.

    2. Create a JSON file ontology_quiz3.jsonarrow-up-right under the resourcesarrow-up-right directory.

    3. Update them to design a dialogue flow for the chatbot.

    hashtag
    Task 2

    Create a PDF file quiz3.pdf that describes the following:

    • Sample dialogues that your chatbot can conduct.

    • Explanations of how the ontology, macro(s), and regular expression(s) are used for contextual understanding in your chatbot.

    hashtag
    Submission

    1. Commit and push quiz3.py to your GitHub repository.

    2. Submit quiz3.pdf to Canvas.

    For each type of animal, however, the list can be indefinitely long (e.g., there are over 5,400 mammal species). In this case, it is better to use an ontologyarrow-up-right (e.g., WordNetarrow-up-right, FrameNetarrow-up-right).

    Let us create a JSON file, ontology_animal.jsonarrow-up-right, containing an ontology of animals:

    • #2: the key ontology is paired with a dictionary as a value.

    • #3: the key animal represents the category, and its subcategories are indicated in the list.

    • #4-6: each subcategory, mammal, reptile, and amphibian, has its own subcategory.

    • #7: the ontology hierarchy: animal -> mammal -> dog.

    Given the ontology, the above transitions can be rewritten as follow:

    • #4: matches the key "mammal" as well as its subcategories: "dog", "ape", and "rat".

    • #5: matches the key "reptile" as well as its subcategories: "snake" and "lizard".

    • #6: matches the key "amphibian" as well as its subcategories: "frog" and "salamander".

    Unlike set matching, ontology matching handles plurals (e.g., "frogs").

    Although there is no condition specified for the category dog that includes "golden retriever", there is a condition for its supercategory mammal (#4), to which it backs off.

    triangle-exclamation

    Currently, ontology matching does not handle plurals for compound nouns (e.g., "golden retrievers"), which will be fixed in the following version.

    hashtag
    Expression

    It is possible that a category is mentioned in a non-canonical way; the above conditions do not match "puppy" because it is not introduced as a category in the ontology. In this case, we can specify the aliases as "expressions":

    • #10: the key expressions is paired with a dictionary as a value.

    • #4: allows matching "canine" and "puppy" for the dog category.

    Once you load the updated JSON file, it now understands "puppy" as an expression of "dog":

    circle-check

    It is possible to match "puppy" by adding the term as a category of "dog" (#7). However, it would not be a good practice as "puppy" should not be considered a subcategory of "dog".

    hashtag
    Variable

    Values matched by the ontology can also be stored in variables:

    • #4,7,10: the matched term gets stored in the variable FAVORITE_ANIMAL.

    • #5,8,11: the system uses the value of FAVORITE_ANIMAL to generate the response.

    hashtag
    Loading

    The custom ontology must be loaded to the knowledge base of the dialogue flow before it runs:

    • #1: loads the ontology in ontology_animal.json to the knowledge base of df.

    hashtag
    Code Snippet

  • #8: informs the current weather in Sunnyville.

  • #11: plays the song "Raining Tacosarrow-up-right".

  • #14: print the error message and references to the start state.

  • Notice that when the user input does not match any of the conditions, it prints the error message and loops back to the start state.

    hashtag
    Custom States

    It is possible to name any transition you create as a state:

    • #6: names the state as time.

    • #9: names the state as weather.

    • #13: names the state as play_raining_tacos.

    • #17: references to the play_raining_tacos state.

    hashtag
    Exit State

    State referencing can be abused to create transitions that never end (infinite loop). It is important to design an exit state so you can terminate the conversation without throwing errors:

    • #6,10,14,17: loops back to the start state.

    • #19-21: creates an exit state to terminate the dialogue.

    What is the main difference between an error transition and an exit state?

    An error transition defines a default action for uninterpretable user input, whereas an exit state terminates the current session of the dialogue.

    #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):

    circle-info

    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".

    triangle-exclamation

    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.

    hashtag
    Partial Matching

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

    • #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.

    circle-exclamation

    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":

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

    See Sequential Matching for more details.

    hashtag
    Nesting

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

    • #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.

    circle-exclamation

    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.

    hashtag
    Sequential Matching

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

    • #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.

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

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

    • #10: first matches ('how' or 'and'), then matches ('you' or 'going') sequentially.

    circle-exclamation

    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:

    hashtag
    Code Snippet

    setarrow-up-right
  • #1: imports Macro from STDM.

  • #2: imports type hints from the typingarrow-up-right package in Python.

  • #4: creates the MacroGetName class inheriting Macro.

  • #5: overrides the run method declared in Macro.

  • Currently, the run method returns True no matter what the input is.

    hashtag
    Integration

    Let us create transitions using this macro. A macro is represented by an alias preceded by the pound sign (#):

    • #4: calls the macro #GET_NAME that is an alias of MacroGetName.

    • #13: creates a dictionary defining aliases for macros.

    • #14: creates an object of MacroGetName and saves it to the alias GET_NAME.

    To call the macro, we need to add the alias dictionary macros to the dialogue flow:

    • #3: adds all macros defined in macros to the dialogue flow df.

    hashtag
    Parameters

    The run method has three parameters:

    • ngrams: is a set of strings representing every n-gramarrow-up-right of the input matched by the Natex.

    • vars: is the variable dictionary, maintained by a DialogueFlow object, where the keys and values are variable names and objects corresponding to their values.

    • args: is a list of strings representing arguments specified in the macro call.

    Let us modify the run method to see what ngrams and vars give:

    • #2: prints the original string of the matched input span before preprocessing.

    • #3: prints the input span, preprocessed by STDM and matched by the Natex.

    • #4: prints a set of n-grams.

    When you interact with the the dialogue flow by running it (df.run()), it prints the followings:

    The raw_text method returns the original input:

    The text method returns the preprocessed input used to match the Natex:

    The ngrams gives a set of all possible n-grams in text():

    Finally, the vars gives a dictionary consisting of both system-level and user-custom variables (no user-custom variables are saved at the moment):

    hashtag
    Implementation

    Let us update the run method that matches the title, first name, and last name in the input and saves them to the variables $TITLE, $FIRSTNAME, and $LASTNAME, respectively:

    • #2: creates a regular expression to match the title, first name and last name.

    • #3: searches for the span to match.

    • #4: returns False if no match is found.

    • #6-18 -> exercise.

    • #20-22: saves the recognized title, first name, and last name to the corresponding variables.

    • #24: returns True as the regular expression matches the input span.

    Given the updated macro, the above transitions can be modified as follow:

    • #5: uses the variables $FIRSTNAME and $LASTNAME retrieved by the macro to generate the output.

    The followings show outputs:

    Although the last name is not recognized, and thus, it leaves a blank in the output, it is still considered "matched" because run() returns True for this case. Such output can be handled better by using the language generation capability in Natex.

    circle-exclamation

    Can macros be mixed with other Natex expressions?

    abstract classarrow-up-right
    overridesarrow-up-right

    #3: the system prompts the literal and ends the dialogue.

    S: Hello. How are you?

    hashtag
    Matching

    Natex supports several ways of matching the input with key terms.

    hashtag
    Term

    The condition is true if the input exactly matches the term. A term is represented as a string and can have more than one token:

    • #4: matches the input with 'could be better'.

    • #7: error is a reserved term indicating the default condition of this conditional branching, similar to the wildcard condition (_) in a matcharrow-up-right statement.

    hashtag
    Set

    The condition is true if the input exactly matches any term in the set. A set is represented by curly brackets ({}):

    • #7: matches the input with either 'good' or 'not bad'.

    hashtag
    Unordered List

    The condition is true if some terms in the input match all terms in the unordered list, regardless of the order. An unordered list is represented by angle brackets (<>):

    • #10: matches the input with both 'very' and 'good' in any order.

    hashtag
    Ordered List

    The condition is true if some terms in the input match all terms in the ordered list, a.k.a. sequence, in the same order. An ordered list is represented by square brackets ([]):

    • #13: matches the input with both 'so' and 'good' in that order.

    Currently, it matches the input "could be better" with the condition in #4, but does not match "it could be better" or "could be better for sure", where there are terms other than the ones indicated in the condition.

    1. Update the condition such that it matches all three inputs.

    2. How about matching inputs such as "could be much better" or "could be really better"?

    1. '[could be better]'

    2. '[could be, better]'

    hashtag
    Rigid Sequence

    The condition is true if all terms in the input exactly match all terms in the rigid sequence in the same order. A rigid sequence is represented by square brackets ([ ]), where the left bracket is followed by an exclamation mark (!):

    #16: matches the input with both 'hello' and 'world' in that order.

    circle-info

    There is no difference between matching a term (e.g., 'hello world') and matching a rigid sequence (e.g., '[!hello, world]'). The rigid sequence is designed specifically for negation, which will be deprecated in the next version.

    hashtag
    Negation

    The condition is true if all terms in the input exactly match all terms in the rigid sequence except for ones that are negated. A negation is represented by a hyphen (-):

    • #19: matches the input with 'aweful' and zero to many terms prior to it that are not 'not'.

    hashtag
    Nesting

    It is possible to nest conditions for more advanced matching. Let us create a term condition that matches both "so good" and "very good" using a nested set:

    • #4: uses a set inside a term.

    Does this condition match "good"?

    No, because the outer condition uses term matching that requires the whole input to be the same as the condition.

    However, it does not match when other terms are included in the input (e.g., "It's so good to be here"). To broaden the matching scope, you can put the condition inside a sequence:

    • #4: the term condition is inside the sequence.

    What if we want the condition to match the above inputs as well as "fantastic"? You can put the condition under a set and add fantastic as another term:

    • #4: the sequence condition and the new term fantastic is inside the set.

    The above transitions match "Fantastic" but not "It's fantastic". Update the condition such that it can match both inputs.

    Put fantastic under a sequence such that '{[{so, very} good], [fantastic]}'.

    hashtag
    Variable

    Saving user content can be useful in many ways. Let us consider the following transitions:

    Users may feel more engaged if the system says, "I like dogs too" instead of "them". Natex allows you to create a variable to store the matched term. A variable is represented by a string preceded (without spaces) by a dollar sign $:

    • #4: creates a variable FAVORITE_ANIMAL storing the matched term from the user content.

    • #5: uses the value of the variable to generate the follow-up system utterance.

    circle-info

    In #5, two literals, `I like` and `too!` surround the variable $FAVORITE_ANIMAL. If a variable were indicated inside a literal, STDM would throw an error.

    Matching Strategy
    What is the role of MacroWhatElse?

    hashtag
    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.

    circle-info

    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.

    • #5: matches the condition in the global transition.

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

    Ask about the user's name (with a different way of asking each time the user logins).

  • If it is the first time the system sees the name, then prompt the first-time greeting. Otherwise, greet by asking about its previous recommendation.

  • Recommend a movie or a song, depending on the user's request. Do not make the same recommendation more than once for each genre.

  • If the user requests a different recommendation, make another suggestion.

  • Provide more information about the recommendation upon request.

  • Here is an example dialogue for a user talking to this chatbot for the first time:

    Here is an example dialogue for a user coming back for the second time:

    Your chatbot should give an appropriate response to every user response.

    hashtag
    Task 1

    1. Create a Python file quiz4.pyarrow-up-right under the quizarrow-up-right package.

    2. Update it to design a dialogue flow for the chatbot.

    hashtag
    Task 2

    Create a PDF file quiz4.pdf that describes the following:

    • Sample dialogues that your chatbot can conduct.

    • Explanations of your approach.

    hashtag
    Submission

    1. Commit and push quiz4.py to your GitHub repository.

    2. Submit quiz4.pdf to Canvas.

    Good morning, I was hoping to set up a time to speak with Dr. Brown. Could you assist me with that?
  • Hello, I'm interested in scheduling a general appointment with Professor Green. Would it be possible for you to arrange that for me?

  • Greetings, I would like to schedule a meeting with Prof. Garcia. Is there a convenient time we could arrange?

  • Hi, I would appreciate your help setting up a time to meet with Dr. Patel. Could you let me know his availability?

  • Good day, I would like to request a meeting with Professor Jones for general purposes. Can you assist me in scheduling that?

  • Hello, I need to speak with Dr. Kim and was hoping to schedule an appointment. Could you please let me know when she is available?

  • Good morning, I would like to set up a meeting with Prof. Nguyen. Could you please help me arrange that?

  • Hi, I am interested in speaking with Dr. Lee and was hoping to schedule a time to meet. Could you assist me with that?

  • Good day, I would like to request a general appointment with Professor Chen. Could you please help me schedule a time to meet with her?

  • Give me 10 unique ways of me asking to make an appointment with professors regarding coursework. Write as I would speak to the professor's secretary. Use "Prof.", "Dr.", or "Professor" to indicate professors. Add specific times.

    1. Hi there, could I please schedule an appointment with Prof. Johnson to discuss coursework? I'm available next Tuesday from 2-3pm if that works for him.

    2. Hello, may I request an appointment with Dr. Lee to go over some coursework? I'm free on Thursday mornings before 11am, would that be possible?

    3. Good morning, could I schedule a meeting with Professor Green to talk about our coursework? I'm available on Wednesday afternoons after 1pm, is that a good time for her?

    4. Hi, I was wondering if it would be possible to set up a time to meet with Dr. Patel about coursework? I have availability on Monday and Wednesday evenings after 6pm, would either of those work for her?

    5. Hello, I would like to make an appointment with Professor Hernandez to discuss our coursework. I'm free on Friday mornings between 9am and 11am, could we schedule something then?

    6. Good afternoon, could I request a meeting with Dr. Kim to go over some coursework? I have availability on Tuesday afternoons from 3-4pm, would that work for her?

    7. Hi there, I was hoping to schedule a time to talk with Professor Chen about our coursework. I'm available on Thursday evenings after 5pm, would that be a good time for him?

    8. Hello, may I schedule a meeting with Dr. Jones to discuss some coursework? I'm free on Monday mornings before noon, would that work for her?

    9. Good morning, could I please set up an appointment with Professor Nguyen to go over our coursework? I have availability on Wednesday afternoons from 2-3pm, would that be convenient for her?

    10. Hi, I would like to make an appointment with Dr. Smith to discuss some coursework. I'm available on Friday afternoons after 1pm, would that be a good time for him?

    Replace all professors with their full names.

    1. Hi there, could I please schedule an appointment with Professor Elizabeth Johnson to discuss coursework? I'm available next Tuesday from 2-3pm if that works for her.

    2. Hello, may I request an appointment with Dr. Amanda Lee to go over some coursework? I'm free on Thursday mornings before 11am, would that be possible?

    3. Good morning, could I schedule a meeting with Professor Emily Green to talk about our coursework? I'm available on Wednesday afternoons after 1pm, is that a good time for her?

    4. Hi, I was wondering if it would be possible to set up a time to meet with Dr. Rahul Patel about coursework? I have availability on Monday and Wednesday evenings after 6pm, would either of those work for her?

    5. Hello, I would like to make an appointment with Professor Sofia Hernandez to discuss our coursework. I'm free on Friday mornings between 9am and 11am, could we schedule something then?

    6. Good afternoon, could I request a meeting with Dr. Ji-Young Kim to go over some coursework? I have availability on Tuesday afternoons from 3-4pm, would that work for her?

    7. Hi there, I was hoping to schedule a time to talk with Professor Yen-Ling Chen about our coursework. I'm available on Thursday evenings after 5pm, would that be a good time for him?

    8. Hello, may I schedule a meeting with Dr. Lauren Jones to discuss some coursework? I'm free on Monday mornings before noon, would that work for her?

    9. Good morning, could I please set up an appointment with Professor Thu-Huong Nguyen to go over our coursework? I have availability on Wednesday afternoons from 2-3pm, would that be convenient for her?

    10. Hi, I would like to make an appointment with Dr. James Smith to discuss some coursework. I'm available on Friday afternoons after 1pm, would that be a good time for him?

    Give me 10 unique ways of me asking to make an appointment with professors regarding research. Write as I would speak to the professor's secretary. Use only first names to indicate professors without "Prof.", "Dr.", or "Professor". Add specific times where multiple options are allowed.

    1. Hi there! Could I schedule a meeting with Sarah sometime this week to discuss research? I'm available on Tuesday at 2 pm, Wednesday at 10 am, or Thursday at 3 pm.

    2. Hello! I was wondering if I could set up a time to chat with David about some research I'm working on. Is he available next Monday at 11 am, Wednesday at 1 pm, or Friday at 3 pm?

    3. Good morning! Can I schedule a meeting with Jessica to talk about research opportunities? I'm free on Tuesday at 11 am, Thursday at 2 pm, or Friday at 10 am.

    4. Hey there! Could I arrange a time to meet with John to discuss a research project I'm working on? I'm available on Monday at 1 pm, Wednesday at 3 pm, or Friday at 11 am.

    5. Hi! I would love to schedule a meeting with Lisa to talk about some research ideas I have. Would next Wednesday at 10 am, Thursday at 2 pm, or Friday at 11 am work for her?

    6. Good afternoon! I was hoping to schedule a meeting with Michael to discuss a potential research collaboration. Is he available on Tuesday at 3 pm, Wednesday at 10 am, or Friday at 2 pm?

    7. Hello there! Can I arrange a time to meet with Rachel to discuss research opportunities in her department? I'm free on Monday at 11 am, Wednesday at 1 pm, or Friday at 3 pm.

    8. Hey! Could I schedule a meeting with Sam to talk about a research project I'm working on? I'm available on Tuesday at 2 pm, Thursday at 11 am, or Friday at 10 am.

    9. Hi, I'd like to schedule a meeting with Tom to discuss a research proposal I'm developing. Would next Monday at 2 pm, Wednesday at 10 am, or Thursday at 3 pm work for him?

    10. Good morning! I was hoping to set up a time to meet with Victoria to discuss some research ideas I have. Is she available on Tuesday at 1 pm, Thursday at 3 pm, or Friday at 10 am?

    Give me 10 unique ways of me asking to make an appointment with professors regarding specific course issues (e.g., homework, quiz, midterm, final, exam). Write as I would speak to the professor's secretary. Use "Prof.", "Dr.", or "Professor" to indicate professors. Add specific time for the appointment.

    1. Hello, may I schedule a meeting with Prof. Smith to discuss some issues with the upcoming midterm? How about next Tuesday at 3 PM?

    2. Good morning, could I make an appointment with Dr. Johnson to talk about the final exam? Would next Wednesday at 1 PM work for you?

    3. Excuse me, can I schedule a meeting with Professor Brown to go over some questions I had on the last quiz? What about this Thursday at 10 AM?

    4. Hi, I was wondering if I could meet with Prof. Garcia to discuss a specific homework problem. Is there any availability next Friday at 2 PM?

    5. Good afternoon, can I make an appointment with Dr. Kim to talk about some course material I am struggling with? How about next Monday at 11 AM?

    6. Hello, may I schedule a meeting with Professor Patel to discuss an issue with the midterm grades? Would next Wednesday at 4 PM be possible?

    7. Excuse me, I would like to make an appointment with Prof. Jones to review some final exam questions. What about this Friday at 9 AM?

    8. Hi, I was hoping to schedule a meeting with Dr. Davis to discuss some study strategies for the upcoming final exam. Is there any availability next Thursday at 2 PM?

    9. Good morning, can I make an appointment with Professor Lee to discuss some questions I have about the course syllabus? How about next Tuesday at 1 PM?

    10. Hello, I would like to schedule a meeting with Dr. Hernandez to discuss some exam review material. Is there any availability next Monday at 3 PM?

    Specify when the homework, quiz, midterm, final, exam was.

    1. Hi, could I schedule a meeting with Prof. Johnson to discuss some issues with the homework we turned in last Friday? How about next Tuesday at 3 PM?

    2. Good morning, I was wondering if I could make an appointment with Dr. Williams to go over some questions I had on the quiz we took last week. Would next Wednesday at 1 PM work for you?

    3. Excuse me, may I schedule a meeting with Professor Brown to talk about the midterm we took two weeks ago? What about this Thursday at 10 AM?

    4. Hi, I would like to make an appointment with Prof. Garcia to discuss a specific problem on the final exam we took last month. Is there any availability next Friday at 2 PM?

    5. Good afternoon, could I make an appointment with Dr. Kim to talk about some course material we covered in class yesterday? How about next Monday at 11 AM?

    6. Hello, I was wondering if I could schedule a meeting with Professor Patel to discuss an issue with the midterm grades that were posted last week. Would next Wednesday at 4 PM be possible?

    7. Excuse me, may I schedule a meeting with Prof. Jones to review some final exam questions that we went over in class last week? What about this Friday at 9 AM?

    8. Hi, I would like to schedule a meeting with Dr. Davis to discuss some study strategies for the upcoming final exam that is in two weeks. Is there any availability next Thursday at 2 PM?

    9. Good morning, could I make an appointment with Professor Lee to discuss some questions I have about the course syllabus and the midterm that we took three weeks ago? How about next Tuesday at 1 PM?

    10. Hello, may I schedule a meeting with Dr. Hernandez to discuss some exam review material that was covered in class yesterday? Is there any availability next Monday at 3 PM?

    Give me 10 unique ways of me asking to make an appointment with professors regarding research issues (e.g., progress, deadline, result). Write as I would speak to the professor's secretary. Use "Prof.", "Dr.", or "Professor" to indicate professors.

    1. Hi, may I please schedule a meeting with Prof. Smith to discuss my research progress and set some deadlines?

    2. Good morning, I was hoping to arrange a meeting with Dr. Johnson to review the results of my research project.

    3. Hello, could you help me schedule an appointment with Professor Garcia to discuss some issues related to my research?

    4. Hi, I need to meet with Prof. Lee to discuss the results of my research and get some feedback on next steps. Can you help me schedule a meeting?

    5. Good afternoon, I'd like to schedule a meeting with Dr. Patel to discuss the progress of my research and any areas where I need to improve.

    6. Hello, I'd like to set up a meeting with Professor Kim to discuss my research project and ask for advice on how to proceed.

    7. Hi, could you help me schedule a meeting with Prof. Brown to talk about my research progress and any issues I'm encountering?

    8. Good morning, I need to meet with Dr. Davis to discuss the results of my research and get some guidance on next steps. Can you help me schedule a meeting?

    9. Hello, I'd like to arrange a meeting with Professor Nguyen to discuss my research and get some feedback on how I can improve it.

    10. Hi, may I please schedule a meeting with Prof. Taylor to review the progress of my research and discuss any concerns or questions I have?

    Replace all professors with their full names. Indicate another person who also wants to come to this appointment.

    1. Hi there, could I please schedule an appointment with Professor Jane Smith and my research partner, John Doe, to discuss the progress of our research project?

    2. Good morning, I was hoping to schedule a meeting with Dr. Emily Johnson and my lab assistant, Sarah Lee, to talk about the results of our latest experiment.

    3. Hello, I would like to request a meeting with Professor William Brown and my co-author, Karen Chen, to discuss the deadlines for our research paper.

    4. Hi, could you help me schedule a time to meet with Professor Sungsoo Kim and my graduate student, Michael Park, to go over the progress of our thesis?

    5. Good afternoon, I need to speak with Dr. Maya Patel and my research assistant, David Rodriguez, regarding the results of our research study. Could you assist me in scheduling a meeting?

    6. Hello, I was hoping to schedule a meeting with Professor Youngjin Lee and my fellow lab member, Jiyeon Kim, to discuss the next steps for our research project.

    7. Good morning, I need to speak with Dr. Carlos Garcia and my co-researcher, Maria Torres, about our research proposal. Could you please help me schedule a meeting?

    8. Hi, I'd like to request a meeting with Professor Rachel Davis and my research partner, Steven Nguyen, to talk about the progress of our research project and any feedback they may have.

    9. Hello, I would like to schedule a time to meet with Dr. Adam Adams and my co-investigator, Laura Nguyen, to discuss the results of our latest research experiment and any potential implications.

    10. Good afternoon, I need to speak with Professor Lingling Chen and my research collaborator, Wei Zhang, regarding the deadlines for our research paper. Could you please assist me in scheduling a meeting with them?

    • G: General

    • C: Coursework

    • R: Research

    • CI: Course Issues

    • RI: Research Issues

    1. Is the following about making an appointment? Respond with "yes" or "no". 2. Who does the speaker want to meet? Respond with the name. 3. What are the suggested times? Respond with bullet points 4. What is it about? Save the answer to a JSON format such as {"Q1": "yes", "Q2": [{"first_name": "John", "last_name": "Doe"}], "Q3": ["Monday at 1 pm"], "Q4": "Regarding the deadlines for their research paper."}:

    Now is 2023-03-10 12:05. Convert "Tomorrow at 3:30pm" to the absolute date and time. Respond in the following JSON format: {"from": "%Y-%m-%d %H:%M", "to": "%Y-%m-%d %H:%M"}.

    "Thursday evenings after 5pm"

    "Thursday between 3:30 - 5pm"

    S: Hello, may I have your name?
    U: Call me Jinho.
    S: It's nice to meet you, Jinho. What was the latest movie you watched?
    U: That'd be Spider Man No Way Home.
    S: I love Marvel movies. Who is your favorite avenger?
    U: Captain America.
    S: Captain is my man. So I guess you are a big fan of Sci-Fi movies?
    U: Yes, I am.
    S: Excellent. Why do you like them so much?
    U: They make me feel like living in the future.
    S: I'm with you. Thanks for sharing.
    S: What is your favorite animal?
    U: I love frogs
    S: Amphibians can be cute :)
    S: What is your favorite animal?
    U: I love my golden retriever
    S: I love mammals!
    S: What is your favorite animal?
    U: I cannot live without my puppy!
    S: I've never heard of that animal.
    S: What is your favorite animal?
    U: I cannot live without my puppy!
    S: I love mammals!
    S: What is your favorite animal?
    U: I love frogs
    S: frogs can be cute :)
    S: What is your favorite animal?
    U: I can't live without my puppy!
    S: I love puppy !
    transitions = {
        'state': 'start',
        '`What is your favorite animal?`': {
            '[{dog, ape, rat}]': {
                '`I love mammals!`': 'end'
            },
            '[{snake, lizard}]': {
                '`Reptiles are slick, haha`': 'end'
            },
            '[{frog, salamander}]': {
                '`Amphibians can be cute :)`': 'end'
            },
            'error': {
                '`I\'ve never heard of that animal.`': 'end'
            }
        }
    }
    S: What is your favorite animal?
    U: I love frog
    S: Amphibians can be cute :)
    S: What is your favorite animal?
    U: Cat
    S: I've never heard of that animal.
    S: What is your favorite animal?
    U: Dogs
    S: I've never heard of that animal.
    {
        "ontology": {
            "animal": ["mammal", "fish", "bird", "reptile", "amphibian"],
            "mammal": ["dog", "ape", "rat"],
            "reptile": ["snake", "lizard"],
            "amphibian": ["frog", "salamander"],
            "dog": ["golden retriever", "poodle"]
        }
    }
    transitions = {
        'state': 'start',
        '`What is your favorite animal?`': {
            '[#ONT(mammal)]': {
                '`I love mammals!`': 'end'
            },
            '[#ONT(reptile)]': {
                '`Reptiles are slick, haha`': 'end'
            },
            '[#ONT(amphibian)]': {
                '`Amphibians can be cute :)`': 'end'
            },
            'error': {
                '`I\'ve never heard of that animal.`': 'end'
            }
        }
    }
    {
        "ontology": {
            "animal": ["mammal", "fish", "bird", "reptile", "amphibian"],
            "mammal": ["dog", "ape", "rat"],
            "reptile": ["snake", "lizard"],
            "amphibian": ["frog", "salamander"],
            "dog": ["golden retriever", "poodle"]
        },
    
        "expressions": {
            "dog": ["canine", "puppy"]
        }
    }
    transitions = {
        'state': 'start',
        '`What is your favorite animal?`': {
            '[$FAVORITE_ANIMAL=#ONT(mammal)]': {
                '`I love` $FAVORITE_ANIMAL `!`': 'end'
            },
            '[$FAVORITE_ANIMAL=#ONT(reptile)]': {
                '$FAVORITE_ANIMAL `are slick, haha`': 'end'
            },
            '[$FAVORITE_ANIMAL=#ONT(amphibian)]': {
                '$FAVORITE_ANIMAL `can be cute :)`': 'end'
            },
            'error': {
                '`I\'ve never heard of that animal.`': 'end'
            }
        }
    }
    df = DialogueFlow('start', end_state='end')
    df.knowledge_base().load_json_file('resources/ontology_animal.json')
    df.load_transitions(transitions)
    def natex_ontology() -> DialogueFlow:
        transitions = {
            'state': 'start',
            '`What is your favorite animal?`': {
                '[$FAVORITE_ANIMAL=#ONT(mammal)]': {
                    '`I love` $FAVORITE_ANIMAL `!`': 'end'
                },
                '[$FAVORITE_ANIMAL=#ONT(reptile)]': {
                    '$FAVORITE_ANIMAL `are slick, haha`': 'end'
                },
                '[$FAVORITE_ANIMAL=#ONT(amphibian)]': {
                    '$FAVORITE_ANIMAL `can be cute :)`': 'end'
                },
                'error': {
                    '`I\'ve never heard of that animal.`': 'end'
                }
            }
        }
    
        df = DialogueFlow('start', end_state='end')
        df.knowledge_base().load_json_file('resources/ontology_animal.json')
        df.load_transitions(transitions)
        return df
        
    if __name__ == '__main__':
        natex_ontology().run()
    S: What can I do for you?
    U: What time is it now?
    S: It's 3PM.
    S: What can I do for you?
    U: What's the weather like?
    S: It's sunny outside
    S: What can I do for you?
    U: Play rainy taco
    S: Sorry, I didn't understand you. What can I do for you?
    U: Play raining tacos
    S: It's raining tacos. From out of the sky ...
    S: What can I do for you?
    U: Play rainy taco
    S: Sorry, I didn't understand you. It's raining tacos. From out of the sky ...
    S: What can I do for you?
    U: time
    S: It's 3PM. What can I do for you?
    U: weather
    S: It's sunny outside What can I do for you?
    U: play raining tacos
    S: It's raining tacos. From out of the sky ... What can I do for you?
    U: exit
    S: Goodbye!
    transitions = {
        'state': 'start',
        '`What can I do for you?`': {
            '[{time, clock}]': {
                '`It\'s 3PM.`': 'end'
            },
            '[{weather, forecast}]': {
                '`It\'s sunny outside`': 'end'
            },
            '[play, raining tacos]': {
                '`It\'s raining tacos. From out of the sky ...`': 'end'
            },
            'error': {
                '`Sorry, I didn\'t understand you.`': 'start'
            }
        }
    }
    transitions = {
        'state': 'start',
        '`What can I do for you?`': {
            '[{time, clock}]': {
                'state': 'time',
                '`It\'s 3PM.`': 'end'
            },
            '[{weather, forecast}]': {
                'state': 'weather',
                '`It\'s sunny outside`': 'end'
            },
            '[play, raining tacos]': {
                'state': 'play_raining_tacos',
                '`It\'s raining tacos. From out of the sky ...`': 'end'
            },
            'error': {
                '`Sorry, I didn\'t understand you.`': 'play_raining_tacos'
            }
        }
    }
    transitions = {
        'state': 'start',
        '`What can I do for you?`': {
            '[{time, clock}]': {
                'state': 'time',
                '`It\'s 3PM.`': 'start'
            },
            '[{weather, forecast}]': {
                'state': 'weather',
                '`It\'s sunny outside`': 'start'
            },
            '[play, raining tacos]': {
                'state': 'play_raining_tacos',
                '`It\'s raining tacos. From out of the sky ...`': 'start'
            },
            'error': {
                '`Sorry, I didn\'t understand you.`': 'start'
            },
            '[exit]': {
                'state': 'exit',
                '`Goodbye!`': 'end'
            }
        }
    }
    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 :(
    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 :(
    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.
    S: Hello. How are you?
    U: good and fantastic!
    S: Glad to hear that you are doing well :)
    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 :(
    S: Hello. How are you?
    U: Fine. How are you doing?
    S: I feel superb. Thank you!
    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.
    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!
    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!
    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'
            }
        }
    }
    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'
            },
        }
    }
    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'
            },
        }
    }
    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'
            },
        }
    }
    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'
            },
        }
    }
    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()
    S: Hello. What should I call you?
    U: Dr. Jinho Choi
    S: It's nice to meet you.
    S: Hello. What should I call you?
    U: Dr. Jinho Choi
    S: It's nice to meet you, jinho . choi is my favorite name.
    S: Hello. What should I call you?
    U: Jinho Choi
    S: It's nice to meet you, jinho . choi is my favorite name.
    S: Hello. What should I call you?
    U: Dr. Choi
    S: It's nice to meet you, dr choi . choi is my favorite name.
    S: Hello. What should I call you?
    U: Jinho
    S: It's nice to meet you, jinho .  is my favorite name.
    from emora_stdm import Macro, Ngrams
    from typing import Dict, Any, List
    
    class MacroGetName(Macro):
        def run(self, ngrams: Ngrams, vars: Dict[str, Any], args: List[Any]):
            return True
    transitions = {
        'state': 'start',
        '`Hello. What should I call you?`': {
            '#GET_NAME': {
                '`It\'s nice to meet you.`': 'end'
            },
            'error': {
                '`Sorry, I didn\'t understand you.`': 'end'
            }
        }
    }
    
    macros = {
        'GET_NAME': MacroGetName()
    }
    df = DialogueFlow('start', end_state='end')
    df.load_transitions(transitions)
    df.add_macros(macros)
    def run(self, ngrams: Ngrams, vars: Dict[str, Any], args: List[Any]):
        print(ngrams.raw_text())
        print(ngrams.text())
        print(ngrams)
        print(vars)
    Dr. Jinho Choi
    dr jinho choi
    {
        'dr',
        'jinho',
        'choi',
        'dr jinho',
        'jinho choi',
        'dr jinho choi'
    }
    {
        '__state__': '0',
        '__system_state__': 'start',
        '__stack__': [],
        '__user_utterance__': 'dr jinho choi',
        '__goal_return_state__': 'None',
        '__selected_response__': 'Hello. What should I call you?',
        '__raw_user_utterance__': 'Dr. Jinho Choi',
        '__converged__': 'True'
    }
    def run(self, ngrams: Ngrams, vars: Dict[str, Any], args: List[Any]):
        r = re.compile(r"(mr|mrs|ms|dr)?(?:^|\s)([a-z']+)(?:\s([a-z']+))?")
        m = r.search(ngrams.text())
        if m is None: return False
    
        title, firstname, lastname = None, None, None
        
        if m.group(1):
            title = m.group(1)
            if m.group(3):
                firstname = m.group(2)
                lastname = m.group(3)
            else:
                firstname = m.group()
                lastname = m.group(2)
        else:
            firstname = m.group(2)
            lastname = m.group(3)
    
        vars['TITLE'] = title
        vars['FIRSTNAME'] = firstname
        vars['LASTNAME'] = lastname
    
        return True
    transitions = {
        'state': 'start',
        '`Hello. What should I call you?`': {
            '#GET_NAME': {
                '`It\'s nice to meet you,` $FIRSTNAME `.` $LASTNAME `is my favorite name.`': 'end'
            },
            'error': {
                '`Sorry, I didn\'t understand you.`': 'end'
            }
        }
    }?
    S: Hello. How are you?
    U: Could be better..
    S: I hope your day gets better soon :(
    S: Hello. How are you?
    U: It could be better
    S: Sorry, I didn't understand you.
    S: Hello. How are you?
    U: Good!!
    S: Glad to hear that you are doing well :)
    S: Hello. How are you?
    U: Not bad..
    S: Glad to hear that you are doing well :)
    S: Hello. How are you?
    U: I'm good
    S: Sorry, I didn't understand you.
    S: Hello. How are you?
    U: Not so bad
    S: Sorry, I didn't understand you.
    S: Hello. How are you?
    U: Very good!
    S: So glad that you are having a great day!
    S: Hello. How are you?
    U: I'm very well and good
    S: So glad that you are having a great day!
    S: Hello. How are you?
    U: Good, things are going very well!
    S: So glad that you are having a great day!
    S: Hello. How are you?
    U: Good
    S: Glad to hear that you are doing well :)
    S: Hello. How are you?
    U: So good!
    S: Things are just getting better for you!
    S: Hello. How are you?
    U: It's so wonderfully good!
    S: Things are just getting better for you!
    S: Hello. How are you?
    U: It's good
    S: Sorry, I didn't understand you.
    S: Hello. How are you?
    U: It's good so far
    S: Sorry, I didn't understand you.
    S: Hello. How are you?
    U: Hello World
    S: You're a programmer!
    S: Hello. How are you?
    U: hello world to you
    S: Sorry, I didn't understand you.
    S: Hello. How are you?
    U: It's hello world
    S: Sorry, I didn't understand you.
    S: Hello. How are you?
    U: Aweful!
    S: Sorry to hear that :(
    S: Hello. How are you?
    U: It's so aweful..
    S: Sorry to hear that :(
    S: Hello. How are you?
    U: Not aweful
    S: Sorry, I didn't understand you.
    S: Hello. How are you?
    U: Not so aweful
    S: Sorry to hear that :(
    S: Hello. How are you?
    U: Aweful and terrible
    S: Sorry, I didn't understand you.
    S: Hello. How are you?
    U: I'm very good, thank you!
    S: Things are just getting better for you!
    S: Hello. How are you?
    U: It's so good to be here :)
    S: Things are just getting better for you!
    S: Hello. How are you?
    U: Fantastic!!!
    S: Things are just getting better for you!
    S: Hello. How are you?
    U: Good
    S: Sorry, I didn't understand you.
    S: Hello. How are you?
    U: It's fantastic
    S: Sorry, I didn't understand you.
    S: What is your favorite animal?
    U: I like dogs
    S: I like them too!
    S: What is your favorite animal?
    U: I like dogs!!
    S: I like dogs too!
    S: What is your favorite animal?
    U: Hamsters are my favorite!
    S: I like hamsters too!
    transitions = {
        'state': 'start',
        '`Hello. How are you?`': 'end'  # literal
    }
    transitions = {
        'state': 'start',
        '`Hello. How are you?`': {         # literal
            'could be better': {           # term
                '`I hope your day gets better soon :(`': 'end'
            },
            'error': {
                '`Sorry, I didn\'t understand you.`': 'end'
            }
        }
    }
    transitions = {
        'state': 'start',
        '`Hello. How are you?`': {         # literal
            'could be better': {           # term
                '`I hope your day gets better soon :(`': 'end'
            },
            '{good, not bad}': {           # set
                '`Glad to hear that you are doing well :)`': 'end'
            },
            'error': {
                '`Sorry, I didn\'t understand you.`': 'end'
            }
        }
    }
    transitions = {
        'state': 'start',
        '`Hello. How are you?`': {         # literal
            'could be better': {           # term
                '`I hope your day gets better soon :(`': 'end'
            },
            '{good, not bad}': {           # set
                '`Glad to hear that you are doing well :)`': 'end'
            },
            '<very, good>': {              # unordered list
                '`So glad that you are having a great day!`': 'end'
            },
            'error': {
                '`Sorry, I didn\'t understand you.`': 'end'
            }
        }
    }
    transitions = {
        'state': 'start',
        '`Hello. How are you?`': {         # literal
            'could be better': {           # term
                '`I hope your day gets better soon :(`': 'end'
            },
            '{good, not bad}': {           # set
                '`Glad to hear that you are doing well :)`': 'end'
            },
            '<very, good>': {              # unordered list
                '`So glad that you are having a great day!`': 'end'
            },
            '[so, good]': {                # ordered list (sequence)
                '`Things are just getting better for you!`': 'end'
            },
            'error': {
                '`Sorry, I didn\'t understand you.`': 'end'
        }
    }
    transitions = {
        'state': 'start',
        '`Hello. How are you?`': {         # literal
            'could be better': {           # term
                '`I hope your day gets better soon :(`': 'end'
            },
            '{good, not bad}': {           # set
                '`Glad to hear that you are doing well :)`': 'end'
            },
            '<very, good>': {              # unordered list
                '`So glad that you are having a great day!`': 'end'
            },
            '[so, good]': {                # ordered list (sequence)
                '`Things are just getting better for you!`': 'end'
            },
            '[!hello, world]': {           # rigid sequence
                '`You\'re a programmer!`': 'end'
            },
            'error': {
                '`Sorry, I didn\'t understand you.`': 'end'
            }
        }
        }
    }
    transitions = {
        'state': 'start',
        '`Hello. How are you?`': {         # literal
            'could be better': {           # term
                '`I hope your day gets better soon :(`': 'end'
            },
            '{good, not bad}': {           # set
                '`Glad to hear that you are doing well :)`': 'end'
            },
            '<very, good>': {              # unordered list
                '`So glad that you are having a great day!`': 'end'
            },
            '[so, good]': {                # ordered list (sequence)
                '`Things are just getting better for you!`': 'end'
            },
            '[!hello, world]': {           # rigid sequence
                '`You\'re a programmer!`': 'end'
            },
            '[!-not, aweful]': {           # negation
                '`Sorry to hear that :(`': 'end'
            },
            'error': {
                '`Sorry, I didn\'t understand you.`': 'end'
            }
        }
    }
    transitions = {
        'state': 'start',
        '`Hello. How are you?`': {
            '{so, very} good': {
                    '`Things are just getting better for you!`': 'end'
                },
            'error': {
                '`Sorry, I didn\'t understand you.`': 'end'
            }
        }
    }
    transitions = {
        'state': 'start',
        '`Hello. How are you?`': {
            '[{so, very} good]': {
                    '`Things are just getting better for you!`': 'end'
                },
            'error': {
                '`Sorry, I didn\'t understand you.`': 'end'
            }
        }
    }
    transitions = {
        'state': 'start',
        '`Hello. How are you?`': {
            '{[{so, very} good], fantastic}': {
                    '`Things are just getting better for you!`': 'end'
                },
            'error': {
                '`Sorry, I didn\'t understand you.`': 'end'
            }
        }
    }
    transitions = {
        'state': 'start',
        '`What is your favorite animal?`': {
            '[{dogs, cats, hamsters}]': {
                '`I like them too!`': 'end'
            },
            'error': {
                '`I\'ve never heard of that animal.`': 'end'
            }
        }
    }
    transitions = {
        'state': 'start',
        '`What is your favorite animal?`': {
            '[$FAVORITE_ANIMAL={dogs, cats, hamsters}]': {
                '`I like` $FAVORITE_ANIMAL `too!`': 'end'
            },
            'error': {
                '`I\'ve never heard of that animal.`': 'end'
            }
        }
    }
    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!
    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!
    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?
    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: I hope you are OK. Glad to hear that. What else do you want to talk about?
    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)
    gloabl_transitions = {
        '[{covid, corona, virus}]': {
            '`I hope you are OK.`': 'good'
        },
        '[{birthday}]': {
            '`Happy birthday to you!`': 'good'
        }
    }
    
    df.load_global_nlu(gloabl_transitions)
    gloabl_transitions = {
        '[{covid, corona, virus}]': {
            'score': 0.5,
            '`I hope you are OK.`': 'good'
        },
        '[{birthday}]': {
            'score': 0.5,
            '`Happy birthday to you!`': 'good'
        }
    }
    S: Good afternoon; it's sunny today. What should I call you?
    U: Call me Jinho.
    S: Hi, Jinho. Nice to meet you. What do you want me to recommend?
    U: A movie, please.
    S: How about "Spider-Man: Homecoming"? It's my personal favorite.
    U: I've already seen that.
    S: Got ya. How about "The Sound of Music"? It's classic.
    U: Sure, I'll watch that one. Thanks.
    S: Don't mention. 
    S: Good morning; it's cloudy today. What's your name?
    U: I'm Jinho.
    S: Welcome back, Jinho. Did you get to watch "The Sound of Music"?
    U: Yes, I did. I loved it.
    S: Wonderful. What else do you want me to recommend?
    U: Maybe, a song?
    S: How about "Raining Tacos"?
    U: What is it about?
    S: It's a fun children's song by Parry Gripp.
    U: Sure, I'll listen to that.
    S: Enjoy!
    S: Hello, Jinho. Should I call you Jinho or something else?
    U: 
    PyCharm may automatically create the __init__.py file under src, which is required for Python to treat the directory as a package, so leave the file as it is.

    2. Create the quizarrow-up-right package under the src package.

    3. Create a python file called quiz0.pyarrow-up-right under the quiz package and copy the code:

    circle-info

    If PyCharm prompts you to add quiz0.py to git, press [Add].

    4. Run quiz0 by clicking [Run] - [Run 'quiz0']. An alternative way of running the program is to click the green triangle by the line #26 and select Run 'quiz0':

    5. Conduct the following two dialogues with the chatbot you just created (S: system, U: user):

    This is what your directory structure may look like in PyCharm after finishing this assignment:

    hashtag
    Submission

    1. Create the .gitignorearrow-up-right file under the conversational-ai directory and copy the content:

    2. Add the following files to git by right-clicking on them and selecting [Git] - [Add]:

    • quiz0.py

    • .gitignore

    circle-info

    Once the files are added to git, they should turn green. If not, restart PyCharm and try to add them again.

    3. Commit and push your changes to GitHub:

    • Right-click on conversational-ai.

    • Select [Git] - [Commit Directory].

    • Enter a commit message (e.g., Submit Quiz 0).

    • Press the [Commit and Push] button.

    circle-info

    Make sure you both commit and push, not just commit.

    4. Check if the above files are properly pushed to your GitHub repository.

    5. Submit the address of your repository to Canvas.

    srcarrow-up-right
    In-class Discussion

    You will meet three groups during this class. Each team discussion will last 20 minutes, including the time to find group members:

    1. Find 3-4 people you have not interacted with from your previous group(s).

    2. Discuss your project idea with your group and check if anyone has a similar interest.

    Individual Ideas, Spring 2023.
    Quiz 1

    Conversation: interactive communication between two or more people.

  • Dialogue: a conversation, often between two people, with a specific goal in mind.

  • Dialog: a window that appears on a screen in computing contexts (e.g., dialog box).

    hashtag
    Application

    • Dialogue System: a computer system that interacts with humans in natural language.

    • Conversational Agent: a dialogue system that interprets and responds to user statements.

    • Virtual Assistant: a dialogue system that performs tasks or services for user requests.

    • Chatbot: a dialogue system that simulates and processes human conversation.

    circle-info

    Chatbots are typically understood to follow pre-defined dialogue flows for open-domain conversations without using sophisticated artificial intelligence technology.

    hashtag
    Intelligence

    • Dialogue Management: a process of controlling the state and flow of the dialogue to conduct contextual communications.

    • Conversational AI: a type of Artificial Intelligence (AI) for a dialogue system to understand user inputs and respond properly to them, often processed by machine learning models.

    1. What are examples of dialogue systems currently used in practical applications?

    2. Are there applications that would greatly benefit from adopting dialogue systems?

    hashtag
    Properties

    hashtag
    Unit

    • Turn: a single contribution from one speaker to the dialogue.

    • Utterance: a natural unit of speech bounded by breaths or pauses.

    circle-info

    For a text-based conversation, each turn is often considered an utterance.

    hashtag
    Context

    • Speech Act: the action, either explicitly or implicitly, expressed by an utterance (e.g., answering, advising, greeting; see Switchboard Dialog Act Corpusarrow-up-right).

    • Intent: the user's goal expressed by an utterance within the context of a conversation (e.g., making an appointment, requesting information).

    • Topic: the matter dealt with in an utterance (e.g., movie, family, midterm).

    circle-info

    It is possible that one utterance expresses multiple speech acts and intents and also deals with various topics.

    Classify each of the following utterances from Friends S1E1 using the dialogue acts: http://compprag.christopherpotts.net/swda.htmlarrow-up-right

    Ross: Hi.

    Joey: This guy says hello, I wanna kill myself.

    Monica: Are you okay, sweetie?

    Ross: I just feel like someone reached down my throat, grabbed my small intestine, pulled it out of my mouth and tied it around my neck...

    Chandler: Cookie?

    Monica: Carol moved her stuff out today.

    Joey: Ohh.

    Monica: Let me get you some coffee.

    Ross: Thanks.

    hashtag
    Scopes

    hashtag
    Task-oriented

    Task-oriented dialogue systems have specific tasks to be accomplished:

    • The Second Dialog State Tracking Challengearrow-up-right, Henderson et al., SIGDIAL, 2014 (datasetarrow-up-right).

    • Conditional Generation and Snapshot Learning in Neural Dialogue Systemsarrow-up-right, Wen et al., EMNLP 2016 (datasetarrow-up-right).

    • Learning End-to-End Goal-Oriented Dialogarrow-up-right, Bordes et al., ICLR, 2017 (datasetarrow-up-right).

    • , Eric et al., SIGDIAL, 2017 ().

    • , Budzianowski et al., EMNLP, 2018 ().

    • , Qin et al., EMNLP, 2019 ().

    • , Rastogi et al., AAAI, 2020 ().

    hashtag
    Open-domain

    Open-domain dialogue systems aim to talk about any topics without specific end goals:

    • Alexa Prize Socialbot Grand Challengearrow-up-right (Emora demoarrow-up-right)

    • Meta BlenderBotarrow-up-right (demoarrow-up-right)

    • OpenAI ChatGPTarrow-up-right (demoarrow-up-right; requires login)

    • (; )

    1. What kind of tasks are presented in the above task-oriented datasets?

    2. Try the demos of BlenderBot and ChatGPT. What are their limitations?

    3. What are the challenges in building task-oriented vs. open-domain dialogue systems?

    hashtag
    Techniques

    hashtag
    State Machine

    A dialogue flow can be designed into a fine-state machine. Most commercial dialogue systems take this approach because it gives greater control over how the systems behave. Several platforms are available to facilitate the development of state machine-based dialogue systems:

    • Amazon Lexarrow-up-right

    • Google Dialogflowarrow-up-right

    • IBM Watson Assistantarrow-up-right

    hashtag
    End-to-End

    Recent researches focus on developing end-to-end dialogue systems using sequence-to-sequence (S2S) models, which is a type of encoder-decoder model:

    • Sequence to Sequence Learning with Neural Networksarrow-up-right, Sutskever et al., NeurIPS, 2014.

    The current state-of-the-art S2S models use transformers such as BERT as their encoders:

    • Attention is All you Needarrow-up-right, Vaswani et al., NeurIPS, 2017.

    • BERT: Pre-training of Deep Bidirectional Transformers for Language Understandingarrow-up-right, Devlin et al., NAACL, 2019.

    Three of the open-domain dialogue systems above, Meta BlenderBot, OpenAI ChatGPT, and Google LaMDA, are end-to-end systems based on S2S models.

    circle-info

    Implementing an end-to-end system is beyond the scope of this course. Thus, we will use the state machine approach to develop dialogue systems, starting from Chapter 2.

    hashtag
    Assessments

    The primary objective of both task-oriented and open-domain dialogue systems is to satisfy users by communicating with them. For task-oriented, users are generally satisfied if the tasks are accomplished efficiently. For open-domain, however, user satisfaction is often highly subjective, so proper conversational analysis may need to be involved.

    • Towards Unified Dialogue System Evaluation: A Comprehensive Analysis of Current Evaluation Protocolsarrow-up-right, Finch and Choi, SIGDIAL, 2020.

    • Report from the NSF Future Directions Workshop on Automatic Evaluation of Dialog: Research Directions and Challengesarrow-up-right, Mehri et al., arXiv, 2022.

    • Don't Forget Your ABC's: Evaluating the State-of-the-Art in Chat-Oriented Dialogue Systemsarrow-up-right, Finch et al., arXiv, 2022.

    Regular Expresions 101arrow-up-right

    hashtag
    Syntax

    hashtag
    Grouping

    Syntax
    Description

    [ ]

    A set of characters

    ( )

    A capturing group

    (?: )

    A non capturing group

    |

    or

    hashtag
    Repetitions

    Syntax
    Description
    Non-greedy

    .

    Any character except a newline

    *

    0 or more repetitions

    *?

    +

    1 or more repetitions

    +?

    hashtag
    Special Characters

    Syntax
    Description

    ^

    The start of the string

    $

    The end of the string

    \num

    The contents of the group of the same number

    \d

    Any decimal digit

    \D

    Any non-decimal-digit character

    hashtag
    Functions

    Several functions are provided in Python to match regular expressions.

    hashtag
    match()

    Let us create a regular expression that matches "Mr." and "Ms.":

    • #1: imports the regular expression libraryarrow-up-right.

    • #3: compilesarrow-up-right the regular expression into the regex objectarrow-up-right RE_MR.

    • #4: the string "Dr. Choi" with RE_MR and saves the to m.

    circle-info

    A regular expression is represented by r'expression' where the expression is in a string preceded by the special character r.

    The above code prints None, indicating that the value of m is None, because the regular expression does not match the string.

    • #1: since RE_MR matches the string, m is a match object.

    • #3: true since m is a match object.

    • #4: prints the matched substring, and the (inclusive) and (exclusive) indices of the substring with respect to the original string in #1.

    Currently, no groupsarrow-up-right are specified in RE_MR:

    • #1: returns an empty tuple ().

    circle-exclamation

    What are the differences between a list and a tuple in Python?

    It is possible to grouparrow-up-right specific patterns using parentheses:

    • #1: there are two groups in this regular expression, (M[rs]) and (\.).

    • #3: returns a tuplearrow-up-right of matched substrings ('Ms', '.') for the two groups in #1.

    • #4,5: return the entire match "Ms.".

    • #6: returns "Ms" matched by the first group (M[rs]).

    • #7: returns "." matched by the second group (\.).

    The above RE_MR matches "Mr." and "Ms." but not "Mrs." Modify it to match all of them (Hint: use a non-capturing group and |).

    The non-capturing group (?:[rs]|rs) matches "r", "s", or "rs" such that the first group matches "Mr", "Ms", and "Mrs", respectively.

    Since we use the non-capturing group, the following code still prints a tuple of two strings:

    What if we use a capturing group instead?

    Now, the nested group ([rs]|rs) is considered the second group such that the match returns a tuple of three strings as follows:

    hashtag
    search()

    Let us match the following strings with RE_MR:

    • #4: matches "Mr." but not "Ms."

    • #5: matches neither "Mr." nor "Mrs."

    For s1, only "Mr." is matched because match() stops matching after finding the first pattern. For s2 on the other hand, even "Mr." is not matched because match() requires the pattern to be at the beginning of the string.

    To match a pattern anywhere in the string, we need to searcharrow-up-right for the pattern instead:

    • search() returns a match object as match() does.

    hashtag
    findall()

    search() still does not return the second substrings, "Ms." and "Mrs.". The following shows how to find allarrow-up-right substrings that match the pattern:

    • findall() returns a list of tuples where each tuple represents a group of matched results.

    hashtag
    finditer()

    Since findall() returns a list of tuples instead of match objects, there is no definite way of locating the matched results in the original string. To return match objects instead, we need to interactively findarrow-up-right the pattern:

    • #1: finditer() returns an iteratorarrow-up-right that keeps matching the pattern until it no longer finds.

    You can use a list comprehensionarrow-up-right to store the match objects as a list:

    • #1: returns a list of all m (in order) matched by finditer().

    circle-exclamation

    How is the code above different from the one below?

    What are the advantages of using a list comprehension over a for-loop other than it makes the code shorter?

    Write regular expressions to match the following cases:

    • Abbreviation: Dr., U.S.A.

    • Apostrophe: '80, '90s, 'cause

    • Concatenation: don't, gonna, cannot

    • Hyperlink: https://github.com/emory-courses/cs329/

    • Number: 1/2, 123-456-7890, 1,000,000

    • Unit: $10, #20, 5kg

    hashtag
    Natex Integration

    The nesting example in Section 3.1 has a condition as follows (#4):

    Write a regular expression that matches the above condition.

    It is possible to use regular expressions for matching in Natex. A regular expression is represented by forward slashes (/../):

    • #4: true if the entire input matches the regular expression.

    You can put the expression in a sequence to allow it a partial match:

    • #4: the regular expression is put in a sequence [].

    circle-info

    When used in Natex, all literals in the regular expression (e.g., "so", "good" in #4) must be lowercase because Natex matches everything in lowercase. The design choice is made because users tend not to follow typical capitalization in a chat interface, whether it is text- or audio-based.

    hashtag
    Variable

    It is possible to store the matched results of a regular expression to variables. A variable in a regular expression is represented by angle brackets (<..>) inside a capturing group ((?..)).

    The following transitions take the user name and respond with the stored first and last name:

    • #4: matches the first name and the last name in order and stores them in the variables FIRSTNAME and LASTNAME.

    • #5: uses FIRSTNAME and LASTNAME in the response.

    Chapter 2.1: Regular Expressionsarrow-up-right
    Regular Expression HOWTOarrow-up-right
    #3: directs to the music state.
  • #4: directs to the movie state.

  • The music and movie states can be defined in separate transition dictionaries:

    • #5: directs to the start state.

    • #8: directs to the movie state.

    • #5: directs to the start state.

    • #8: directs to the music state.

    Finally, all three transition dictionaries can be loaded to the same dialogue flow:

    Overview of the above transitions combining three transition dictionaries.

    When the dialogue flow runs, it randomly selects one of the 3 states, music, movie, and end:

    • #1: randomly selects the music state.

    • #3: switches to the movie state when it does not understand the user input.

    • #5: switches to the music state when it does not understand the user input.

    • #7: goes back to the start state when it understands the user input, and randomly selects the movie state.

    • #9: goes back to the start state when it understands the user input, and randomly selects the music state.

    • #11: goes back to the start state when it understands the user input, and randomly selects the end state.

    • #1: randomly selects the end state and terminates the dialogue.

    hashtag
    Gating

    The randomness in the above transitions can be quite annoying because it may end the dialogue immediately after it runs or repeats the same topic over and over. This can be alleviated by using the #GATE built-in macro:

    • #3: puts the music topic to an open gate.

    • #4: puts the movie topic to an open gate.

    • #4: has no gate to open (so it can be selected at any time).

    Once an output is selected, #GATE closes the door for that output such that it will never be selected again.

    circle-info

    It is important to have at least one output with no gate; otherwise, the system will crash unless one of the outputs leads to the end state.

    hashtag
    Scoring

    The gating prevents the system from repeating the same topic, but the end state can still be selected at any time without consuming all the other topics. To ensure that the end state gets selected last, we use scoring:

    • #6: indicates that this is the end state.

    • #7: assigns the score of this state to 0.1.

    By default, all states receive a score of 1; thus, assigning a score below 1 would make that state not selected at all unless there are dynamic scoring changes through macros such as #GATE.

  • #2-6: uses the ChatCompletitionarrow-up-right model to retrieve the GPT output.

  • #8-10: uses the regular expression (if provided) to extract the output in the specific format.

  • Let us create a macro that calls MacroGPTJSON:

    • #3: the task to be requested regarding the user input (e.g., How does the speaker want to be called?).

    • #4: the example output where all values are filled (e.g., {"call_names": ["Mike", "Michael"]}).

    • #5: the example output where all collections are empty (e.g., {"call_names": []}).

    • #6: the to check the information.

    • #7: it is a function that takes the STDM variable dictionary and the JSON output dictionary and sets necessary variables.

    Override the run method in MacroGPTJSON:

    • #2-3: creates a input prompt to the GPT API.

    • #4-5: retreives the GPT output using the prompt.

    • #7-11: checks if the output is in a proper JSON format.

    • #13-14: updates the variable table using the custom function.

    • #15-16: updates the variable table using the same keys as in the JSON output.

    Let us create another macro called MacroNLG:

    • #3: is a function that takes a variable table and returns a string output.

    Finally, we use the macros in a dialogue flow:

    The helper methods can be as follow:

    How does the speaker want to be called? Respond in the one-line JSON format such as {"call_names": ["Mike", "Michael"]}: My friends call me Pete, my students call me Dr. Parker, and my parents call me Peter. 
    OpenAI API key generator.
    circle-info

    Make sure to save this key in a local file. If you close the dialog without saving, you cannot retrieve the key again, in which case, you have to create a new one.

    Create a file openai_api.txt under the resourcesarrow-up-right directory and paste the API key to the file such that it contains only one line showing the key.

    Add openai_api.txt to the .gitignorearrow-up-right file:

    circle-info

    Do not share this key with anyone or push it to any remote repository (including your private GitHub repository).

    hashtag
    Using GPT API

    Open the terminal in PyCharm and install the OpenAI package:

    Create a function called api_key() as follow:

    • #4: specifies the path of the file containing the OpenAI API key.

    Retrieve a response by creating a ChatCompletitionarrow-up-right module:

    • #1: the GPT modelarrow-up-right to use.

    • #2: the content to be sent to the GPT model.

    • #3: creates the chat completion model and retrieves the response.

    • #5: messages are stored in a list of dictionaries where each dictionary contains content from either the user or the system.

    Print the type of the response and the response itself that is in the JSON format:

    • #1: the response type.

    • #2: the response in the JSON format.

    Print only the content from the output:

    OpenAIarrow-up-right
    OpenAI account menu.

    Communication is a fundamental part of human interaction, and studying it can help us better understand social dynamics and cultural norms.

  • It involves analyzing the structure of conversations, including turn-taking, topic initiation and maintenance, and repair strategies.

  • By examining these elements, researchers can gain insight into the social dynamics of a particular interaction and the underlying cultural norms that guide communication.

  • circle-info

    Can the study of Human-to-Human Conversational Analysis be applied to analyze Huaman-to-Machine conversations?

    How to conduct a conversational analysis?

    • Record and transcribe the conversation -> It allows you to analyze the conversation in detail and identify patterns in the interaction.

    • Identify the participants

      -> It helps you understand the social context of the conversation.

    • -> It helps you understand the patterns of communication between speakers.

    • -> It helps you understand how speakers introduce and develop discussion topics.

    • -> It helps you understand how speakers handle communication breakdowns and errors.

    • -> It helps you understand how cultural norms, values, and beliefs influence communication.

    hashtag
    Recording/Transcribing

    If your conversations are based on an audio or video interface, recording and transcribing them enables you to go back and analyze the conversation to gain a deeper understanding.

    There are several automatic transcribers available:

    Category
    OpenAI Whisper
    Microsoft Azure
    Rev AI

    Website

    Pricing

    Free

    $1 / hour

    $0.02 / minute

    Interface

    hashtag
    Identifying Participants

    When analyzing a conversation, it is important to consider the gender, age, social status, and other relevant characteristics of the speakers. These factors can influence communication and provide important context for understanding the conversation.

    • Diversity: Including a diverse range of participants can provide insights into how different groups communicate and interact. It can include age, gender, race, ethnicity, socioeconomic status, and cultural background.

    • Context: Conversations in different settings, such as workplaces or social gatherings, may involve different communication styles and norms.

    • Purpose: Conversations focused on a specific topic or goal may involve different communication strategies than casual conversations.

    • Power Dynamics: Conversations that involve power imbalances, such as a boss and an employee, may involve different communication patterns than conversations between peers.

    • Relationship: Conversations between strangers may involve different communication patterns than conversations between friends or family members.

    circle-info

    Identify ideal participants for testing your chatbot and discuss your strategy to gather such participants for the final project.

    hashtag
    Turn-taking

    Turn-taking refers to the way that speakers take turns participating in the interaction. It includes both the decision to speak and the transition between speakers. Turn-taking can reveal:

    • Power imbalances between speakers, with some individuals dominating the conversation and others having less opportunity to speak.

    • How speakers collaborate and negotiate with each other to move the conversation forward.

    Analysis aspects:

    • Message Length: The length of messages can indicate a speaker's intention to take a turn or signal that they have finished speaking.

    • Response Time: The time it takes for a speaker to respond to a message can indicate their intention to take a turn or signal that they are finished speaking.

    • Use of Markers: Speakers may use markers such as ellipses, dashes, or quotation marks to signal that they are taking a turn or indicate that they are listening to another speaker.

    • Emojis / Emoticons: The use of emojis or emoticons can indicate a speaker's attitude, emotion, or intention to take a turn.

    • Repetition: Speakers may repeat words or phrases to indicate their intention to take a turn or emphasize a point.

    circle-info

    What are your strategies to balance the lengths between the chatbot and the users? Can you use any of the above cues to improve the overall quality of the conversations?

    hashtag
    Topic Analysis

    Topic initiation refers to how speakers introduce a new topic of conversation, while topic maintenance refers to how they keep the conversation focused on that topic. Through this analysis, we:

    • Gain insights into the participants' interests, goals, and social context.

    • Understand how speakers collaborate to build shared understanding and mutual goals.

    • Learn effective communication techniques for keeping conversations focused and productive.

    Analysis aspects:

    • Topic Introduction: Speakers may introduce a new topic of discussion explicitly by using phrases such as "By the way," "Speaking of," or "Have you heard about". Such phrases indicate the speaker intends to change the topic or introduce something new.

    • Topic Development: Speakers may develop a topic by providing additional information or asking related questions. They may use open-ended, follow-up, or clarifying questions to maintain the topic.

    • Topic Shift: Speakers may shift the topic of discussion by changing the subject or introducing a new topic. Such shifts may be explicit or implicit and can be signaled by phrases such as "Anyway," "Moving on," or "So, as I was saying".

    • Topic Re-introduction: Speakers may re-introduce a topic discussed earlier by referring to it or bringing it up again. Such references can indicate that the speaker wants to continue discussing or bring attention to the topic.

    • Nonverbal Cues: Speakers may use punctuation or capitalization for emphasis or tone to indicate their intention to initiate or maintain a topic.

    circle-info

    Does your chatbot allow users to introduce or switch topics? How does your chatbot proceed when users intend to do so?

    hashtag
    Repair Strategies

    Repair strategies refer to techniques used by speakers to correct misunderstandings, clarify meaning, or resolve problems in communication. It allows us to:

    • Identify areas where communication breakdowns are more likely to occur, such as when speakers have different cultural backgrounds, use different languages, or have varying knowledge about the discussed topic.

    • Identify communication patterns that may be hindering effective communication. For example, a speaker consistently interrupts others or fails to listen actively can lead to more frequent communication breakdowns.

    Several aspects need to be analyzed to understand repair strategies:

    1. Self-repair: Speakers may self-correct errors or repair communication breakdowns in real time by repeating or rephrasing their previous statement.

    2. Other-repair: Speakers may ask their conversational partner to repeat or clarify what they said to repair communication breakdowns. They may also offer suggestions or provide information to help resolve the problem.

    3. Repair Initiation: Speakers may initiate repair by indicating a problem or error in communication, such as saying, "I didn't understand what you said," or "Can you repeat that?".

    4. Repair Resolution: Speakers may resolve the problem by clarifying, repeating, or rephrasing their previous statement or using other strategies to ensure successful communication.

    5. Lexical Choice: The words speakers choose to use can impact the success of the repair. They may use more straightforward language to clarify their message or help their conversational partner understand.

    circle-info

    Does your chatbot have any repair strategies? What are effective ways of catching them in STDM?

    hashtag
    Cultural Analysis

    Cultural context refers to the social norms, values, and beliefs that influence communication. They can vary between different cultures and can impact how people interact with each other:

    • In some cultures, interrupting someone may be seen as assertive and confident, while in others, it may be seen as rude or disrespectful.

    • Some cultures may place a high value on politeness and indirect communication, while others may value directness and assertiveness.

    Culture shapes how individuals perceive and interpret the world around them. By analyzing the cultural context, we can:

    • Gain insights into how communication is influenced by cultural factors such as social status, gender roles, power dynamics, and language proficiency.

    • Recognize and address potential biases or assumptions we may bring to the interaction.

    • Avoid misunderstandings and communicate more respectfully and effectively with people from different cultural backgrounds.

    Analysis aspects:

    1. Social Norms: Different cultures may have different social norms that dictate appropriate behavior in conversation, such as turn-taking, interruptions, and politeness strategies.

    2. Language Use: Language use may vary based on cultural context, including vocabulary, grammar, and pronunciation. For example, some languages may have different words or expressions for the same concept, or different cultures may have different levels of formality in their language use.

    3. Worldviews: Cultural differences can impact how people perceive and interpret events and actions. These differences can manifest in conversation through differences in humor, storytelling, and nonverbal communication.

    4. Values and Beliefs: Different cultures may have different values and beliefs, influencing how people communicate and what topics they discuss. For example, some cultures may prioritize directness and honesty, while others prioritize harmony and social relationships.

    5. Contextual Factors: Cultural context is also influenced by contextual factors such as the purpose of the conversation, the setting, and the relationship between speakers.

    GitHub: https://github.com/emory-courses/conversational-aiarrow-up-right
  • Time: MW 2:30PM - 3:45PM

  • Location: White Hall 112

  • hashtag
    Instructors

    • Jinho Choienvelope Associate Professor of Computer Science Office Hours → MW 4PM - 5:30PM, MSC W302F

    • Talyn Fanenvelope Research Engineer at the Emory NLP Research Lab Office Hours → TuTh 1PM - 2:30PM, MSC W302B (https://emory.zoom.us/j/94134466856arrow-up-right)

    • Benjamin Ascolienvelope Ph.D. student of Computer Science and Informatics Office Hours → MW 11:30AM - 1PM, MSC W302B

    • Ph.D. student of Computer Science and Informatics Office Hours → MW 1PM - 2:30PM, MSC W302B

    hashtag
    Grading

    • 1 + 7 topical quizzes: 55%

    • 3 LINC discussions: 10%

    • Project proposal: 15%

    • Final project: 20%

    • Your work is governed by the . Honor code violations (e.g., copies from any source, including colleagues and internet sites) will be referred to the .

    • Excuses for exam absence/rescheduling and other serious personal events (health, family, personal related, etc.) that affect course performance must be accompanied by a letter from the .

    hashtag
    Topical Quizzes

    • For every topic, one quiz will be assigned to check if you keep up with the materials.

    • Quizzes must be submitted individually. Discussions are allowed; however, your work must be original.

    • Late submissions within a week will be accepted with a grading penalty of 15% and will not be accepted once the solutions are discussed in class.

    hashtag
    LINC Discussions

    • You will meet with students from IDS 385W - Translation: Who, What, How three times:

      • 02/08 (W): evening (60 mins), 6PM, Atwood 215

      • 03/15 (W): evening (60 mins), 6PM, Atwood 215

      • 04/24 (M): evening (75 mins), 6PM, Atwood 215

    • For the first two meetings, you will meet in small groups. These meetings will not replace our regular class hours.

    • For the third meeting, you will present your chatbot to LINC students. This meeting will replace our regular class hours.

    hashtag
    Project Proposal

    • You are expected to:

      • Group a team of 3-4 members.

      • Give a presentation to propose your idea about the final project.

      • Write a proposal that illustrates details about your proposed project.

    • Everyone in each group will receive the same grade for the project proposal.

    • .

    hashtag
    Final Project

    • You are expected to:

      • Give a presentation about your final project.

      • Give a demonstration of your system.

      • Write a final report that illustrates details about your work.

    • Everyone in each group will receive the same grade for the final project.

    https://emory.gitbook.io/conversational-aiarrow-up-right
    defined in
    #7
    .

    MacroVisits can be defined as follow:

    • #10-13: uses the matcharrow-up-right statements to return the appropriate literal.

    The challenge is that we must save the number of visits to make this macro effective (and correct). This can be achieved by saving the variable dictionary into a binary file using the built-in Python object serialization called picklearrow-up-right:

    • #1: takes a dialogue flow df and a file path varfile for saving the variable dictionary to.

    • #3: creates a dictionary by copying only user-generated variables.

    • #4: a writable (w) and binary (b) file and dumps the dictionry object into the file.

    After running this code, you will see the visits.pkl file saved under the resources directory.

    hashtag
    Loading

    The following code shows how to load the saved dictionary to a new dialogue flow:

    • #1: takes a dialogue flow df and a file path varfile for loading the variable dictionary from.

    • #2: opens a readable (r) and binary (b) file and loads the object as a dictionary.

    • #3: adds all variables in the loaded dictioinary to the variable dictionary of df.

    • #5: saves the new variable dictionary to the same file.

    • Time: MW 10:00am - 11:15am

    • Location: Callaway S420

    • Instructor: Lisa Dillmanarrow-up-right

    hashtag
    First Meeting

    • Time: 6 - 7:15PM, 2/8(W)

    • Location: Atwood 215

    2/8/2023

    hashtag
    Second Meeting

    • Time: 6 - 7:15PM, 3/15(W)

    • Location: Atwood 215

    • Please watch the movie Babelarrow-up-right before coming to this meeting. You can watch it at Emory's Swank Streaming: linkarrow-up-right.

    from emora_stdm import DialogueFlow
    
    transitions = {
        'state': 'start',
        '`Hello. How are you?`': {
            '[{good, fantastic}]': {
                '`Glad to hear that you are doing well :)`': {
                    'error': {
                        '`See you later!`': 'end'
                    }
                }
            },
            'error': {
                '`I hope your day gets better soon :(`': {
                    'error': {
                        '`Take care!`': 'end'
                    }
                }
            }
        }
    }
    
    df = DialogueFlow('start', end_state='end')
    df.load_transitions(transitions)
    
    if __name__ == '__main__':
        df.run()
    S: Hello. How are you?
    U: I'm good
    S: Glad to hear that you are doing well :)
    U: Thanks
    S: See you later!
    ==========================================
    S: Hello. How are you?
    U: It's not going well
    S: I hope your day gets better soon :(
    U: Hopefully
    S: Take care!
    .idea/
    venv/
    <re.Match object; span=(0, 3), match='Mr.'>
    Mr. 0 3
    ('Ms', '.')
    Ms.
    Ms.
    Ms
    .
    RE_MR = re.compile(r'(M(?:[rs]|rs))(\.)')
    print(RE_MR.match('Mrs. Wayne').groups())
    --> ('Mrs', '.')
    <re.Match object; span=(0, 3), match='Mr.'>
    None
    <re.Match object; span=(0, 3), match='Mr.'>
    <re.Match object; span=(9, 12), match='Mr.'>
    [('Mr', '.'), ('Ms', '.')]
    [('Mr', '.'), ('Mrs', '.')]
    <re.Match object; span=(0, 3), match='Mr.'>
    <re.Match object; span=(8, 11), match='Ms.'>
    <re.Match object; span=(9, 12), match='Mr.'>
    <re.Match object; span=(17, 21), match='Mrs.'>
    [<re.Match object; span=(0, 3), match='Mr.'>, <re.Match object; span=(8, 11), match='Ms.'>]
    ms = []
    for m in RE_MR.finditer(s1):
        ms.append(m)
    r'((?:so|very) good|fantastic)'
    S: Hello. How are you?
    U: So good!!!
    S: Things are just getting better for you!
    S: Hello. How are you?
    U: Fantastic :)
    S: Things are just getting better for you!
    S: Hello. How are you?
    U: It's fantastic
    S: Sorry, I didn't understand you.
    S: Hello. How are you?
    U: It's fantastic!!
    S: Things are just getting better for you!
    S: Hello. How are you?
    U: I'm so good, thank you!
    S: Things are just getting better for you!
    S: Hello. What should I call you?
    U: Jinho Choi
    S: It's nice to meet you, jinho . I know several other choi .
    import re
    
    RE_MR = re.compile(r'M[rs]\.')
    m = RE_MR.match('Dr. Wayne')
    print(m)
    m = RE_MR.match('Mr. Wayne')
    print(m)
    if m:
        print(m.group(), m.start(), m.end())
    print(m.groups())
    RE_MR = re.compile(r'(M[rs])(\.)')
    m = RE_MR.match('Ms. Wayne')
    print(m.groups())
    print(m.group())
    print(m.group(0))
    print(m.group(1))
    print(m.group(2))
    s1 = 'Mr. and Ms. Wayne are here'
    s2 = 'Here are Mr. and Mrs. Wayne'
    
    print(RE_MR.match(s1))
    print(RE_MR.match(s2))
    print(RE_MR.search(s1))
    print(RE_MR.search(s2))
    print(RE_MR.findall(s1))
    print(RE_MR.findall(s2))
    for m in RE_MR.finditer(s1):
        print(m)
    for m in RE_MR.finditer(s2):
        print(m)
    ms = [m for m in RE_MR.finditer(s1)]
    print(ms)
    '{[{so, very} good], fantastic}'
    transitions = {
        'state': 'start',
        '`Hello. How are you?`': {
            '/((?:so|very) good|fantastic)/': {
                '`Things are just getting better for you!`': 'end'
            },
            'error': {
                '`Sorry, I didn\'t understand you.`': 'end'
            }
        }
    }
    transitions = {
        'state': 'start',
        '`Hello. How are you?`': {
            '[/((?:so|very) good|fantastic)/]': {
                '`Things are just getting better for you!`': 'end'
            },
            'error': {
                '`Sorry, I didn\'t understand you.`': 'end'
            }
        }
    }
    transitions = {
        'state': 'start',
        '`Hello. What should I call you?`': {
            '[/(?<FIRSTNAME>[a-z]+) (?<LASTNAME>[a-z]+)/]': {
                '`It\'s nice to meet you,` $FIRSTNAME `. I know several people with the last name,` $LASTNAME': 'end'
            },
            'error': {
                '`Sorry, I didn\'t understand you.`': 'end'
            }
        }
    }
    transitions_music = {
        'state': 'music',
        '`What is your favorite song?`': {
            '[[!{#LEM(rain), rainy}, #LEM(taco)]]': {
                '`I love children\'s songs by Parry Gripp.`': 'start',
            },
            'error': {
                '`Sorry, I don\'t know that song.`': 'movie'
            }
        }
    }
    transitions_movie = {
        'state': 'movie',
        '`What is your favorite movie?`': {
            '[{#LEM(avenger), iron man, hulk}]': {
                '`I love the Marvel Cinematic Universe.`': 'start',
            },
            'error': {
                '`Sorry, I don\'t know that movie.`': 'music'
            }
        }
    }
    S: Let's talk about music. What is your favorite song?
    U: Doremi Song
    S: Sorry, I don't know that song. What is your favorite movie?
    U: Superman
    S: Sorry, I don't know that movie. What is your favorite song?
    U: Raining Tacos
    S: I love children's songs by Parry Gripp. Let's talk about movies. What is your favorite movie?
    U: Iron man
    S: I love the Marvel Cinematic Universe. Let's talk about music. What is your favorite song?
    U: It's raining tacos
    S: I love children's songs by Parry Gripp. That\'s all I can talk about.
    S:  Let's talk about music. What is your favorite song?
    U: Raining Tacos
    S: I love children's songs by Parry Gripp.  Let's talk about movies. What is your favorite movie?
    U: Iron Man
    S: I love the Marvel Cinematic Universe. That's all I can talk about.
    transitions = {
        'state': 'start',
        '#GATE `Let\'s talk about music.`': 'music',
        '#GATE `Let\'s talk about movies.`': 'movie',
        '`That\'s all I can talk about.`': 'end',
    }
    transitions = {
        'state': 'start',
        '`Let\'s talk about music.`': 'music',
        '`Let\'s talk about movies.`': 'movie',
        '`That\'s all I can talk about.`': 'end'
    }
    df = DialogueFlow('start', end_state='end')
    df.load_transitions(transitions)
    df.load_transitions(transitions_music)
    df.load_transitions(transitions_movie)
    df.run()
    transitions = {
        'state': 'start',
        '#GATE `Let\'s talk about music.`': 'music',
        '#GATE `Let\'s talk about movies.`': 'movie',
        '`That\'s all I can talk about.`': 'end',
    }
    transitions = {
        'state': 'start',
        '#GATE `Let\'s talk about music.`': 'music',
        '#GATE `Let\'s talk about movies.`': 'movie',
        '`That\'s all I can talk about.`': {
            'state': 'end',
            'score': 0.1
        }
    }
    S: Hi, how should I call you?
    U: My friends call me Jin, but you can call me Jinho. Some students call me Dr. Choi as well.
    def gpt_completion(input: str, regex: Pattern = None) -> str:
        response = openai.ChatCompletion.create(
            model='gpt-3.5-turbo',
            messages=[{'role': 'user', 'content': input}]
        )
        output = response['choices'][0]['message']['content'].strip()
    
        if regex is not None:
            m = regex.search(output)
            output = m.group().strip() if m else None
    
        return output
    class MacroGPTJSON(Macro):
        def __init__(self, request: str, full_ex: Dict[str, Any], empty_ex: Dict[str, Any] = None, set_variables: Callable[[Dict[str, Any], Dict[str, Any]], None] = None):
            self.request = request
            self.full_ex = json.dumps(full_ex)
            self.empty_ex = '' if empty_ex is None else json.dumps(empty_ex)
            self.check = re.compile(regexutils.generate(full_ex))
            self.set_variables = set_variables
    def run(self, ngrams: Ngrams, vars: Dict[str, Any], args: List[Any]):
        examples = f'{self.full_ex} or {self.empty_ex} if unavailable' if self.empty_ex else self.full_ex
        prompt = f'{self.request} Respond in the JSON schema such as {examples}: {ngrams.raw_text().strip()}'
        output = gpt_completion(prompt)
        if not output: return False
    
        try:
            d = json.loads(output)
        except JSONDecodeError:
            print(f'Invalid: {output}')
            return False
    
        if self.set_variables:
            self.set_variables(vars, d)
        else:
            vars.update(d)
            
        return True
    class MacroNLG(Macro):
        def __init__(self, generate: Callable[[Dict[str, Any]], str]):
            self.generate = generate
    
        def run(self, ngrams: Ngrams, vars: Dict[str, Any], args: List[Any]):
            return self.generate(vars)
    transitions = {
        'state': 'start',
        '`Hi, how should I call you?`': {
            '#SET_CALL_NAMES': {
                '`Nice to meet you,` #GET_CALL_NAME `. Can you tell me where your office is and when your general office hours are?`': {
                    '#SET_OFFICE_LOCATION_HOURS': {
                        '`Can you confirm if the following office infos are correct?` #GET_OFFICE_LOCATION_HOURS': {
                        }
                    }
                }
            },
            'error': {
                '`Sorry, I didn\'t understand you.`': 'end'
            }
        }
    }
    
    macros = {
        'GET_CALL_NAME': MacroNLG(get_call_name),
        'GET_OFFICE_LOCATION_HOURS': MacroNLG(get_office_location_hours),
        'SET_CALL_NAMES': MacroGPTJSON(
            'How does the speaker want to be called?',
            {V.call_names.name: ["Mike", "Michael"]}),
        'SET_OFFICE_LOCATION_HOURS': MacroGPTJSON(
            'Where is the speaker\'s office and when are the office hours?',
            {V.office_location.name: "White Hall E305", V.office_hours.name: [{"day": "Monday", "begin": "14:00", "end": "15:00"}, {"day": "Friday", "begin": "11:00", "end": "12:30"}]},
            {V.office_location.name: "N/A", V.office_hours.name: []},
            set_office_location_hours
        ),
    }
    def get_call_name(vars: Dict[str, Any]):
        ls = vars[V.call_names.name]
        return ls[random.randrange(len(ls))]
    
    def get_office_location_hours(vars: Dict[str, Any]):
        return '\n- Location: {}\n- Hours: {}'.format(vars[V.office_location.name], vars[V.office_hours.name])
    
    def set_office_location_hours(vars: Dict[str, Any], user: Dict[str, Any]):
        vars[V.office_location.name] = user[V.office_location.name]
        vars[V.office_hours.name] = {d['day']: [d['begin'], d['end']] for d in user[V.office_hours.name]}
    <class 'openai.openai_object.OpenAIObject'>
    {
      "choices": [
        {
          "finish_reason": "stop",
          "index": 0,
          "message": {
            "content": "\n\n\"Believe in yourself and all that you are. Know that there is something inside you that is greater than any obstacle.\"",
            "role": "assistant"
          }
        }
      ],
      "created": 1678893623,
      "id": "chatcmpl-6uNDL6Qfh7MjxpLxH3NW7UPJXS3tN",
      "model": "gpt-3.5-turbo-0301",
      "object": "chat.completion",
      "usage": {
        "completion_tokens": 26,
        "prompt_tokens": 10,
        "total_tokens": 36
      }
    }
    "Believe in yourself and all that you are. Know that there is something inside you that is greater than any obstacle."
    .idea/
    venv/
    /resources/openai_api.txt
    (venv) $ pip install openai
    import openai
    
    PATH_API_KEY = 'resources/openai_api.txt'
    openai.api_key_path = PATH_API_KEY
    model = 'gpt-3.5-turbo'
    content = 'Say something inspiring'
    response = openai.ChatCompletion.create(
        model=model,
        messages=[{'role': 'user', 'content': content}]
    )
    output = response['choices'][0]['message']['content'].strip()
    print(output)
    S: It's your first visit!
    S: It's your second visit!
    S: It's your third visit!
    S: It's your 4th visit!
    def visits() -> DialogueFlow:
        transitions = {
            'state': 'start',
            '`It\'s your` #VISITS `visit!`': 'end'
        }
    
        macros = {
            'VISITS': MacroVisits()
        }
    
        df = DialogueFlow('start', end_state='end')
        df.load_transitions(transitions)
        df.add_macros(macros)
        return df
    class MacroVisits(Macro):
        def run(self, ngrams: Ngrams, vars: Dict[str, Any], args: List[Any]):
            vn = 'VISITS'
            if vn not in vars:
                vars[vn] = 1
                return 'first'
            else:
                count = vars[vn] + 1
                vars[vn] = count
                match count:
                    case 2: return 'second'
                    case 3: return 'third'
                    case default: return '{}th'.format(count)
    def save(df: DialogueFlow, varfile: str):
        df.run()
        d = {k: v for k, v in df.vars().items() if not k.startswith('_')}
        pickle.dump(d, open(varfile, 'wb'))
    
    save(visits(), 'resources/visits.pkl')
    def load(df: DialogueFlow, varfile: str):
        d = pickle.load(open(varfile, 'rb'))
        df.vars().update(d)
        df.run()
        save(df, varfile)
    Key-Value Retrieval Networks for Task-Oriented Dialoguearrow-up-right
    datasetarrow-up-right
    MultiWOZ - A Large-Scale Multi-Domain Wizard-of-Oz Dataset for Task-Oriented Dialogue Modellingarrow-up-right
    datasetarrow-up-right
    Entity-Consistent End-to-end Task-Oriented Dialogue System with KB Retrieverarrow-up-right
    datasetarrow-up-right
    Towards Scalable Multi-domain Conversational Agents: The Schema-Guided Dialogue Datasetarrow-up-right
    datasetarrow-up-right
    Google LaMDAarrow-up-right
    articlearrow-up-right
    interviewarrow-up-right
    Microsoft Azure Bot Servicearrow-up-right
    Emora STDM
    regular expressionarrow-up-right
    Sichang Tuenvelope
    Emory Honor Codearrow-up-right
    Emory Honor Councilarrow-up-right
    Office of Undergraduate Educationarrow-up-right
    Proposal Guidelines
    opensarrow-up-right

    Local Installation

    Azure Platform

    Web API

    Diarization

    No

    Yes

    Yes

    Pros

    Handles noisy environments well

    High accuracy

    East to use

    Cons

    Requires a local GPU machine

    Can be difficult to configure

    Pricier than Azure for less accuracy

    Analyze turn-taking
    Look for topic initiation and maintenance
    Analyze repair strategies
    Consider the cultural context
    Linkarrow-up-right
    Linkarrow-up-right
    Linkarrow-up-right

    ?

    0 or 1 repetitions

    ??

    {m}

    Exactly m repetitions

    {m,n}

    From m to n repetitions

    {m,n}?

    \s

    Any whitespace character

    \S

    Any non-whitespace character

    \w

    Any alphanumeric character and the underscore

    \W

    Any non-alphanumeric character

    matchesarrow-up-right
    match objectarrow-up-right
    startarrow-up-right
    endarrow-up-right
    RE_MR = re.compile(r'(M([rs]|rs))(\.)')
    print(RE_MR.match('Mrs. Wayne').groups())
    --> ('Mr', 'rs', '.')
    RE_TOK = re.compile(r'([",.]|n\'t|\s+)')
    RE_ABBR = re.compile(r'((?:Mr|Mrs|Ms|Dr)\.)|((?:[A-Z]\.){2,})')
    RE_APOS = re.compile(r'\'(\d\ds?|cause)')
    RE_CONC = re.compile(r'([A-Za-z]+)(n\'t)|(gon)(na)|(can)(not)')
    RE_HYPE = re.compile(r'(https?://\S+)')
    RE_NUMB = re.compile(r'(\d+/\d+)|(\d{3}-\d{3}-\d{4})|(\d(?:,\d{3})+)')
    RE_UNIT = re.compile(r'([$#])?(\d+)([km]g)?')
    S: That\'s all I can talk about.