代码拉取完成,页面将自动刷新
同步操作将从 young-rich/知识图谱推理 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
import pandas as pd
import numpy as np
import json
import jsonlines
from sentence_transformers import SentenceTransformer, InputExample, losses, CrossEncoder
from torch.utils.data import DataLoader
from sentence_transformers.cross_encoder.evaluation import CEBinaryClassificationEvaluator
# labels = ['品类_适用_场景', '品类_搭配_品类', '品类_适用_人物', '人物_蕴含_场景']
# pre_name = 'hfl-chinese-bert-wwm-ext'
for pre_name in ['hfl-chinese-bert-wwm-ext', 'hfl-chinese-macbert-base', 'hfl-chinese-roberta-wwm-ext', 'hfl-chinese-electra-180g-base-discriminator']:
for label in ['品类_适用_场景', '品类_搭配_品类', '品类_适用_人物', '人物_蕴含_场景']:
# label = '品类_适用_场景'
df_result = pd.read_csv('/home/yx/project/P_prediction/ccks_1_sbert/output/model_save_path_' +
pre_name + '_' + label + '/CEBinaryClassificationEvaluator_sts-dev_results.csv')
threshold = df_result['F1_Threshold'].values[-1]
df_dev = pd.read_pickle(
'/home/yx/project/P_prediction/ccks_1_sbert/data/dev_data.pkl')
test_samples = []
df_label_dev = df_dev.loc[(df_dev['predicate'] == label)]
sentence1 = df_label_dev.subject.values
sentence2 = df_label_dev.object.values
for s1, s2 in zip(sentence1, sentence2):
test_samples.append([s1, s2])
model = CrossEncoder(
'/home/yx/project/P_prediction/ccks_1_sbert/output/model_save_path_'+pre_name+'_' + label)
results = model.predict(test_samples)
result_i = []
for i in results:
if i > threshold:
result_i.append(1)
else:
result_i.append(0)
df_label_dev['salience'] = result_i
df_label_dev.to_pickle(
'/home/yx/project/P_prediction/ccks_1_sbert/output/model_save_path_'+pre_name+'_' + label + '/result.pkl')
df_result1 = pd.read_pickle(
'/home/yx/project/P_prediction/ccks_1_sbert/output/model_save_path_'+pre_name+'_品类_搭配_品类/result.pkl')
df_result2 = pd.read_pickle(
'/home/yx/project/P_prediction/ccks_1_sbert/output/model_save_path_'+pre_name+'_品类_适用_场景/result.pkl')
df_result3 = pd.read_pickle(
'/home/yx/project/P_prediction/ccks_1_sbert/output/model_save_path_'+pre_name+'_品类_适用_人物/result.pkl')
df_result4 = pd.read_pickle(
'/home/yx/project/P_prediction/ccks_1_sbert/output/model_save_path_'+pre_name+'_人物_蕴含_场景/result.pkl')
df_result = pd.concat([df_result1, df_result2, df_result3, df_result4])
# df_result[['salience', 'triple_id']].to_json('/home/yx/project/P_prediction/ccks_1_sbert/data/result_'+pre_name +'.jsonl', orient='records', lines= True)
df_result[['salience', 'triple_id']].to_pickle(
'/home/yx/project/P_prediction/ccks_1_sbert/data/result_'+pre_name + '.pkl')
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。