'##', '').replace('□', ' ') if subject[0] == '《': subject = subject[1:] if subject[-1] == '》': subject = subject[:-1] logging.info('抽到的主语为:{}'.format(subject)) spos = [] spos += graph.get(subject, []) ons = entity_linking.get(subject, []) for on in ons: spos += graph.get(on, []) spos = set(spos) pres = list(set([spo[1] for spo in spos])) # logging.info('候选关系为:{}'.format(pres)) if pres: sub_re_data = bl.build_re_data(question, pres) sub_re_bl = bl.batch_loader(None, sub_re_data, args.ner_max_len, args.re_max_len, args.batch_size, is_train=False) sub_labels = [] for batch_data in sub_re_bl: batch_data = tuple( tmp.to(args.device) for tmp in batch_data) label_logits = model(batch_data, 1, False).cpu().tolist() sub_labels += label_logits index_pre = np.argmax(sub_labels) pre = pres[index_pre]