forked from LuoUndergradXJTU/TwiBot-22
-
Notifications
You must be signed in to change notification settings - Fork 0
/
split_id.py
84 lines (68 loc) · 2.79 KB
/
split_id.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
import numpy as np
from tqdm import tqdm
id_list=np.load('/data2/whr/lyh/twibot22_baseline/Twibot-22/id.npy')
id_include=(np.load('/data2/whr/lyh/baseline2/Twibot-22'+'/id_include.npy',allow_pickle=True))
id_include=list(id_include.item())
id_list=list(id_list)
train_id=[]
val_id=[]
test_id=[]
# with open(r'/data2/whr/czl/TwiBot22-baselines/datasets/Twibot-22/split.csv','r') as f:
# lines=f.readlines()[1:]
# for line in tqdm(lines):
# line=line.split(',')
# curr=eval(line[0][1:])
# curr=id_list.index(curr)
# try:
# curr=id_include.index(curr)
# if(line[1]=='train'):
# train_id.append(curr)
# elif(line[1]=='valid'):
# val_id.append(curr)
# else:
# test_id.append(curr)
# except:
# pass
# print(f"train_size:{len(train_id)} val_size:{len(val_id)} test_size:{len(test_id)} all:{len(id_include)}")
# np.save('/data2/whr/lyh/baseline2/Twibot-22/'+'train_id.npy',np.array(train_id))
# np.save('/data2/whr/lyh/baseline2/Twibot-22/'+'val_id.npy',np.array(val_id))
# np.save('/data2/whr/lyh/baseline2/Twibot-22/'+'test_id.npy',np.array(test_id))
f_train=open('/data2/whr/lyh/baseline2/Twibot-22/train.txt','w')
f_val=open('/data2/whr/lyh/baseline2/Twibot-22/val.txt','w')
f_test=open('/data2/whr/lyh/baseline2/Twibot-22/test.txt','w')
id_list_dict={}
for i,d in enumerate(tqdm(id_list)):
id_list_dict[d]=i
id_include_dict={}
for i,d in enumerate(tqdm(id_include)):
id_include_dict[d]=i
with open(r'/data2/whr/czl/TwiBot22-baselines/datasets/Twibot-22/split.csv','r') as f:
lines=f.readlines()[1:]
for line in tqdm(lines[:700000]):
line=line.split(',')
curr=eval(line[0][1:])
curr=id_list_dict[curr]
if not (curr in id_include):
continue
curr=id_include_dict[curr]
train_id.append(curr)
for line in tqdm(lines[700000:900000]):
line=line.split(',')
curr=eval(line[0][1:])
curr=id_list_dict[curr]
if not (curr in id_include):
continue
curr=id_include_dict[curr]
val_id.append(curr)
for line in tqdm(lines[900000:]):
line=line.split(',')
curr=eval(line[0][1:])
curr=id_list_dict[curr]
if not (curr in id_include):
continue
curr=id_include_dict[curr]
test_id.append(curr)
print(f"train_size:{len(train_id)} val_size:{len(val_id)} test_size:{len(test_id)} all:{len(id_include)}")
np.save('/data2/whr/lyh/baseline2/Twibot-22/'+'train_id.npy',np.array(train_id))
np.save('/data2/whr/lyh/baseline2/Twibot-22/'+'val_id.npy',np.array(val_id))
np.save('/data2/whr/lyh/baseline2/Twibot-22/'+'test_id.npy',np.array(test_id))