forked from jaywonchung/BERT4Rec-VAE-Pytorch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
paint_out.py
182 lines (160 loc) · 8.65 KB
/
paint_out.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
import matplotlib.pyplot as plt
import os
import json
lw = 1.7
markersize = 5.7
def data_to_line(data):
r_s = '\t'
n_s = '\t'
Recall = 'Recall@'
NDCG = 'NDCG@'
for i in [1, 5, 10, 15, 20, 25]:
r_s += '%.4f' % data[Recall + str(i)] + '\t'
n_s += '%.4f' % data[NDCG + str(i)] + '\t'
# r_s += str(round(data[Recall + str(i)], 4)) + '\t'
# n_s += str(round(data[NDCG + str(i)], 4)) + '\t'
return r_s + n_s
def data_load():
dir = './experiments'
for root, dirs, files in os.walk(dir):
infos = root.split('_')
for f in files:
if 'test_metrics.json' == f and '1m' in root:
if 'cnn' == infos[2]:
infos[1] = infos[1] + infos[2]
infos[2] = infos[3]
infos[3] = infos[4]
data_file = open(root + '\\\\' + f)
data = json.load(data_file)
print('%12s\t%3s\t%10s\t%s'
% (infos[1], infos[2], infos[3], data_to_line(data)))
def data_load_bert_cnn():
dir = './experiments'
print('model\tdim\tdataset\tblocks\theads\tepochs\tstride\tkernel_size')
for root, dirs, files in os.walk(dir):
for sub_dir in dirs:
path = root + '/' + sub_dir
if 1 ==1 :
try:
data, data_config = {}, {}
data_file = open(path + '/logs/' + 'test_metrics.json')
data = json.load(data_file)
data_file = open(path + '/' + 'config.json')
data_config = json.load(data_file)
print('%12s\t%3s\t%10s\t%d\t%d\t%d\t%d\t%d\t%s'
% (data_config['model_code'],
data_config['dim'],
data_config['dataset_code'],
data_config['bert_num_blocks'],
data_config['bert_num_heads'],
data_config['num_epochs'],
data_config['stride'],
data_config['kernel_size'],
data_to_line(data)))
except BaseException:
pass
# print()
def paint_dim_1_4():
x = ['32', '64', '128', '256']
fig = plt.figure(figsize=(40, 10), dpi=80)
# 创建子图1
sub1 = fig.add_subplot(1, 2, 1)
sub1.plot(x, [0.7037, 0.7442, 0.7558, 0.7671], '^-' ,color='coral', label=r'ConvBERT4Rec@20M', lw=lw, markersize=markersize)
sub1.plot(x, [0.6818, 0.7180, 0.7499, 0.7588], 's-' ,color='green', label=r'BERT4Rec@20M', lw=lw, markersize=markersize)
sub1.plot(x, [0.7029, 0.7476, 0.7684, 0.7594], '^--',color='coral', label=r'ConvBERT4Rec@1M', lw=lw, markersize=markersize)
sub1.plot(x, [0.6740, 0.7171, 0.7489, 0.7513], 's--',color='green', label=r'BERT4Rec@1M', lw=lw, markersize=markersize)
# sub1.title.set_text('MovieLens 20M')
sub1.set_xlabel('dim', fontsize=font_size)
sub1.set_ylabel('Recall@10', fontsize=font_size)
sub1.tick_params(labelsize=font_size)
sub1.grid(color='r', linestyle='--', linewidth=0.5, alpha=0.2)
# 创建子图2
sub3 = fig.add_subplot(1, 2, 2)
sub3.plot(x, [0.4523, 0.4926, 0.5073, 0.5216], '^-', color='coral', label=r'ConvBERT4Rec@20M', lw=lw, markersize=markersize)
sub3.plot(x, [0.4291, 0.4633, 0.5005, 0.5142], 's-', color='green', label=r'BERT4Rec@20M', lw=lw, markersize=markersize)
sub3.plot(x, [0.4784, 0.5286, 0.5457, 0.5393], '^--',color='coral', label=r'ConvBERT4Rec@1M', lw=lw, markersize=markersize)
sub3.plot(x, [0.4193, 0.4866, 0.5367, 0.5402], 's--',color='green', label=r'BERT4Rec@1M', lw=lw, markersize=markersize)
# sub3.title.set_text('MovieLens 20M')
sub3.set_xlabel('dim', fontsize=font_size)
sub3.set_ylabel('NDCG@10', fontsize=font_size)
sub3.tick_params(labelsize=font_size)
sub3.grid(color='r', linestyle='--', linewidth=0.5, alpha=0.2)
# 创建子图1
# sub4 = fig.add_subplot(2, 2, 3)
# sub4.plot(x, [0.7029, 0.7476, 0.7684, 0.7594], '^-', label=r'ConvBERT4Rec', lw=lw, markersize=markersize)
# sub4.plot(x, [0.6740, 0.7171, 0.7489, 0.7513], 's-', label=r'BERT4Rec', lw=lw, markersize=markersize)
# sub4.plot(x, [0.3676, 0.3756, 0.3772, 0.3619], '.-', label=r'ADE', lw=lw, markersize=markersize)
# sub4.plot(x, [0.3800, 0.3656, 0.3682, 0.3604], 'x-', label=r'VDE', lw=lw, markersize=markersize)
# sub4.title.set_text('MovieLens 1M')
# sub4.set_xlabel('dim')
# sub4.set_ylabel('Recall@10')
# sub4.grid(color='r', linestyle='--', linewidth=0.5, alpha=0.2)
#
# # 创建子图2
# sub2 = fig.add_subplot(2, 2, 4)
# sub2.plot(x, [0.4784, 0.5286, 0.5457, 0.5393], '^-', label=r'ConvBERT4Rec', lw=lw, markersize=markersize)
# sub2.plot(x, [0.4193, 0.4866, 0.5367, 0.5402], 's-', label=r'BERT4Rec', lw=lw, markersize=markersize)
# sub2.plot(x, [0.3902, 0.3971, 0.3887, 0.3776], '.-', label=r'ADE', lw=lw, markersize=markersize)
# sub2.plot(x, [0.3959, 0.3773, 0.3855, 0.3771], 'x-', label=r'VDE', lw=lw, markersize=markersize)
# sub2.title.set_text('MovieLens 1M')
# sub2.set_xlabel('dim')
# sub2.set_ylabel('NDCG@10')
# sub2.grid(color='r', linestyle='--', linewidth=0.5, alpha=0.2)
plt.legend(loc=0, bbox_to_anchor=(1.05, 1),fontsize=font_size)
# plt.tight_layout()
plt.show()
def paint_top_1_4():
x = ['5', '10', '15', '20', '25']
fig = plt.figure(figsize=(40, 10), dpi=80)
# 创建子图1
sub1 = fig.add_subplot(1, 2, 1)
sub1.plot(x, [0.6058, 0.7442, 0.8113, 0.8532, 0.8812], '^-', color='coral', label=r'ConvBERT4Rec@20M', lw=lw, markersize=markersize)
sub1.plot(x, [0.5740, 0.7180, 0.7909, 0.8367, 0.8676], 's-', color='green', label=r'BERT4Rec@20M', lw=lw, markersize=markersize)
sub1.plot(x, [0.6336, 0.7476, 0.8108, 0.8519, 0.8848], '^--',color='coral', label=r'ConvBERT4Rec@1M', lw=lw, markersize=markersize)
sub1.plot(x, [0.5883, 0.7171, 0.7823, 0.8289, 0.8647], 's--',color='green', label=r'BERT4Rec@1M', lw=lw, markersize=markersize)
# sub1.title.set_text('MovieLens 20M')
sub1.set_xlabel('K',fontsize=font_size)
sub1.set_ylabel('Recall@K',fontsize=font_size)
sub1.tick_params(labelsize=font_size)
sub1.grid(color='r', linestyle='--', linewidth=0.5, alpha=0.2)
# 创建子图2
sub3 = fig.add_subplot(1, 2, 2)
sub3.plot(x, [0.4477, 0.4926, 0.5104, 0.5203, 0.5265], '^-', color='coral', label=r'ConvBERT4Rec@20M', lw=lw, markersize=markersize)
sub3.plot(x, [0.4166, 0.4633, 0.4827, 0.4935, 0.5002], 's-', color='green', label=r'BERT4Rec@20M', lw=lw, markersize=markersize)
sub3.plot(x, [0.4917, 0.5286, 0.5454, 0.5551, 0.5623], '^--',color='coral', label=r'ConvBERT4Rec@1M', lw=lw, markersize=markersize)
sub3.plot(x, [0.4449, 0.4866, 0.5039, 0.5149, 0.5228], 's--',color='green', label=r'BERT4Rec@1M', lw=lw, markersize=markersize)
# sub3.title.set_text('MovieLens 20M')
sub3.set_xlabel('K',fontsize=font_size)
sub3.set_ylabel('NDCG@K',fontsize=font_size)
sub3.tick_params(labelsize=font_size)
sub3.grid(color='r', linestyle='--', linewidth=0.5, alpha=0.2)
#
# # 创建子图1
# sub4 = fig.add_subplot(2, 2, 3)
# sub4.plot(x, [0.6336, 0.7476, 0.8108, 0.8519, 0.8848], '^-', label=r'ConvBERT4Rec', lw=lw, markersize=markersize)
# sub4.plot(x, [0.5883, 0.7171, 0.7823, 0.8289, 0.8647], 's-', label=r'BERT4Rec', lw=lw, markersize=markersize)
# sub4.plot(x, [0.4034, 0.3756, 0.3744, 0.3774, 0.3908], '.-', label=r'ADE', lw=lw, markersize=markersize)
# sub4.plot(x, [0.3861, 0.3656, 0.3704, 0.3845, 0.4015], 'x-', label=r'VDE', lw=lw, markersize=markersize)
# sub4.title.set_text('MovieLens 1M')
# sub4.set_xlabel('K')
# sub4.set_ylabel('Recall@K')
# sub4.grid(color='r', linestyle='--', linewidth=0.5, alpha=0.2)
#
# # 创建子图2
# sub2 = fig.add_subplot(2, 2, 4)
# sub2.plot(x, [0.4917, 0.5286, 0.5454, 0.5551, 0.5623], '^-', label=r'ConvBERT4Rec', lw=lw, markersize=markersize)
# sub2.plot(x, [0.4449, 0.4866, 0.5039, 0.5149, 0.5228], 's-', label=r'BERT4Rec', lw=lw, markersize=markersize)
# sub2.plot(x, [0.4246, 0.3971, 0.3875, 0.3830, 0.3853], '.-', label=r'ADE', lw=lw, markersize=markersize)
# sub2.plot(x, [0.3978, 0.3773, 0.3728, 0.3749, 0.3802], 'x-', label=r'VDE', lw=lw, markersize=markersize)
# sub2.title.set_text('MovieLens 1M')
# sub2.set_xlabel('K')
# sub2.set_ylabel('NDCG@K')
# sub2.grid(color='r', linestyle='--', linewidth=0.5, alpha=0.2)
plt.legend(loc=0, bbox_to_anchor=(1.05, 1),fontsize=font_size)
# plt.tight_layout()
plt.show()
font_size=17
if __name__ == '__main__':
paint_dim_1_4()
# data_load_bert_cnn()
# data_load()