|
|
|
@ -10,16 +10,17 @@ import ConfigSpace
|
|
|
|
|
from ConfigSpace import Configuration
|
|
|
|
|
from ConfigSpace.read_and_write import json as csj
|
|
|
|
|
import torch.nn.functional
|
|
|
|
|
from colorama import init, Fore
|
|
|
|
|
from tqdm import tqdm
|
|
|
|
|
|
|
|
|
|
from setting import *
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def matching(config):
|
|
|
|
|
print(f'\033[33mConfig: {config}\033[0m')
|
|
|
|
|
start = time.time()
|
|
|
|
|
# init(autoreset=True)
|
|
|
|
|
print(Fore.BLUE + f'Config: {config}')
|
|
|
|
|
|
|
|
|
|
with open(md_output_dir + "mds.pickle", "rb") as file:
|
|
|
|
|
with open(md_output_dir + r"\mds.pickle", "rb") as file:
|
|
|
|
|
md_list = pickle.load(file)
|
|
|
|
|
|
|
|
|
|
train, valid, test = dm.data.process(
|
|
|
|
@ -30,9 +31,9 @@ def matching(config):
|
|
|
|
|
use_magellan_convention=True, # 与Magellan命名风格相同
|
|
|
|
|
embeddings=config['embeddings'])
|
|
|
|
|
|
|
|
|
|
train_table = train.get_raw_table()
|
|
|
|
|
test_table = test.get_raw_table()
|
|
|
|
|
valid_table = valid.get_raw_table()
|
|
|
|
|
# train_table = train.get_raw_table()
|
|
|
|
|
# test_table = test.get_raw_table()
|
|
|
|
|
# valid_table = valid.get_raw_table()
|
|
|
|
|
|
|
|
|
|
attr_summarizer = config['attr_summarizer']
|
|
|
|
|
if attr_summarizer == 'sif':
|
|
|
|
@ -79,21 +80,25 @@ def matching(config):
|
|
|
|
|
|
|
|
|
|
indicators = {}
|
|
|
|
|
f1_score = model_.run_eval(test, device='cuda')
|
|
|
|
|
indicators["F1"] = f1_score
|
|
|
|
|
indicators["F1"] = f1_score.item() / 100
|
|
|
|
|
|
|
|
|
|
predictions = model_.run_prediction(test, device='cuda', output_attributes=True)
|
|
|
|
|
# predictions中没有predicted列, 根据match_score手动新增 deepmatcher在计算F1时的阈值为0.5
|
|
|
|
|
predictions['predicted'] = predictions['match_score'].apply(lambda score: 1 if score >= 0.5 else 0)
|
|
|
|
|
predictions = predictions.reset_index(drop=True)
|
|
|
|
|
predictions = predictions.astype(str)
|
|
|
|
|
# 目前predictions包含的属性:左右表全部属性+label+predicted+match_score+_id
|
|
|
|
|
sim_tensor_dict = build_col_pairs_sim_tensor_dict(predictions)
|
|
|
|
|
predictions['confidence'] = 0
|
|
|
|
|
predictions['md'] = ''
|
|
|
|
|
|
|
|
|
|
epl_match = 0 # 可解释,预测match
|
|
|
|
|
if len(md_list) > 0:
|
|
|
|
|
for row in tqdm(predictions.itertuples()):
|
|
|
|
|
x = is_explicable(row, md_list, sim_tensor_dict)
|
|
|
|
|
if x > 0 and str(getattr(row, 'predicted')) == str(1):
|
|
|
|
|
predictions.loc[row[0], 'confidence'] = x
|
|
|
|
|
conf, md_dict = is_explicable(row, md_list, sim_tensor_dict)
|
|
|
|
|
if conf > 0 and str(getattr(row, 'predicted')) == str(1):
|
|
|
|
|
predictions.loc[row[0], 'confidence'] = conf
|
|
|
|
|
predictions.loc[row[0], 'md'] = str(md_dict)
|
|
|
|
|
epl_match += 1
|
|
|
|
|
|
|
|
|
|
df = predictions[predictions['predicted'] == str(1)]
|
|
|
|
@ -101,10 +106,10 @@ def matching(config):
|
|
|
|
|
indicators['interpretability'] = interpretability
|
|
|
|
|
performance = interpre_weight * interpretability + (1 - interpre_weight) * indicators["F1"]
|
|
|
|
|
indicators['performance'] = performance
|
|
|
|
|
print(f'ER Indicators: {indicators}')
|
|
|
|
|
print(Fore.BLUE + f'ER Indicators: {indicators}')
|
|
|
|
|
|
|
|
|
|
predictions.to_csv(er_output_dir + r'\predictions.csv', sep=',', index=False, header=True)
|
|
|
|
|
print(f'\033[33mTime consumed by matching in seconds: {time.time() - start}\033[0m')
|
|
|
|
|
print(Fore.CYAN + f'Finish Time: {time.time()}')
|
|
|
|
|
|
|
|
|
|
return indicators
|
|
|
|
|
|
|
|
|
@ -148,13 +153,13 @@ def is_explicable(row, all_mds: list, st_dict):
|
|
|
|
|
explicable = False # 任意一个字段的相似度达不到阈值,这条md就不能解释当前元组
|
|
|
|
|
break # 不再与当前md的其他相似度阈值比较,跳转到下一条md
|
|
|
|
|
if explicable:
|
|
|
|
|
return md_tuple[2] # 任意一条md能解释,直接返回
|
|
|
|
|
return -1.0 # 遍历结束,不能解释
|
|
|
|
|
return md_tuple[2], md_tuple[0] # 任意一条md能解释,直接返回
|
|
|
|
|
return -1.0, {} # 遍历结束,不能解释
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def ml_er(config: Configuration):
|
|
|
|
|
indicators = matching(config)
|
|
|
|
|
output_path = er_output_dir + "eval_result.txt"
|
|
|
|
|
output_path = er_output_dir + r"\eval_result.txt"
|
|
|
|
|
with open(output_path, 'w') as _f:
|
|
|
|
|
_f.write('F1:' + str(indicators["F1"]) + '\n')
|
|
|
|
|
_f.write('interpretability:' + str(indicators['interpretability']) + '\n')
|
|
|
|
@ -162,12 +167,12 @@ def ml_er(config: Configuration):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
|
if os.path.isfile(hpo_output_dir + "incumbent.json"):
|
|
|
|
|
with open(hpo_output_dir + "configspace.json", 'r') as f:
|
|
|
|
|
if os.path.isfile(hpo_output_dir + r"\incumbent.json"):
|
|
|
|
|
with open(hpo_output_dir + r"\configspace.json", 'r') as f:
|
|
|
|
|
dict_configspace = json.load(f)
|
|
|
|
|
str_configspace = json.dumps(dict_configspace)
|
|
|
|
|
configspace = csj.read(str_configspace)
|
|
|
|
|
with open(hpo_output_dir + "incumbent.json", 'r') as f:
|
|
|
|
|
with open(hpo_output_dir + r"\incumbent.json", 'r') as f:
|
|
|
|
|
dic = json.load(f)
|
|
|
|
|
configuration = ConfigSpace.Configuration(configspace, values=dic)
|
|
|
|
|
ml_er(configuration)
|
|
|
|
|