def make_prediction( self, X_test, remove_all_o=True, min_conf=0.0): #not used when this is component classifier if self.iter < 1: return None latest_model_name = self.model_name + str(self.iter - 1) self.tagger.open(self.model_path + latest_model_name + '.crfsuite') y_preds = [] y_preds_mar_probs = [] for seq_idx, xseq in enumerate(X_test): y_pred_ori = self.tagger.tag(xseq) y_pred_mar_prob = [] for t, y in enumerate(y_pred_ori): y_pred_mar_prob.append(self.tagger.marginal(y, t)) if st.FIXED_MIN_SEQ_PROB == None: y_pred_post, _1, y_pred_mar_prob = utils.post_process_y( y_pred_ori, y_pred_mar_prob, remove_all_o, min_conf) else: seq_prob = self.tagger.probability(y_pred_ori) y_pred_post, _1, y_pred_mar_prob = utils.post_process_y( y_pred_ori, y_pred_mar_prob, remove_all_o, min_conf, seq_prob=seq_prob) y_preds.append(y_pred_post) y_preds_mar_probs.append(y_pred_mar_prob) self.tagger.close() return y_preds, y_preds_mar_probs
def _vote_predictions(self, component_preds, component_marginal_prob_dists, remove_all_o, min_conf): #need to be modified if st.VOTE_ON_DIST is True: vote_function = self._vote_on_dist else: vote_function = self._vote voted_preds = [] pred_scores = [] for seq_idx in range(len(component_preds[0])): voted_seq = [] score_seq = [] for bio_idx in range(len(component_preds[0][seq_idx])): pred_4_one = [ component_preds[cp_idx][seq_idx][bio_idx] for cp_idx in range(len(component_preds)) ] mar_prob_dist_4_one = None if st.VOTE_ON_DIST is True: mar_prob_dist_4_one = [ component_marginal_prob_dists[cp_idx][seq_idx][bio_idx] for cp_idx in range(len(component_preds)) ] result, score = vote_function(pred_4_one, mar_prob_dist_4_one) voted_seq.append(result) score_seq.append(score) if len(score_seq) != 0: voted_seq, _, score_seq = utils.post_process_y( voted_seq, score_seq, remove_all_o, min_conf) voted_preds.append(voted_seq) pred_scores.append(score_seq) return voted_preds, pred_scores
def make_prediction( self, X_test, remove_all_o=True, min_conf=0.0, link_pos=None): #not used when this is component classifier if self.iter < 1: return None latest_model_name = self.model_name + str(self.iter - 1) #print('open : '+latest_model_name) self.tagger.open(self.model_path + latest_model_name + '.crfsuite') y_preds = [] y_preds_mar_probs = [] for seq_idx, xseq in enumerate(X_test): y_pred_ori = self.tagger.tag(xseq) # ???????????? #if self.tagger.probability(y_pred_ori) < min_conf : # y_preds.append([]) # y_preds_mar_probs.append([]) # continue y_pred_mar_prob = [] for t, y in enumerate(y_pred_ori): y_pred_mar_prob.append(self.tagger.marginal(y, t)) if st.FIXED_MIN_SEQ_PROB == None: y_pred_post, _1, y_pred_mar_prob = utils.post_process_y( y_pred_ori, y_pred_mar_prob, remove_all_o, min_conf, None if link_pos == None else link_pos[seq_idx]) else: seq_prob = self.tagger.probability(y_pred_ori) y_pred_post, _1, y_pred_mar_prob = utils.post_process_y( y_pred_ori, y_pred_mar_prob, remove_all_o, min_conf, None if link_pos == None else link_pos[seq_idx], seq_prob=seq_prob) #y_pred_mar_prob = [] #if len(y_pred_post) >0 : # for t, y in enumerate(y_pred_ori) : # y_pred_mar_prob.append(self.tagger.marginal(y, t)) y_preds.append(y_pred_post) y_preds_mar_probs.append(y_pred_mar_prob) #y_pred = [self.tagger.tag(xseq) for xseq in X_test] self.tagger.close() #return y_pred return y_preds, y_preds_mar_probs
def _vote_predictions(self, component_preds, component_marginal_prob_dists, remove_all_o, min_conf, link_pos, replace_o, mul_ne_cnt): #need to be modified vote_function = self._vote_on_dist voted_preds = [] pred_scores = [] for seq_idx in range(len(component_preds[0])): voted_seq = [] score_seq = [] for bio_idx in range(len(component_preds[0][seq_idx])): pred_4_one = [ component_preds[cp_idx][seq_idx][bio_idx] for cp_idx in range(len(component_preds)) ] mar_prob_dist_4_one = [ component_marginal_prob_dists[cp_idx][seq_idx][bio_idx] for cp_idx in range(len(component_preds)) ] #for cp_idx in range(len(component_preds)): # pred_4_one.append(component_preds[cp_idx][seq_idx][bio_idx]) # mar_prob_4_one.append() result, score = vote_function(pred_4_one, mar_prob_dist_4_one) voted_seq.append(result) score_seq.append(score) if len(score_seq) != 0: voted_seq, _, score_seq = utils.post_process_y( voted_seq, score_seq, remove_all_o, min_conf, None if link_pos == None else link_pos[seq_idx], replace_o=replace_o, mul_ne_cnt=mul_ne_cnt) voted_preds.append(voted_seq) pred_scores.append(score_seq) return voted_preds, pred_scores