Beispiel #1
0
 def __init__(self, domain: Domain = None, subgraph: dict = None, 
              logger : DiasysLogger =  DiasysLogger()):
     Module.__init__(self, domain, subgraph, logger = logger)
     self.initial_turn = True
     self.description = ''
     init_gui()
     self.dialogs = 0
Beispiel #2
0
 def __init__(self,
              domain: Domain = None,
              subgraph: dict = None,
              logger: DiasysLogger = DiasysLogger(),
              language: Language = None):
     Module.__init__(self, domain, subgraph,
                     logger=logger)  # independent of the domain
     self.language = language
Beispiel #3
0
    def __init__(self,
                 *modules,
                 domain=None,
                 logger: DiasysLogger = DiasysLogger()):
        self.domain = domain
        self.logger = logger
        self.modules = modules

        self.is_training = False
        self.num_dialogs = 0
        self.num_turns = 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
Beispiel #5
0
 def __init__(self, domain=None, subgraph: dict = None, 
              logger : DiasysLogger =  DiasysLogger()):
     Module.__init__(self, domain, subgraph, logger = logger)
     self.initial_turn = True
     init_gui()  # initialise the GUI
Beispiel #6
0
 def __init__(self, domain: Domain = None, subgraph: dict = None, 
              logger : DiasysLogger =  DiasysLogger()):
     Module.__init__(self, domain, subgraph, logger = logger)
     init_gui()
     self.dialogs = 0
Beispiel #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):

    """
        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()
Beispiel #8
0
 def __init__(self, domain, logger=DiasysLogger()):
     # only calls super class' constructor
     super(WeatherNLU, self).__init__(domain, debug_logger=logger)
Beispiel #9
0
class TurnDiff(object):
    def __init__(self, module_idx, module_name, diff_dict):
        self.module_idx = module_idx
        self.module_name = module_name
        self.diff_dict = diff_dict

    def to_dict(self):
        return {
            "index": self.module_idx,
            "name": self.module_name,
            "diff": self.diff_dict
        }
        

ACTIVE_LANGUAGE = Language.ENGLISH
logger = DiasysLogger()
# TODO make domain configurable via command line parameters
domain = JSONLookupDomain('ImsCourses')
nlu = HandcraftedNLU(domain=domain, logger=logger, language=ACTIVE_LANGUAGE)
bst = HandcraftedBST(domain=domain, logger=logger)
# policy = DQNPolicy(domain=domain, logger=self.logger)
policy = HandcraftedPolicy(domain=domain, logger=logger)
# policy.load()
policy.eval()
nlg = HandcraftedNLG(domain=domain, logger=logger, language=ACTIVE_LANGUAGE)


class DialogSystemWrapper(DialogSystem):
    SESSIONS = {}
    
    def __init__(self, uid):
Beispiel #10
0
        help=
        "maximum turns per dialog (dialogs with more turns will be terminated and counting as failed"
    )

    parser.add_argument("-eer",
                        "--evalerror",
                        type=float,
                        default=0.0,
                        help="simulation error rate while evaluating")

    args = parser.parse_args()

    # init random generator and logger
    common.init_random(args.randomseed)
    file_log_lvl = LogLevel.DIALOGS if args.logtofile else LogLevel.NONE
    logger = DiasysLogger(console_log_lvl=LogLevel.RESULTS,
                          file_log_lvl=file_log_lvl)

    # choose 'real' domain name from shorthand
    if args.domain == 'courses':
        domain_name = 'ImsCourses'
    elif args.domain == 'lecturers':
        domain_name = 'ImsLecturers'

    test_hdc_usersim(domain_name=domain_name,
                     logger=logger,
                     eval_epochs=args.epochs,
                     eval_dialogs=args.evaldialogs,
                     max_turns=args.maxturns,
                     test_error=args.evalerror,
                     use_tensorboard=args.logtensorboard)