def __init__(self): import os #实体追踪 et = EntityTracker() #词袋 word2vec self.bow_enc = BoW_encoder() #加载word2vec embedding self.emb = UtteranceEmbed() #将实体追踪器添加到动作追踪器中 at = ActionTracker(et) #得到数据集和对话开始 结束行数 self.dataset, dialog_indices = Data(et, at).trainset #划分数据集:200对做训练 50对做测试 self.dialog_indices_tr = dialog_indices self.dialog_indices_dev = dialog_indices #obs_size 300维的词向量 + 85个袋中的词 + 4个槽位 obs_size = self.emb.dim + self.bow_enc.vocab_size + et.num_features #话术模板 self.action_templates = at.get_action_templates() #动作个数 action_size = at.action_size #隐藏层神经元个数 nb_hidden = 128 self.net = LSTM_net(obs_size=obs_size, action_size=action_size, nb_hidden=nb_hidden)
def __init__(self): et = EntityTracker() self.bow_enc = BoW_encoder() self.emb = UtteranceEmbed() at = ActionTracker(et) self.train_dataset, train_dialog_indices = Data(et, at).train_set self.test_dataset, test_dialog_indices = Data(et, at).test_set print('=========================\n') print('length of Train dialog indices : ', len(train_dialog_indices)) print('=========================\n') print('=========================\n') print('length of Test dialog indices : ', len(test_dialog_indices)) print('=========================\n') # Shuffle Training Dataset random.shuffle(train_dialog_indices) self.dialog_indices_tr = train_dialog_indices self.dialog_indices_dev = test_dialog_indices obs_size = self.emb.dim + self.bow_enc.vocab_size + et.num_features self.action_templates = at.get_action_templates() action_size = at.action_size # nb_hidden = 128 nb_hidden = 150 print('=========================\n') print('Action_templates: ', action_size) print('=========================\n') self.net = LSTM_net(obs_size=obs_size, action_size=action_size, nb_hidden=nb_hidden) self.et = et self.at = at action_projection = [] for action in self.action_templates: action_projection.append(self.emb.encode(action)) self.action_projection = np.transpose(action_projection) self.action_size = action_size
def __init__(self): et = EntityTracker() self.bow_enc = BoW_encoder() self.emb = UtteranceEmbed() at = ActionTracker(et) obs_size = self.emb.dim + self.bow_enc.vocab_size + et.num_features self.action_templates = at.get_action_templates() action_size = at.action_size nb_hidden = 128 self.net = LSTM_net(obs_size=obs_size, action_size=action_size, nb_hidden=nb_hidden) # restore checkpoint self.net.restore()
def __init__(self): et = EntityTracker() self.bow_enc = BoW_encoder() self.emb = UtteranceEmbed() at = ActionTracker(et) self.dataset, dialog_indices = Data(et, at).trainset self.dialog_indices_tr = dialog_indices[:200] self.dialog_indices_dev = dialog_indices[200:250] obs_size = self.emb.dim + self.bow_enc.vocab_size + et.num_features self.action_templates = at.get_action_templates() action_size = at.action_size nb_hidden = 128 self.net = LSTM_net(obs_size=obs_size, action_size=action_size, nb_hidden=nb_hidden)
def __init__(self): et = EntityTracker() self.bow_enc = BoW_encoder() self.emb = UtteranceEmbed() at = ActionTracker(et) ''' ['any preference on a type of cuisine', 'api_call <cuisine> <location> <party_size> <rest_type>', 'great let me do the reservation', 'hello what can i help you with today', 'here it is <info_address>', 'here it is <info_phone>', 'how many people would be in your party', "i'm on it", 'is there anything i can help you with', 'ok let me look into some options for you', 'sure is there anything else to update', 'sure let me find an other option for you', 'what do you think of this option: <restaurant>', 'where should it be', 'which price range are looking for', "you're welcome"] ''' self.dataset, dialog_indices = Data(et, at).trainset self.dialog_indices_tr = dialog_indices[:200] self.dialog_indices_dev = dialog_indices[200:250] obs_size = self.emb.dim + self.bow_enc.vocab_size + et.num_features self.action_templates = at.get_action_templates() action_size = at.action_size nb_hidden = 128 self.net = LSTM_net(obs_size=obs_size, action_size=action_size, nb_hidden=nb_hidden)
def __init__(self): et = EntityTracker() self.bow_enc = BoW_encoder() self.emb = UtteranceEmbed() at = ActionTracker(et) self.dataset, dialog_indices = Data(et, at).trainset train_indices = joblib.load('data/train_test_list/train_indices_759') test_indices = joblib.load('data/train_test_list/test_indices_759_949') self.dialog_indices_tr = train_indices self.dialog_indices_dev = test_indices obs_size = self.emb.dim + self.bow_enc.vocab_size + et.num_features self.action_templates = at.get_action_templates() action_size = at.action_size nb_hidden = 128 self.net = LSTM_net(obs_size=obs_size, action_size=action_size, nb_hidden=nb_hidden)
def __init__(self): # stor whole dialogues self.story = [] self.sp_confidecne = [] self.file_path = os.path.join( rospkg.RosPack().get_path('dialogue_system'), 'log', 'dialogue.txt') # count turn taking self.usr_count = 0 self.sys_count = 0 # paramaters self.network_type = rospy.get_param('~network_model', 'stacked_lstm') self.lang_type = rospy.get_param('~lang', 'eng') self.is_emb = rospy.get_param('~embedding', 'false') self.is_am = rospy.get_param('~action_mask', "true") self.user_num = rospy.get_param('~user_number', '0') # call rest of modules self.et = EntityTracker() self.at = ActionTracker(self.et) self.bow_enc = BoW_encoder() self.emb = UtteranceEmbed(lang=self.lang_type) # select observation size for RNN if self.is_am and self.is_emb: obs_size = self.emb.dim + self.bow_enc.vocab_size + self.et.num_features + self.at.action_size elif self.is_am and not (self.is_emb): obs_size = self.bow_enc.vocab_size + self.et.num_features + self.at.action_size elif not (self.is_am) and self.is_emb: obs_size = self.emb.dim + self.bow_enc.vocab_size + self.et.num_features elif not (self.is_am) and not (self.is_emb): obs_size = self.bow_enc.vocab_size + self.et.num_features self.action_template = self.at.get_action_templates() self.at.do_display_template() # must clear entities space self.et.do_clear_entities() action_size = self.at.action_size nb_hidden = 128 if self.network_type == 'gru': self.net = GRU(obs_size=obs_size, nb_hidden=nb_hidden, action_size=action_size, lang=self.lang_type, is_action_mask=self.is_am) elif self.network_type == 'reversed_lstm': self.net = ReversingLSTM(obs_size=obs_size, nb_hidden=nb_hidden, action_size=action_size, lang=self.lang_type, is_action_mask=self.is_am) elif self.network_type == 'reversed_gru': self.net = ReversingGRU(obs_size=obs_size, nb_hidden=nb_hidden, action_size=action_size, lang=self.lang_type, is_action_mask=self.is_am) elif self.network_type == 'stacked_gru': self.net = StackedGRU(obs_size=obs_size, nb_hidden=nb_hidden, action_size=action_size, lang=self.lang_type, is_action_mask=self.is_am) elif self.network_type == 'stacked_lstm': self.net = StackedLSTM(obs_size=obs_size, nb_hidden=nb_hidden, action_size=action_size, lang=self.lang_type, is_action_mask=self.is_am) elif self.network_type == 'lstm': self.net = LSTM(obs_size=obs_size, nb_hidden=nb_hidden, action_size=action_size, lang=self.lang_type, is_action_mask=self.is_am) elif self.network_type == 'bidirectional_lstm': self.net = BidirectionalLSTM(obs_size=obs_size, nb_hidden=nb_hidden, action_size=action_size, lang=self.lang_type, is_action_mask=self.is_am) elif self.network_type == 'bidirectional_gru': self.net = BidirectionalGRU(obs_size=obs_size, nb_hidden=nb_hidden, action_size=action_size, lang=self.lang_type, is_action_mask=self.is_am) # restore trained model self.net.restore() # rostopics self.pub_reply = rospy.Publisher('reply', Reply, queue_size=10) self.pub_complete = rospy.Publisher('complete_execute_scenario', Empty, queue_size=10) rospy.Subscriber('raising_events', RaisingEvents, self.handle_raise_events) try: rospy.wait_for_service('reception_db/query_data') self.get_response_db = rospy.ServiceProxy( 'reception_db/query_data', DBQuery) rospy.logwarn("waiting for reception DB module...") except rospy.exceptions.ROSInterruptException as e: rospy.logerr(e) quit() rospy.logwarn( "network: {}, lang: {}, action_mask: {}, embedding: {}, user_number: {}" .format(self.network_type, self.lang_type, self.is_am, self.is_emb, self.user_num)) self.story.append('user number: %s' % self.user_num) rospy.loginfo('\033[94m[%s]\033[0m initialized.' % rospy.get_name())
def __init__(self, args): self.response_accuracy = [] self.dialog_accuracy = [] try: ###################### selective import ############################# if args[0] == 'am': self.is_action_mask = True else: self.is_action_mask = False if args[1] == 'emb': self.is_emb = True else: self.is_emb = False self.network_type = args[2] self.lang_type = args[3] if self.lang_type == 'eng': from modules.entities import EntityTracker from modules.data_utils import Data from modules.actions import ActionTracker from modules.bow import BoW_encoder elif self.lang_type == 'kor': from modules.entities_kor import EntityTracker from modules.data_utils_kor import Data from modules.actions_kor import ActionTracker from modules.bow_kor import BoW_encoder ################################################################### except: rospy.logwarn( "please try again. i.e. ... train.py <am> <emb> <bidirectional_lstm> <eng>" ) if self.is_emb: if self.lang_type == 'eng': self.emb = UtteranceEmbed(lang=self.lang_type) elif self.lang_type == 'kor': self.emb = UtteranceEmbed(lang=self.lang_type) et = EntityTracker() self.bow_enc = BoW_encoder() at = ActionTracker(et) at.do_display_template() self.dataset, dialog_indices = Data(et, at).trainset # self.dialog_indices_tr = dialog_indices[:200] self.dialog_indices_tr = random.sample(dialog_indices, 200) # self.dialog_indices_dev = dialog_indices[200:250] self.dialog_indices_dev = random.sample(dialog_indices, 50) self.action_templates = at.get_action_templates() action_size = at.action_size nb_hidden = 128 # set feature input if self.is_action_mask and self.is_emb: obs_size = self.emb.dim + self.bow_enc.vocab_size + et.num_features + at.action_size elif self.is_action_mask and not (self.is_emb): obs_size = self.bow_enc.vocab_size + et.num_features + at.action_size elif not (self.is_action_mask) and self.is_emb: obs_size = self.emb.dim + self.bow_enc.vocab_size + et.num_features elif not (self.is_action_mask) and not (self.is_emb): obs_size = self.bow_enc.vocab_size + et.num_features # set network_type type if self.network_type == 'gru': self.net = GRU(obs_size=obs_size, nb_hidden=nb_hidden, action_size=action_size, lang=self.lang_type, is_action_mask=self.is_action_mask) elif self.network_type == 'reversed_lstm': self.net = ReversingLSTM(obs_size=obs_size, nb_hidden=nb_hidden, action_size=action_size, lang=self.lang_type, is_action_mask=self.is_action_mask) elif self.network_type == 'reversed_gru': self.net = ReversingGRU(obs_size=obs_size, nb_hidden=nb_hidden, action_size=action_size, lang=self.lang_type, is_action_mask=self.is_action_mask) elif self.network_type == 'stacked_gru': self.net = StackedGRU(obs_size=obs_size, nb_hidden=nb_hidden, action_size=action_size, lang=self.lang_type, is_action_mask=self.is_action_mask) elif self.network_type == 'stacked_lstm': self.net = StackedLSTM(obs_size=obs_size, nb_hidden=nb_hidden, action_size=action_size, lang=self.lang_type, is_action_mask=self.is_action_mask) elif self.network_type == 'lstm': self.net = LSTM(obs_size=obs_size, nb_hidden=nb_hidden, action_size=action_size, lang=self.lang_type, is_action_mask=self.is_action_mask) elif self.network_type == 'bidirectional_lstm': self.net = BidirectionalLSTM(obs_size=obs_size, nb_hidden=nb_hidden, action_size=action_size, lang=self.lang_type, is_action_mask=self.is_action_mask) elif self.network_type == 'bidirectional_gru': self.net = BidirectionalGRU(obs_size=obs_size, nb_hidden=nb_hidden, action_size=action_size, lang=self.lang_type, is_action_mask=self.is_action_mask) file_path = os.path.join(rospkg.RosPack().get_path('dialogue_system'), 'log', self.network_type) # init logging self.logger = self.get_logger(file_path) msg = "'\033[94m[%s trainer]\033[0m initialized - %s (action_mask: %s, embedding: %s, lang: %s, obs_size: %s, bow: %s, context_feature: %s, action_size: %s)" % ( rospy.get_name(), self.net.__class__.__name__, self.is_action_mask, self.is_emb, self.lang_type, obs_size, self.bow_enc.vocab_size, et.num_features, action_size) rospy.loginfo(msg)