コード例 #1
0
def load_superhero_domain():
    """ Try loading the restaurant domain shared by all following tests in this file. """
    domain = JSONLookupDomain('superhero')

    assert domain.db is not None
    assert domain.ontology_json is not None

    return domain
コード例 #2
0
ファイル: run_chat.py プロジェクト: wendywtchang/adviser
def test_domain(domain_name: str, policy_type: str, gui: bool, logger: DiasysLogger,
                language: Language):
    """ Start chat with system.

    Args:
        domain_name (str): name of domain (according to the names in resources/databases)
        policy_type (str): either hdc (handcrafted policy) or dqn (reinforcement learning policy)
        gui (bool): if true, will start a QT GUI session, otherwise the console will be used
                    for interaction
        logger (DiasysLogger): logger for all modules

    .. note::
    
        When using dqn, make sure you have a trained model. You can train a model for the specified
        domain by executing
        
        .. code:: bash
        
            python modules/policy/rl/train_dqnpolicy.py -d domain_name

    """

    # init domain
    domain = JSONLookupDomain(name=domain_name)

    # init modules
    nlu = HandcraftedNLU(domain=domain, logger=logger, language=language)
    bst = HandcraftedBST(domain=domain, logger=logger)

    if policy_type == 'hdc':
        policy = HandcraftedPolicy(domain=domain, logger=logger)
    else:
        policy = DQNPolicy(domain=domain, train_dialogs=1, logger=logger)
        policy.load()

    nlg = HandcraftedNLG(domain=domain, logger=logger, language=language)

    # interaction mode
    if gui:
        input_module = GuiInput(domain, logger=logger)
        output_module = GuiOutput(domain, logger=logger)
    else:
        input_module = ConsoleInput(domain, logger=logger, language=language)
        output_module = ConsoleOutput(domain, logger=logger)

    # construct dialog graph
    ds = DialogSystem(
        input_module,
        nlu,
        bst,
        policy,
        nlg,
        output_module,
        logger=logger)

    # start chat
    ds.eval()
    ds.run_dialog()
コード例 #3
0
ファイル: run_chat.py プロジェクト: wendywtchang/adviser
def test_multi(logger: DiasysLogger, language: Language):
    domain = JSONLookupDomain(
        'ImsLecturers',
        json_ontology_file=os.path.join('resources', 'databases', 'ImsLecturers-rules.json'),
        sqllite_db_file=os.path.join('resources', 'databases', 'ImsLecturers-dbase.db'))
    l_nlu = HandcraftedNLU(domain=domain, logger=logger, language=language)
    l_bst = HandcraftedBST(domain=domain, logger=logger)
    l_policy = HandcraftedPolicy(domain=domain, logger=logger)
    l_nlg = HandcraftedNLG(domain=domain, logger=logger, language=language)

    lecturers = DialogSystem(
                            l_nlu,
                            l_bst,
                            l_policy,
                            l_nlg,
                            domain=domain,
                            logger=logger
    )
    domain = JSONLookupDomain(
        'ImsCourses',
        json_ontology_file=os.path.join('resources', 'databases', 'ImsCourses-rules.json'),
        sqllite_db_file=os.path.join('resources', 'databases', 'ImsCourses-dbase.db'))
    c_nlu = HandcraftedNLU(domain=domain, logger=logger, language=language)
    c_bst = HandcraftedBST(domain=domain, logger=logger)
    c_policy = HandcraftedPolicy(domain=domain, logger=logger)
    c_nlg = HandcraftedNLG(domain=domain, logger=logger, language=language)

    courses = DialogSystem(
                        c_nlu,
                        c_bst,
                        c_policy,
                        c_nlg,
                        domain=domain,
                        logger=logger
    )

    multi = HandcraftedMetapolicy(
        subgraphs=[courses, lecturers],
        in_module=ConsoleInput(None, logger=logger, language=language),
        out_module=ConsoleOutput(None, logger=logger),
        logger=logger)
    multi.run_dialog()
コード例 #4
0
ファイル: run_chat.py プロジェクト: zerov4mp/adviser
def load_lecturers_domain(backchannel: bool = False):
    from utils.domain.jsonlookupdomain import JSONLookupDomain
    from services.nlu.nlu import HandcraftedNLU
    from services.nlg.nlg import HandcraftedNLG
    from services.policy import HandcraftedPolicy
    domain = JSONLookupDomain('ImsLecturers', display_name="Lecturers")
    lect_nlu = HandcraftedNLU(domain=domain)
    lect_bst = HandcraftedBST(domain=domain)
    lect_policy = HandcraftedPolicy(domain=domain)
    lect_nlg = load_nlg(backchannel=backchannel, domain=domain)
    return domain, [lect_nlu, lect_bst, lect_policy, lect_nlg]
コード例 #5
0
def test_setup_of_user_informables_lecturers():
    """
    
    Tests if user informable slots are recognized as such

    """
    domain = JSONLookupDomain('ImsLecturers')
    nlu = HandcraftedNLU(domain)

    for user_informable_slot in ['name', 'department', 'position']:
        assert user_informable_slot in nlu.USER_INFORMABLE
コード例 #6
0
def test_setup_of_user_requestables_lecturers():
    """

    Tests if user requestable slots are recognized as such

    """
    domain = JSONLookupDomain('ImsLecturers')
    nlu = HandcraftedNLU(domain)

    for user_requestable_slot in [
            'name', 'department', 'office_hours', 'mail', 'phone', 'room',
            'position'
    ]:
        assert user_requestable_slot in nlu.USER_REQUESTABLE
コード例 #7
0
def train(domain_name: str, log_to_file: bool, seed: int, train_epochs: int, train_dialogs: int,
          eval_dialogs: int, max_turns: int, train_error_rate: float, test_error_rate: float,
          lr: float, eps_start: float, grad_clipping: float, buffer_classname: str, 
          buffer_size: int, use_tensorboard: bool):

    common.init_random(seed=seed)

    file_log_lvl = LogLevel.DIALOGS if log_to_file else LogLevel.NONE
    logger = DiasysLogger(console_log_lvl=LogLevel.RESULTS, file_log_lvl=file_log_lvl)
    if buffer_classname == "prioritized":
        buffer_cls = NaivePrioritizedBuffer
    elif buffer_classname == "uniform":
        buffer_cls = UniformBuffer

    domain = JSONLookupDomain(name=domain_name)
    bst = HandcraftedBST(domain=domain, logger=logger)
    user = HandcraftedUserSimulator(domain, logger=logger)
    noise = SimpleNoise(domain=domain, train_error_rate=train_error_rate, 
                        test_error_rate=test_error_rate, logger=logger)
    policy = DQNPolicy(domain=domain, lr=lr, eps_start=eps_start, 
                        gradient_clipping=grad_clipping, buffer_cls=buffer_cls, 
                        replay_buffer_size=buffer_size, train_dialogs=train_dialogs,
                        logger=logger)
    evaluator = PolicyEvaluator(domain=domain, use_tensorboard=use_tensorboard, 
                                experiment_name=domain_name, logger=logger)
    ds = DialogSystem(policy,
                    user,
                    noise,
                    bst,
                    evaluator)

    for epoch in range(train_epochs):
        # train one epoch
        ds.train()
        evaluator.start_epoch()
        for episode in range(train_dialogs):
            ds.run_dialog(max_length=max_turns)
        evaluator.end_epoch()   # important for statistics!
        ds.num_dialogs = 0  # IMPORTANT for epsilon scheduler in dqnpolicy
        policy.save()       # save model

        # evaluate one epoch
        ds.eval()
        evaluator.start_epoch()
        for episode in range(eval_dialogs):
            ds.run_dialog(max_length=max_turns)
        evaluator.end_epoch()   # important for statistics!
        ds.num_dialogs = 0 # IMPORTANT for epsilon scheduler in dqnpolicy
コード例 #8
0
ファイル: courses_regexes_test.py プロジェクト: kdbz/adviser
def test_request_time_slot():
    """
	
	Tests exemplary whether a given synonym, i.e. a user utterance, is recognized as belonging to a certain slot

	"""
    domain = JSONLookupDomain('ImsCourses')
    nlu = HandcraftedNLU(domain)

    act_out = UserAct()
    act_out.type = UserActionType.Request
    act_out.slot = "time_slot"

    usr_utt = nlu.extract_user_acts(nlu, user_utterance='at what time')
    assert 'user_acts' in usr_utt
    assert usr_utt['user_acts'][0] == act_out
コード例 #9
0
def test_inform_lecturers_department():
    """

    Tests exemplary whether a given synonym, i.e. a user utterance, is recognized as belonging to a certain slot-value pair

    """
    domain = JSONLookupDomain('ImsLecturers')
    nlu = HandcraftedNLU(domain)

    act_out = UserAct()
    act_out.type = UserActionType.Inform
    act_out.slot = "department"
    act_out.value = "external"

    usr_utt = nlu.extract_user_acts(nlu, user_utterance='informatics')
    assert 'user_acts' in usr_utt
    assert usr_utt['user_acts'][0] == act_out
コード例 #10
0
def test_request_lecturers_office_hours():
    """
    
    Tests exemplary whether a given synonym, i.e. a user utterance, is recognized as belonging to a certain slot

    """
    domain = JSONLookupDomain('ImsLecturers')
    nlu = HandcraftedNLU(domain)

    act_out = UserAct()
    act_out.type = UserActionType.Request
    act_out.slot = "office_hours"

    usr_utt = nlu.extract_user_acts(
        nlu, user_utterance='when are the consultation hours')
    assert 'user_acts' in usr_utt
    assert usr_utt['user_acts'][0] == act_out
コード例 #11
0
def test_inform_lecturers_name():
    """
    
    Tests exemplary whether a given synonym, i.e. a user utterance, is recognized as belonging to a certain slot-value pair

    """
    domain = JSONLookupDomain('ImsLecturers')
    nlu = HandcraftedNLU(domain)

    act_out = UserAct()
    act_out.type = UserActionType.Inform
    act_out.slot = "name"
    act_out.value = "apl. prof. dr. agatha christie"

    usr_utt = nlu.extract_user_acts(nlu, user_utterance='agatha christie')
    assert 'user_acts' in usr_utt
    assert usr_utt['user_acts'][0] == act_out
コード例 #12
0
ファイル: courses_regexes_test.py プロジェクト: kdbz/adviser
def test_inform_courses_language():
    """
	
	Tests exemplary whether a given synonym, i.e. a user utterance, is recognized as belonging to a certain slot-value pair

	"""
    domain = JSONLookupDomain('ImsCourses')
    nlu = HandcraftedNLU(domain)

    act_out = UserAct()
    act_out.type = UserActionType.Inform
    act_out.slot = "lang"
    act_out.value = "de"

    usr_utt = nlu.extract_user_acts(nlu, user_utterance='german')
    assert 'user_acts' in usr_utt
    assert usr_utt['user_acts'][0] == act_out
コード例 #13
0
def test_request_lecturers_phone():
    """
    
    Tests exemplary whether a given synonym, i.e. a user utterance, is recognized as belonging to a certain slot

    """
    domain = JSONLookupDomain('ImsLecturers')
    nlu = HandcraftedNLU(domain)

    act_out = UserAct()
    act_out.type = UserActionType.Request
    act_out.slot = "phone"

    usr_utt = nlu.extract_user_acts(
        nlu, user_utterance='can you tell me the phone number')
    assert 'user_acts' in usr_utt
    assert usr_utt['user_acts'][0] == act_out
コード例 #14
0
ファイル: courses_regexes_test.py プロジェクト: kdbz/adviser
def test_setup_of_user_requestables_courses():
    """

    Tests if user requestable slots are recognized as such

    """
    domain = JSONLookupDomain('ImsCourses')
    nlu = HandcraftedNLU(domain)

    for user_requestable_slot in [
            'applied_nlp', 'bachelor', 'cognitive_science', 'course_type',
            'deep_learning', 'ects', 'elective', 'extendable', 'lecturer',
            'lang', 'linguistics', 'machine_learning', 'master', 'module_id',
            'module_name', 'name', 'obligatory_attendance', 'oral_exam',
            'participation_limit', 'presentation', 'programming', 'project',
            'report', 'semantics', 'speech', 'statistics', 'sws', 'syntax',
            'turn', 'written_exam'
    ]:
        assert user_requestable_slot in nlu.USER_REQUESTABLE
コード例 #15
0
ファイル: courses_regexes_test.py プロジェクト: kdbz/adviser
def test_multiple_user_acts_courses():
    """
    
    Tests exemplary whether a given sentence with multiple user acts is understood properly
    
    """
    domain = JSONLookupDomain('ImsCourses')
    nlu = HandcraftedNLU(domain)

    usr_utt = nlu.extract_user_acts(
        nlu,
        user_utterance='Hi, I want a course that is related to linguistics')
    assert 'user_acts' in usr_utt

    act_out = UserAct()
    act_out.type = UserActionType.Hello
    assert usr_utt['user_acts'][0] == act_out

    act_out = UserAct()
    act_out.type = UserActionType.Inform
    act_out.slot = "linguistics"
    act_out.value = "true"
    assert usr_utt['user_acts'][1] == act_out
コード例 #16
0
def test_multiple_user_acts_lecturers():
    """
    
    Tests exemplary whether a given sentence with multiple user acts is understood properly
    
    """
    domain = JSONLookupDomain('ImsLecturers')
    nlu = HandcraftedNLU(domain)

    usr_utt = nlu.extract_user_acts(
        nlu,
        user_utterance=
        'Hi, I want a lecturer who is responsible for gender issues')
    assert 'user_acts' in usr_utt

    act_out = UserAct()
    act_out.type = UserActionType.Hello
    assert usr_utt['user_acts'][0] == act_out

    act_out = UserAct()
    act_out.type = UserActionType.Inform
    act_out.slot = "position"
    act_out.value = "gender"
    assert usr_utt['user_acts'][1] == act_out
コード例 #17
0
def test_hdc_usersim(domain_name: str, logger: DiasysLogger, eval_epochs: int,
                     eval_dialogs: int, max_turns: int, test_error: float,
                     use_tensorboard: bool):

    domain = JSONLookupDomain(domain_name)
    bst = HandcraftedBST(domain=domain, logger=logger)
    user_simulator = HandcraftedUserSimulator(domain, logger=logger)
    noise = SimpleNoise(domain=domain,
                        train_error_rate=0.,
                        test_error_rate=test_error,
                        logger=logger)
    policy = HandcraftedPolicy(domain=domain, logger=logger)
    evaluator = PolicyEvaluator(domain=domain,
                                use_tensorboard=use_tensorboard,
                                experiment_name='hdc_eval',
                                logger=logger)
    ds = DialogSystem(policy, user_simulator, noise, bst, evaluator)
    ds.eval()

    for epoch in range(eval_epochs):
        evaluator.start_epoch()
        for episode in range(eval_dialogs):
            ds.run_dialog(max_length=max_turns)
        evaluator.end_epoch()
コード例 #18
0
    TRAIN_EPISODES = 1000
    NUM_TEST_SEEDS = 10
    EVAL_EPISODES = 500
    MAX_TURNS = -1
    TRAIN_EPOCHS = 10

    # get #num_test_seeds random seeds
    random_seeds = []
    for i in range(NUM_TEST_SEEDS):
        random_seeds.append(random.randint(0, 2**32-1))

    results = {}
    for seed in random_seeds:
        common.init_once = False
        common.init_random(seed=seed)    
        domain = JSONLookupDomain('ImsCourses')
        bst = HandcraftedBST(domain=domain)
        user_simulator = HandcraftedUserSimulator(domain=domain)
        policy = None

        policy= DQNPolicy(domain=domain)
        evaluator = PolicyEvaluator(domain=domain, use_tensorboard=True, 
                                experiment_name='eval_rl_imscourses' + str(seed))
        ds = DialogSystem(policy,
                        user_simulator,
                        bst,
                        evaluator
                            )
            
        for i in range(TRAIN_EPOCHS):
            ds.train()
コード例 #19
0
from services.ust.ust import HandcraftedUST
from services.nlg import HandcraftedNLG
from services.backchannel import AcousticBackchanneller
from services.nlg import BackchannelHandcraftedNLG
from services.nlg import HandcraftedEmotionNLG
from services.nlu import HandcraftedNLU
from services.policy import HandcraftedPolicy
from services.policy.affective_policy import EmotionPolicy
from services.service import DialogSystem
from utils.domain.jsonlookupdomain import JSONLookupDomain
from utils.logger import DiasysLogger, LogLevel
from services.simulator.emotion_simulator import EmotionSimulator
from utils.userstate import EmotionType

# load domains
lecturers = JSONLookupDomain(name='ImsLecturers', display_name="Lecturers")
weather = WeatherDomain()
mensa = MensaDomain()

# only debug logging
conversation_log_dir = "./conversation_logs"
os.makedirs(f"./{conversation_log_dir}/", exist_ok=True)
logger = DiasysLogger(file_log_lvl=LogLevel.NONE,
                      console_log_lvl=LogLevel.DIALOGS,
                      logfile_basename="full_log")

# input modules
user_in = ConsoleInput(conversation_log_dir=conversation_log_dir)
user_out = ConsoleOutput()
recorder = SpeechRecorder(conversation_log_dir=conversation_log_dir)
speech_in_decoder = SpeechInputDecoder(
コード例 #20
0
from modules.simulator import HandcraftedUserSimulator, SimpleNoise
from modules.policy import HandcraftedPolicy, DQNPolicy
from modules.policy.evaluation import PolicyEvaluator
from utils.domain.jsonlookupdomain import JSONLookupDomain
from utils import DiasysLogger, LogLevel

from utils import common

if __name__ == "__main__":
    logger = DiasysLogger(console_log_lvl=LogLevel.RESULTS,
                          file_log_lvl=LogLevel.DIALOGS)

    turns = {}
    success = {}
    for domain in [
            JSONLookupDomain(domain_str) for domain_str in ['ImsCourses']
    ]:
        turns[domain.name] = []
        success[domain.name] = []
        for i in range(5):
            common.init_random()  # add seed here if wanted

            TRAIN_EPOCHS = 10
            TRAIN_EPISODES = 1000
            EVAL_EPISODES = 1000
            MAX_TURNS = 25

            bst = HandcraftedBST(domain=domain, logger=logger)
            user = HandcraftedUserSimulator(domain, logger=logger)
            noise = SimpleNoise(domain=domain,
                                train_error_rate=0.30,
コード例 #21
0
def domain(domain_name):
    return JSONLookupDomain(domain_name)
コード例 #22
0
ファイル: train_dqnpolicy.py プロジェクト: kdbz/adviser
def train(domain_name: str, log_to_file: bool, seed: int, train_epochs: int, train_dialogs: int,
          eval_dialogs: int, max_turns: int, train_error_rate: float, test_error_rate: float,
          lr: float, eps_start: float, grad_clipping: float, buffer_classname: str,
          buffer_size: int, use_tensorboard: bool):

    """
        Training loop for the RL policy, for information on the parameters, look at the descriptions
        of commandline arguments in the "if main" below
    """
    seed = seed if seed != -1 else None
    common.init_random(seed=seed)

    file_log_lvl = LogLevel.DIALOGS if log_to_file else LogLevel.NONE
    logger = DiasysLogger(console_log_lvl=LogLevel.RESULTS, file_log_lvl=file_log_lvl)

    summary_writer = SummaryWriter(log_dir='logs') if use_tensorboard else None
    
    if buffer_classname == "prioritized":
        buffer_cls = NaivePrioritizedBuffer
    elif buffer_classname == "uniform":
        buffer_cls = UniformBuffer

    domain = JSONLookupDomain(name=domain_name)
    
    bst = HandcraftedBST(domain=domain, logger=logger)
    user = HandcraftedUserSimulator(domain, logger=logger)
    # noise = SimpleNoise(domain=domain, train_error_rate=train_error_rate,
    #                     test_error_rate=test_error_rate, logger=logger)
    policy = DQNPolicy(domain=domain, lr=lr, eps_start=eps_start,
                    gradient_clipping=grad_clipping, buffer_cls=buffer_cls,
                    replay_buffer_size=buffer_size, train_dialogs=train_dialogs,
                    logger=logger, summary_writer=summary_writer)
    evaluator = PolicyEvaluator(domain=domain, use_tensorboard=use_tensorboard,
                                experiment_name=domain_name, logger=logger,
                                summary_writer=summary_writer)
    ds = DialogSystem(services=[user, bst, policy, evaluator], protocol='tcp')
    # ds.draw_system_graph()

    error_free = ds.is_error_free_messaging_pipeline()
    if not error_free:
        ds.print_inconsistencies()

    for j in range(train_epochs):
        # START TRAIN EPOCH
        evaluator.train()
        policy.train()
        evaluator.start_epoch()
        for episode in range(train_dialogs):
            if episode % 100 == 0:
                print("DIALOG", episode)
            logger.dialog_turn("\n\n!!!!!!!!!!!!!!!! NEW DIALOG !!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\n")
            ds.run_dialog(start_signals={f'user_acts/{domain.get_domain_name()}': []})
        evaluator.end_epoch()
        policy.save()

        # START EVAL EPOCH
        evaluator.eval()
        policy.eval()
        evaluator.start_epoch()
        for episode in range(eval_dialogs):
            logger.dialog_turn("\n\n!!!!!!!!!!!!!!!! NEW DIALOG !!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\n")
            ds.run_dialog(start_signals={f'user_acts/{domain.get_domain_name()}': []})
        evaluator.end_epoch()
    ds.shutdown()
コード例 #23
0
ファイル: nlu.py プロジェクト: wendywtchang/adviser
        self._solve_informable_values()

        if len(self.user_acts) == 0 and self.prev_sys_act is not None:
            # start of dialogue or no regex matched
            self.user_acts.append(
                UserAct(text=user_utterance if user_utterance else "",
                        act_type=UserActionType.Bad))

        self._assign_scores()
        self.logger.dialog_turn("User Actions: %s" % str(self.user_acts))
        return {'user_acts': self.user_acts}


if __name__ == "__main__":
    domain = JSONLookupDomain(
        'ImsCourses',
        os.path.join('resources', 'databases', 'ImsCourses-rules.json'),
        os.path.join('resources', 'databases', 'ImsCourses-dbase.db'))
    nlu = HandcraftedNLU(domain=domain)
    print(
        nlu.forward(
            None, user_utterance='tell me everything about smt')['user_acts'])
    print(
        len(
            nlu.forward(
                None,
                user_utterance='tell me everything about smt')['user_acts']))
    print(nlu.forward(None, user_utterance='vu'))
    print(nlu.forward(None, user_utterance='his time'))
    print(
        nlu.forward(
            None, user_utterance='what courses does agnieska falenska teach'))
コード例 #24
0
    def _add_new_command(self):
        if self._current_block_level == 0:
            self._add_top_level_command()
        else:
            self._command_stack[-1].add_inner_command(self._current_command)
        self._command_stack.append(self._current_command)

    def _add_top_level_command(self):
        if isinstance(self._current_command, Rule):
            self._rules.append(self._current_command)
        elif isinstance(self._current_command, Function):
            self._functions.append(self._current_command)
        else:
            raise BaseException(
                'Only function or rule commands can be defined on top level!')


if __name__ == '__main__':
    domain = JSONLookupDomain(
        'ImsLecturers',
        os.path.join('resources', 'databases', 'ImsLecturers-rules.json'),
        os.path.join('resources', 'databases',
                     'ImsLecturersConfidential-dbase.db'))
    regex_file = RegexFile(
        '/home/mo/Job/ADvISER/diasys/adviser/resources/regexes/ImsLecturers.nlu',
        domain)

    # user_act = UserAct('', UserActionType.Inform, 'name', 'agnieska falenska')
    user_act = UserAct('', UserActionType.Hello)
    print(regex_file.create_regex(user_act))
コード例 #25
0
ファイル: nlumodules.py プロジェクト: wendywtchang/adviser
NLU_MODULES = {}


def get_module(domain: JSONLookupDomain, module_name: str):
    return NLU_MODULES[domain][module_name]


def update_modules():
    global NLU_MODULES
    NLU_MODULES = {
        DOMAIN_IMS_COURSES: {
            'Handcrafted NLU for courses at the IMS':
            HandcraftedNLU(DOMAIN_IMS_COURSES)
        },
        DOMAIN_IMS_LECTURERS: {
            'Handcrafted NLU for lecturers at the IMS':
            HandcraftedNLU(DOMAIN_IMS_LECTURERS)
        }
    }


if __name__ == "__main__":
    global DOMAIN_IMS_COURSES, DOMAIN_IMS_LECTURERS

    DOMAIN_IMS_COURSES = JSONLookupDomain("ImsCoursesConfidential")
    DOMAIN_IMS_LECTURERS = JSONLookupDomain("ImsLecturersConfidential")

    # Lists of possible NLU modules for each domain

    update_modules()
コード例 #26
0
                elif val == '**NONE**' or val == 'none':
                    del val_dict[key]
                elif key == '**NONE**' or key == 'none':
                    del val_dict[key]
                else:
                    # Fixes formatting issues for float in the beliefstate
                    if isinstance(val, float):
                        val_dict[key] = "{:1.1f}".format(val)
            elif isinstance(val, type(None)):
                del val_dict[key]


ACTIVE_LANGUAGE = Language.ENGLISH
logger = DiasysLogger()
# TODO make domain configurable via command line parameters
domain1 = JSONLookupDomain('ImsLecturers')
l_nlu = HandcraftedNLU(domain=domain1, logger=logger)
l_bst = HandcraftedBST(domain=domain1, logger=logger)
l_policy = HandcraftedPolicy(domain=domain1, logger=logger)
l_nlg = HandcraftedNLG(domain=domain1, logger=logger)
lecturers = MutliDomainDialogSystem(l_nlu,
                                    l_bst,
                                    l_policy,
                                    l_nlg,
                                    domain=domain1,
                                    logger=logger)
domain2 = JSONLookupDomain('ImsCourses')
c_nlu = HandcraftedNLU(domain=domain2, logger=logger)
c_bst = HandcraftedBST(domain=domain2, logger=logger)
c_policy = HandcraftedPolicy(domain=domain2, logger=logger)
c_nlg = HandcraftedNLG(domain=domain2, logger=logger)
コード例 #27
0
                                 slot=slot,
                                 value=value)
            inform_regex_json[slot][value] = template.create_regex(inform_act)
    return inform_regex_json


def create_json_from_template(domain: JSONLookupDomain,
                              template_filename: str):
    template = RegexFile(template_filename, domain)
    domain_name = domain.get_domain_name()
    _write_dict_to_file(_create_request_json(domain, template),
                        f'{domain_name}RequestRules.json')
    _write_dict_to_file(_create_inform_json(domain, template),
                        f'{domain_name}InformRules.json')


if __name__ == '__main__':
    # command line arguments
    parser = argparse.ArgumentParser()
    parser.add_argument("domain", help="name of the domain")
    parser.add_argument(
        "filename",
        help=
        "name of your .nlu file without the .nlu ending (e.g.: resources/nlu_regexes/YOURNLUFILE.nlu -> provide YOURFILE)"
    )
    args = parser.parse_args()
    nlu_file = os.path.join(head_location, 'resources', 'nlu_regexes',
                            f"{args.filename}.nlu")
    dom = JSONLookupDomain(args.domain)
    create_json_from_template(dom, nlu_file)
コード例 #28
0
from services.hci import ConsoleInput, ConsoleOutput
from services.nlu import HandcraftedNLU
from services.bst import HandcraftedBST
from services.policy import HandcraftedPolicy
from services.nlg import HandcraftedNLG
from services.domain_tracker import DomainTracker

from services.service import DialogSystem

from tensorboardX import SummaryWriter
from services.policy.rl.experience_buffer import NaivePrioritizedBuffer
from services.simulator import HandcraftedUserSimulator
from services.policy import DQNPolicy
from services.stats.evaluation import PolicyEvaluator

super_domain = JSONLookupDomain(name="ImsLecturers")

policy = HandcraftedPolicy(domain=super_domain)

# Allows you to track training progress using tensorboard
summary_writer = SummaryWriter(os.path.join('logs', "tutorial"))

# logs summary statistics for each train/test epoch
logger = DiasysLogger(console_log_lvl=LogLevel.RESULTS,
                      file_log_lvl=LogLevel.DIALOGS)
dialogue_logger = DiasysLogger(name='dialogue_logger',
                               console_log_lvl=LogLevel.ERRORS,
                               file_log_lvl=LogLevel.DIALOGS,
                               logfile_folder='dialogue_history',
                               logfile_basename='history')
コード例 #29
0
def _create_inform_json(domain: JSONLookupDomain, template: RegexFile):
    inform_regex_json = {}
    for slot in domain.get_informable_slots():
        inform_regex_json[slot] = {}
        for value in domain.get_possible_values(slot):
            inform_act = UserAct(act_type=UserActionType.Inform,
                                 slot=slot,
                                 value=value)
            inform_regex_json[slot][value] = template.create_regex(inform_act)
    return inform_regex_json


def create_json_from_template(domain: JSONLookupDomain,
                              template_filename: str):
    template = RegexFile(template_filename, domain)
    domain_name = domain.get_domain_name()
    _write_dict_to_file(_create_general_json(domain, template),
                        'GeneralRules.json')
    _write_dict_to_file(_create_request_json(domain, template),
                        f'{domain_name}RequestRules.json')
    _write_dict_to_file(_create_inform_json(domain, template),
                        f'{domain_name}InformRules.json')


if __name__ == '__main__':
    dom = JSONLookupDomain('ImsLecturers')
    create_json_from_template(
        dom,
        '/home/mo/Job/ADvISER/diasys/adviser/resources/regexes/ImsLecturers.nlu'
    )