-
Notifications
You must be signed in to change notification settings - Fork 17
/
combine.py
101 lines (72 loc) · 4.02 KB
/
combine.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import pandas as pd
import numpy as np
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("--model_prefix", default=None, type=str, required=True)
parser.add_argument("--out_path", default=None, type=str, required=True)
args = parser.parse_args()
k = 10
df = pd.read_csv('data_re_5fold/data_0/test.csv')
def kfold_averaging():
df['0']=0
df['1']=0
df['2']=0
for i in range(k):
temp=pd.read_csv('{}{}/sub.csv'.format(args.model_prefix,i))
#将某一个标签上的概率值相加取平均
df['0']+=temp['label_0']/k
df['1']+=temp['label_1']/k
df['2']+=temp['label_2']/k
#print(df['0'].mean())
df['label']=np.argmax(df[['0','1','2']].values,-1)
df[['id','label']].to_csv(args.out_path,index=False)
#df[['id','0', '1', '2']].to_csv(args.out_path,index=False)
def kfold_voting():
for i in range(len(df)):
#记票变量
voting = [0, 0, 0]
#给每个fold模型记票
for z in range(k):
temp = pd.read_csv('{}{}/sub.csv'.format(args.model_prefix,z))
temp['label'] = np.argmax(temp[['label_0','label_1','label_2']].values, -1)
vote = temp['label'][i]
if vote == 0:
voting[0] += 1
elif vote == 1:
voting[1] += 1
elif vote == 2:
voting[2] += 1
winnerID = np.argmax(voting)
df['label'][i] = winnerID
df[['id','label']].to_csv(args.out_path,index=False)
#kfold_averaging()
kfold_voting()
#bert_base
#python combine.py --model_prefix ./results/bert_base_02/bert_base --out_path ./results/bert_base_02/sub_voting.csv
#python combine.py --model_prefix ./results/bert_base_04/bert_base --out_path ./results/bert_base_04/sub_averaging.csv
#bert_wwm
#python combine.py --model_prefix /media/zhan/Mars/datafountain350/results/backup2_bert_wwm/bert_wwm --out_path /media/zhan/Mars/datafountain350/results/backup2_bert_wwm/sub_averaging.csv
#python combine.py --model_prefix ./results/bert_wwm/bert_wwm --out_path ./results/bert_wwm/sub_voting.csv
#bert_wwm_ext
#python combine.py --model_prefix ./results/bert_wwm_ext_03/bert_wwm_ext --out_path ./results/bert_wwm_ext_03/sub_voting.csv
#ERNIE_base
#python combine.py --model_prefix ./results/ERNIE_base_06/ERNIE_base --out_path ./results/ERNIE_base_06/sub_voting.csv
#OpenCLaP_baike
#python combine.py --model_prefix ./results/OpenCLaP_baike/OpenCLaP_baike --out_path ./results/OpenCLaP_baike/sub.csv
#roberta_l12
#python combine.py --model_prefix ./results/roberta_l12/roberta_l12 --out_path ./results/roberta_l12/sub.csv
#python combine.py --model_prefix ./results/roberta_l12/roberta_l12 --out_path ./results/roberta_l12/sub_voting.csv
#roberta_large
#python combine.py --model_prefix ./results/backup1_roberta_large/roberta_large --out_path ./results/backup1_roberta_large/sub_voting_3best.csv
#python combine.py --model_prefix ./results/backup2_roberta_large/roberta_large --out_path ./results/backup2_roberta_large/sub_averaging.csv
#python combine.py --model_prefix ./results/backup4_roberta_large/roberta_large --out_path ./results/backup4_roberta_large/sub_voting.csv
#python combine.py --model_prefix ./results/backup3_roberta_large/roberta_large --out_path ./results/backup4_roberta_large/sub_averaging.csv
#python combine.py --model_prefix ./results/backup4_roberta_large/roberta_large --out_path ./results/backup4_roberta_large/sub_averaging.csv
#python combine.py --model_prefix ./results/backup6_roberta_large/roberta_large --out_path ./results/backup6_roberta_large/sub_voting.csv
#python combine.py --model_prefix /media/zhan/Mars/datafountain350/results/backup5_roberta_large/roberta_large --out_path /media/zhan/Mars/datafountain350/results/backup5_roberta_large/sub_voting.csv
#roberta_wwm_large_ext
#python combine.py --model_prefix ./results/roberta_wwm_large_ext_04/roberta_wwm_large_ext --out_path ./results/roberta_wwm_large_ext_04/sub_voting.csv
#xlnet_mid
#python combine.py --model_prefix ./results/xlnet_mid_02/xlnet_mid --out_path ./results/xlnet_mid_02/sub.csv
#stacking
#python combine.py --model_prefix ./ensemble/stacking/results/bertFC_base/bertFC_base --out_path ./ensemble/stacking/results/bertFC_base/stacking_voting.csv