def run(parameter): """ The entry function of this code. Args: parameter: the super-parameter """ print(json.dumps(parameter, indent=2)) time.sleep(2) slot_set = pickle.load(file=open(parameter["slot_set"], "rb")) action_set = pickle.load(file=open(parameter["action_set"], "rb")) disease_symptom = pickle.load(file=open(parameter["disease_symptom"], "rb")) steward = RunningSteward(parameter=parameter,checkpoint_path=parameter["checkpoint_path"]) print('action_set', action_set) warm_start = parameter.get("warm_start") warm_start_epoch_number = parameter.get("warm_start_epoch_number") train_mode = parameter.get("train_mode") agent_id = parameter.get("agent_id") simulate_epoch_number = parameter.get("simulate_epoch_number") # Warm start. if warm_start == True and train_mode == True: print("warm starting...") agent = AgentRule(action_set=action_set,slot_set=slot_set,disease_symptom=disease_symptom,parameter=parameter) steward.dialogue_manager.set_agent(agent=agent) steward.warm_start(epoch_number=warm_start_epoch_number) # exit() if agent_id.lower() == 'agentdqn': agent = AgentDQN(action_set=action_set,slot_set=slot_set,disease_symptom=disease_symptom,parameter=parameter) elif agent_id.lower() == 'agentrandom': agent = AgentRandom(action_set=action_set,slot_set=slot_set,disease_symptom=disease_symptom,parameter=parameter) elif agent_id.lower() == 'agentrule': agent = AgentRule(action_set=action_set,slot_set=slot_set,disease_symptom=disease_symptom,parameter=parameter) elif agent_id.lower() == 'agenthrl': agent = AgentHRL(action_set=action_set, slot_set=slot_set, disease_symptom=disease_symptom, parameter=parameter) elif agent_id.lower() == 'agentwithgoaljoint': agent = AgentWithGoalJoint(action_set=action_set, slot_set=slot_set, disease_symptom=disease_symptom, parameter=parameter) elif agent_id.lower() == 'agentwithgoal': agent = AgentWithGoal(action_set=action_set, slot_set=slot_set, disease_symptom=disease_symptom, parameter=parameter) elif agent_id.lower() == 'agentwithgoal2': agent = AgentWithGoal2(action_set=action_set, slot_set=slot_set, disease_symptom=disease_symptom, parameter=parameter) elif agent_id.lower() == 'agentwithgoal3': from src.dialogue_system.agent.agent_with_goal_3 import AgentWithGoal as AgentWithGoal3 agent = AgentWithGoal3(action_set=action_set, slot_set=slot_set, disease_symptom=disease_symptom, parameter=parameter) else: raise ValueError('Agent id should be one of [AgentRule, AgentDQN, AgentRandom, AgentHRL, AgentWithGoal, AgentWithGoal2, AgentWithGoalJoint].') steward.dialogue_manager.set_agent(agent=agent) if train_mode is True: # Train steward.simulate(epoch_number=simulate_epoch_number, train_mode=train_mode) else: # test for index in range(simulate_epoch_number): res = steward.evaluate_model(dataset='test', index=index) return res
def __init__(self, parameter, checkpoint_path): self.epoch_size = parameter.get("simulation_size", 100) self.parameter = parameter self.checkpoint_path = checkpoint_path self.learning_curve = {} slot_set = pickle.load(file=open(parameter["slot_set"], "rb")) action_set = pickle.load(file=open(parameter["action_set"], "rb")) goal_set = pickle.load(file=open(parameter["goal_set"], "rb")) disease_symptom = pickle.load( file=open(parameter["disease_symptom"], "rb")) user = User(goal_set=goal_set, disease_syptom=disease_symptom, parameter=parameter) agent = AgentRule(action_set=action_set, slot_set=slot_set, disease_symptom=disease_symptom, parameter=parameter) self.dialogue_manager = DialogueManager(user=user, agent=agent, parameter=parameter) self.best_result = { "success_rate": 0.0, "average_reward": 0.0, "average_turn": 0, "average_wrong_disease": 10 }
def run(): slot_set = pickle.load(file=open(parameter["slot_set"], "rb")) action_set = pickle.load(file=open(parameter["action_set"], "rb")) disease_symptom = pickle.load( file=open(parameter["disease_symptom"], "rb")) steward = RunningSteward(parameter=parameter, checkpoint_path=checkpoint_path) warm_start = parameter.get("warm_start") warm_start_epoch_number = parameter.get("warm_start_epoch_number") train_mode = parameter.get("train_mode") agent_id = parameter.get("agent_id") simulate_epoch_number = parameter.get("simulate_epoch_number") # Warm start. if warm_start == 1 and train_mode == 1: print("warm starting...") agent = AgentRule(action_set=action_set, slot_set=slot_set, disease_symptom=disease_symptom, parameter=parameter) steward.warm_start(agent=agent, epoch_number=warm_start_epoch_number) # exit() if agent_id == 1: agent = AgentDQN(action_set=action_set, slot_set=slot_set, disease_symptom=disease_symptom, parameter=parameter) elif agent_id == 2: agent = AgentActorCritic(action_set=action_set, slot_set=slot_set, disease_symptom=disease_symptom, parameter=parameter) elif agent_id == 3: agent = AgentRandom(action_set=action_set, slot_set=slot_set, disease_symptom=disease_symptom, parameter=parameter) elif agent_id == 0: agent = AgentRule(action_set=action_set, slot_set=slot_set, disease_symptom=disease_symptom, parameter=parameter) steward.simulate(agent=agent, epoch_number=simulate_epoch_number, train_mode=train_mode)
def __init__(self, parameter, checkpoint_path): self.epoch_size = parameter.get("simulation_size", 100) self.parameter = parameter self.checkpoint_path = checkpoint_path self.learning_curve = {} slot_set = pickle.load(file=open(parameter["slot_set"], "rb")) action_set = pickle.load(file=open(parameter["action_set"], "rb")) goal_set = pickle.load(file=open(parameter["goal_set"], "rb")) disease_symptom = pickle.load( file=open(parameter["disease_symptom"], "rb")) user = User(goal_set=goal_set, disease_syptom=disease_symptom, parameter=parameter) agent = AgentRule(action_set=action_set, slot_set=slot_set, disease_symptom=disease_symptom, parameter=parameter) if parameter.get("use_all_labels"): self.dialogue_manager = DialogueManager_HRL(user=user, agent=agent, parameter=parameter) else: self.dialogue_manager = DialogueManager(user=user, agent=agent, parameter=parameter) if self.parameter.get("disease_as_action") == False: if self.parameter.get("classifier_type") == "machine_learning": self.dialogue_manager.train_ml_classifier() print( "############ the machine learning model is training ###########" ) elif self.parameter.get("classifier_type") == "deep_learning": self.dialogue_manager.build_deep_learning_classifier() else: raise ValueError( "the classifier type is not among machine_learning and deep_learning" ) self.best_result = { "success_rate": 0.0, "average_reward": 0.0, "average_turn": 0, "average_wrong_disease": 10 }
def run(parameter): """ The entry function of this code. Args: parameter: the super-parameter """ agent_id = parameter.get("agent_id") dqn_id = parameter.get("dqn_id") disease_number = parameter.get("disease_number") max_turn = parameter.get("max_turn") if agent_id == 1: checkpoint_path = "./../model/dqn/checkpoint/checkpoint_d" + str( disease_number) + "_" + str(agent_id) + "_dqn" + str( dqn_id) + "_T" + str(max_turn) + "/" else: checkpoint_path = "./../model/dqn/checkpoint/checkpoint_d" + str( disease_number) + "_" + str(agent_id) + "_T" + str(max_turn) + "/" print(json.dumps(parameter, indent=2)) time.sleep(1) slot_set = pickle.load(file=open(parameter["slot_set"], "rb")) action_set = pickle.load(file=open(parameter["action_set"], "rb")) disease_symptom = pickle.load( file=open(parameter["disease_symptom"], "rb")) steward = RunningSteward(parameter=parameter, checkpoint_path=checkpoint_path) warm_start = parameter.get("warm_start") warm_start_epoch_number = parameter.get("warm_start_epoch_number") train_mode = parameter.get("train_mode") agent_id = parameter.get("agent_id") simulate_epoch_number = parameter.get("simulate_epoch_number") # Warm start. if warm_start == True and train_mode == True: print("warm starting...") agent = AgentRule(action_set=action_set, slot_set=slot_set, disease_symptom=disease_symptom, parameter=parameter) steward.warm_start(agent=agent, epoch_number=warm_start_epoch_number) # exit() if agent_id.lower() == 'agentdqn': agent = AgentDQN(action_set=action_set, slot_set=slot_set, disease_symptom=disease_symptom, parameter=parameter) elif agent_id.lower() == 'agentactorcritic': agent = AgentActorCritic(action_set=action_set, slot_set=slot_set, disease_symptom=disease_symptom, parameter=parameter) elif agent_id.lower() == 'agentrandom': agent = AgentRandom(action_set=action_set, slot_set=slot_set, disease_symptom=disease_symptom, parameter=parameter) elif agent_id.lower() == 'agentrule': agent = AgentRule(action_set=action_set, slot_set=slot_set, disease_symptom=disease_symptom, parameter=parameter) else: raise ValueError( 'Agent id should be one of [AgentRule, AgentDQN, AgentActorCritic, AgentRandom].' ) steward.simulate(agent=agent, epoch_number=simulate_epoch_number, train_mode=train_mode)
def run(parameter, main_checkpoint_path): agent_id = parameter.get("agent_id") dqn_id = parameter.get("dqn_id") disease_number = parameter.get("disease_number") lr = parameter.get("dqn_learning_rate") reward_for_success = parameter.get("reward_for_success") reward_for_fail = parameter.get("reward_for_fail") reward_for_not_come_yet = parameter.get("reward_for_not_come_yet") reward_for_inform_right_symptom = parameter.get("reward_for_inform_right_symptom") max_turn = parameter.get("max_turn") minus_left_slots = parameter.get("minus_left_slots") gamma = parameter.get("gamma") epsilon = parameter.get("epsilon") run_id = parameter.get('run_id') if agent_id == 1: checkpoint_path = main_checkpoint_path + "checkpoint_d" + str(disease_number) + "_agt" + str(agent_id) + \ "_dqn" + str(dqn_id) + "_T" + str(max_turn) + "_lr" + str(lr) + "_RFS" + str(reward_for_success) +\ "_RFF" + str(reward_for_fail) + "_RFNCY" + str(reward_for_not_come_yet) + "_RFIRS" + str(reward_for_inform_right_symptom) +\ "_mls" + str(minus_left_slots) + "_gamma" + str(gamma) + "_epsilon" + str(epsilon) + "_RID" + str(run_id) + "/" else: checkpoint_path = main_checkpoint_path + "checkpoint_d" + str(disease_number) + "_agt" + str(agent_id) + \ "_T" + str(max_turn) + "_lr" + str(lr) + "_RFS" + str(reward_for_success) + \ "_RFF" + str(reward_for_fail) + "_RFNCY" + str(reward_for_not_come_yet) + "_RFIRS" + str(reward_for_inform_right_symptom) + \ "_mls" + str(minus_left_slots) + "_gamma" + str(gamma) + "_epsilon" + str(epsilon) + "_RID" + str(run_id) + "/" print(json.dumps(parameter, indent=2)) time.sleep(8) slot_set = pickle.load(file=open(parameter["slot_set"], "rb")) action_set = pickle.load(file=open(parameter["action_set"], "rb")) disease_symptom = pickle.load(file=open(parameter["disease_symptom"], "rb")) steward = RunningSteward(parameter=parameter, checkpoint_path=checkpoint_path) warm_start = parameter.get("warm_start") warm_start_epoch_number = parameter.get("warm_start_epoch_number") train_mode = parameter.get("train_mode") agent_id = parameter.get("agent_id") simulate_epoch_number = parameter.get("simulate_epoch_number") # Warm start. if warm_start == 1 and train_mode == 1: print("warm starting...") agent = AgentRule(action_set=action_set, slot_set=slot_set, disease_symptom=disease_symptom, parameter=parameter) steward.warm_start(agent=agent, epoch_number=warm_start_epoch_number) # exit() if agent_id == 1: agent = AgentDQN(action_set=action_set, slot_set=slot_set, disease_symptom=disease_symptom, parameter=parameter) elif agent_id == 2: agent = AgentActorCritic(action_set=action_set, slot_set=slot_set, disease_symptom=disease_symptom, parameter=parameter) elif agent_id == 3: agent = AgentRandom(action_set=action_set, slot_set=slot_set, disease_symptom=disease_symptom, parameter=parameter) elif agent_id == 0: agent = AgentRule(action_set=action_set, slot_set=slot_set, disease_symptom=disease_symptom, parameter=parameter) steward.simulate(agent=agent, epoch_number=simulate_epoch_number, train_mode=train_mode)