(input_file,ner_pred_file,match_file,match_pred,out_file)
根据NER模型以及Match模型的预测结果，进行融合，得到实体识别阶段的最终结果
    :param input_file: 原始文件
    :param ner_pred_file: NER预测文件
    :param match_file: Match输入文件,这个里面有匹配的实体，下面有对应的概率
    :param match_pred: Match预测文件
    :param out_file:
    :return:
根据NER模型以及Match模型的预测结果，进行融合，得到实体识别阶段的最终结果
    :param input_file: 原始文件
    :param ner_pred_file: NER预测文件
    :param match_file: Match输入文件,这个里面有匹配的实体，下面有对应的概率
    :param match_pred: Match预测文件
    :param out_file:
    :return:
根据NER模型以及Match模型的预测结果，进行融合，得到实体识别阶段的最终结果 : param input_file : 原始文件 : param ner_pred_file : NER预测文件 : param match_file : Match输入文件 这个里面有匹配的实体，下面有对应的概率 : param match_pred : Match预测文件 : param out_file : : return :
def get_result(input_file,ner_pred_file,match_file,match_pred,out_file):
    '''
    根据NER模型以及Match模型的预测结果，进行融合，得到实体识别阶段的最终结果
    :param input_file: 原始文件
    :param ner_pred_file: NER预测文件
    :param match_file: Match输入文件,这个里面有匹配的实体，下面有对应的概率
    :param match_pred: Match预测文件
    :param out_file:
    :return:
    '''
    entity_id = pd.read_pickle('data/entity_id.pkl')
    link_prob = entity_link_prob()
    index_bio = get_index_bio()
    pred_all = np.load(ner_pred_file)
    pred_all = list(map(list, zip(*pred_all)))
    result_out = open(out_file,'w')
    match_pred=np.load(match_pred)
    print(match_pred.shape)
    match_entity = pd.read_pickle(match_file)['match_en']
    with open(input_file, 'r') as f:
        for line,pred,match_en,match_p in zip(f,pred_all,match_entity,match_pred):
            out_dict={}
            temDict = json.loads(line)
            text = temDict['text']
            text_id = temDict['text_id']
            entity_count = {}
            for p in pred:
                en_list = get_entity(np.argmax(p, axis=-1), index_bio)
                for en in en_list:
                    entity_count[en]=entity_count.get(en,0)+1

            entity_prob = {}
            for en,p in zip(match_en,match_p):
                if p>0.01:
                    entity_prob[en]=p[0]

            ner_set = set()
            match_set = get_match_entity(entity_prob,link_prob)

            for k in entity_count:
                if entity_count[k]>8 and text[k[0]-1:k[1]] in entity_id:
                    ner_set.add((text[k[0]-1:k[1]],str(k[0]-1),entity_count[k]))

            ner_list=[]
            match_list = []
            for en in ner_set:
                ner_list.append({'mention':en[0],'offset':en[1],'ner_num':en[2],'m_pred':1,})
            for en in match_set:
                match_list.append({'mention':en[0],'offset':en[1],'ner_num':18,'m_pred':en[2],})

            entity_list=filterEntity(ner_list,match_list)

            out_dict['text_id']=text_id
            out_dict['text'] = text
            out_dict['mention_data'] = entity_list
            result_out.write(json.dumps(out_dict, ensure_ascii=False))
            result_out.write('\n')
def get_result ( input_file , ner_pred_file , match_file , match_pred , out_file ) : entity_id = pd . read_pickle ( 'data/entity_id.pkl' ) link_prob = entity_link_prob ( ) index_bio = get_index_bio ( ) pred_all = np . load ( ner_pred_file ) pred_all = list ( map ( list , zip ( * pred_all ) ) ) result_out = open ( out_file , 'w' ) match_pred = np . load ( match_pred ) print ( match_pred . shape ) match_entity = pd . read_pickle ( match_file ) [ 'match_en' ] with open ( input_file , 'r' ) as f : for line , pred , match_en , match_p in zip ( f , pred_all , match_entity , match_pred ) : out_dict = { } temDict = json . loads ( line ) text = temDict [ 'text' ] text_id = temDict [ 'text_id' ] entity_count = { } for p in pred : en_list = get_entity ( np . argmax ( p , axis = - 1 ) , index_bio ) for en in en_list : entity_count [ en ] = entity_count . get ( en , 0 ) + 1 entity_prob = { } for en , p in zip ( match_en , match_p ) : if p > 0.01 : entity_prob [ en ] = p [ 0 ] ner_set = set ( ) match_set = get_match_entity ( entity_prob , link_prob ) for k in entity_count : if entity_count [ k ] > 8 and text [ k [ 0 ] - 1 : k [ 1 ] ] in entity_id : ner_set . add ( ( text [ k [ 0 ] - 1 : k [ 1 ] ] , str ( k [ 0 ] - 1 ) , entity_count [ k ] ) ) ner_list = [ ] match_list = [ ] for en in ner_set : ner_list . append ( { 'mention' : en [ 0 ] , 'offset' : en [ 1 ] , 'ner_num' : en [ 2 ] , 'm_pred' : 1 , } ) for en in match_set : match_list . append ( { 'mention' : en [ 0 ] , 'offset' : en [ 1 ] , 'ner_num' : 18 , 'm_pred' : en [ 2 ] , } ) entity_list = filterEntity ( ner_list , match_list ) out_dict [ 'text_id' ] = text_id out_dict [ 'text' ] = text out_dict [ 'mention_data' ] = entity_list result_out . write ( json . dumps ( out_dict , ensure_ascii = False ) ) result_out . write ( '\n' )