(self)
计算每个词语的主题突出度，并保存在内存
计算每个词语的主题突出度，并保存在内存
计算每个词语的主题突出度，并保存在内存
def _topic_prominence(self):
        ''' 计算每个词语的主题突出度，并保存在内存 '''
        init_prob_distribution = np.array([self.topic_num for i in range(self.topic_num)])
        
        topic_prominence_dict = dict()
        for word in self.topic_word_weight:
            conditional_prob_list = list()
            for i in range(self.topic_num):
                if str(i) in self.topic_word_weight[word]:
                    conditional_prob_list.append(self.topic_word_weight[word][str(i)])
                else:
                    conditional_prob_list.append(1e-5)
            conditional_prob = np.array(conditional_prob_list)
            
            tmp_dot_log_res = np.log2(np.multiply(conditional_prob, init_prob_distribution))
            kl_div_sum = np.dot(conditional_prob, tmp_dot_log_res)  # kl divergence
            topic_prominence_dict.update({word: float(kl_div_sum)})
            
        tmp_list = [i[1] for i in tuple(topic_prominence_dict.items())]
        max_prominence = max(tmp_list)
        min_prominence = min(tmp_list)
        for k, v in topic_prominence_dict.items():
            topic_prominence_dict[k] = (v - min_prominence) / (max_prominence - min_prominence)
            
        self.topic_prominence_dict = topic_prominence_dict
        
        # 计算未知词汇的主题突出度，由于停用词已经预先过滤，所以这里不需要再考停用词无突出度
        tmp_prominence_list = [item[1] for item in self.topic_prominence_dict.items()]
        self.unk_topic_prominence_value = sum(tmp_prominence_list) / (2 * len(tmp_prominence_list))
def _topic_prominence ( self ) : init_prob_distribution = np . array ( [ self . topic_num for i in range ( self . topic_num ) ] ) topic_prominence_dict = dict ( ) for word in self . topic_word_weight : conditional_prob_list = list ( ) for i in range ( self . topic_num ) : if str ( i ) in self . topic_word_weight [ word ] : conditional_prob_list . append ( self . topic_word_weight [ word ] [ str ( i ) ] ) else : conditional_prob_list . append ( 1e-5 ) conditional_prob = np . array ( conditional_prob_list ) tmp_dot_log_res = np . log2 ( np . multiply ( conditional_prob , init_prob_distribution ) ) kl_div_sum = np . dot ( conditional_prob , tmp_dot_log_res ) # kl divergence topic_prominence_dict . update ( { word : float ( kl_div_sum ) } ) tmp_list = [ i [ 1 ] for i in tuple ( topic_prominence_dict . items ( ) ) ] max_prominence = max ( tmp_list ) min_prominence = min ( tmp_list ) for k , v in topic_prominence_dict . items ( ) : topic_prominence_dict [ k ] = ( v - min_prominence ) / ( max_prominence - min_prominence ) self . topic_prominence_dict = topic_prominence_dict # 计算未知词汇的主题突出度，由于停用词已经预先过滤，所以这里不需要再考停用词无突出度 tmp_prominence_list = [ item [ 1 ] for item in self . topic_prominence_dict . items ( ) ] self . unk_topic_prominence_value = sum ( tmp_prominence_list ) / ( 2 * len ( tmp_prominence_list ) )