-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.py
129 lines (123 loc) · 7.11 KB
/
utils.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
import torch
def load_soft_emb_without_conj(template, save_name, device):
premise_mode = (save_name.split('/')[0]).split("-")[1]
emb_arg = save_name.split('/')[1].split(".")
emb_path = ".".join([emb_arg[0], "fs", emb_arg[2], emb_arg[3], "log"])
soft_type = torch.load('soft_embedding/type/{}.pth'.format(emb_path), map_location=device)[1:4]
soft_subclass = torch.load('soft_embedding/subClassOf/{}.pth'.format(emb_path), map_location=device)[1:4]
soft_subprop = torch.load('soft_embedding/subPropertyOf/{}.pth'.format(emb_path), map_location=device)[1:4]
soft_domain = torch.load('soft_embedding/domain/{}.pth'.format(emb_path), map_location=device)[1:4]
soft_range = torch.load('soft_embedding/range/{}.pth'.format(emb_path), map_location=device)[1:4]
if "rdfs2" in save_name:
if premise_mode[0] == '2':
template.soft_embedding.weight.data[1:4] = soft_domain
template.soft_embedding.weight.data[4:7] = soft_type
else:
template.soft_embedding.weight.data[1:4] = soft_type
elif "rdfs3" in save_name:
if premise_mode[0] == '2':
template.soft_embedding.weight.data[1:4] = soft_range
template.soft_embedding.weight.data[4:7] = soft_type
else:
template.soft_embedding.weight.data[1:4] = soft_type
elif "rdfs5" in save_name:
if premise_mode[0] == '2' and premise_mode[1] == '2':
template.soft_embedding.weight.data[1:4] = soft_subprop
template.soft_embedding.weight.data[4:7] = soft_subprop
template.soft_embedding.weight.data[7:10] = soft_subprop
elif premise_mode[0] == '2' and premise_mode[1] != '2':
template.soft_embedding.weight.data[1:4] = soft_subprop
template.soft_embedding.weight.data[4:7] = soft_subprop
else:
template.soft_embedding.weight.data[1:4] = soft_subprop
elif "rdfs7" in save_name:
if premise_mode[0] == '2':
template.soft_embedding.weight.data[1:4] = soft_subprop
elif "rdfs9" in save_name:
if premise_mode[0] == '2' and premise_mode[1] == '2':
template.soft_embedding.weight.data[1:4] = soft_subclass
template.soft_embedding.weight.data[4:7] = soft_type
template.soft_embedding.weight.data[7:10] = soft_type
elif premise_mode[0] == '2' and premise_mode[1] != '2':
template.soft_embedding.weight.data[1:4] = soft_subclass
template.soft_embedding.weight.data[4:7] = soft_type
elif premise_mode[0] != '2' and premise_mode[1] == '2':
template.soft_embedding.weight.data[1:4] = soft_type
template.soft_embedding.weight.data[4:7] = soft_type
else:
template.soft_embedding.weight.data[1:4] = soft_type
elif "rdfs11" in save_name:
if premise_mode[0] == '2' and premise_mode[1] == '2':
template.soft_embedding.weight.data[1:4] = soft_subclass
template.soft_embedding.weight.data[4:7] = soft_subclass
template.soft_embedding.weight.data[7:10] = soft_subclass
elif premise_mode[0] == '2' and premise_mode[1] != '2':
template.soft_embedding.weight.data[1:4] = soft_subclass
template.soft_embedding.weight.data[4:7] = soft_subclass
else:
template.soft_embedding.weight.data[1:4] = soft_subclass
return template
def load_soft_emb_with_conj(template, save_name, device):
premise_mode = (save_name.split('/')[0]).split("-")[1]
emb_arg = save_name.split('/')[1].split(".")
emb_path = ".".join([emb_arg[0], "fs", emb_arg[2], emb_arg[3], "log"])
soft_type = torch.load('soft_embedding/type/{}.pth'.format(emb_path), map_location=device)[1:4]
soft_subclass = torch.load('soft_embedding/subClassOf/{}.pth'.format(emb_path), map_location=device)[1:4]
soft_subprop = torch.load('soft_embedding/subPropertyOf/{}.pth'.format(emb_path), map_location=device)[1:4]
soft_domain = torch.load('soft_embedding/domain/{}.pth'.format(emb_path), map_location=device)[1:4]
soft_range = torch.load('soft_embedding/range/{}.pth'.format(emb_path), map_location=device)[1:4]
if "rdfs2" in save_name:
if premise_mode[0] == '2' and premise_mode[1] == '2':
template.soft_embedding.weight.data[1:4] = soft_domain
template.soft_embedding.weight.data[6:9] = soft_type
elif premise_mode[0] == '2' and premise_mode[1] != '2':
template.soft_embedding.weight.data[1:4] = soft_domain
template.soft_embedding.weight.data[5:8] = soft_type
else:
template.soft_embedding.weight.data[2:5] = soft_type
elif "rdfs3" in save_name:
if premise_mode[0] == '2' and premise_mode[1] == '2':
template.soft_embedding.weight.data[1:4] = soft_range
template.soft_embedding.weight.data[6:9] = soft_type
elif premise_mode[0] == '2' and premise_mode[1] != '2':
template.soft_embedding.weight.data[1:4] = soft_range
template.soft_embedding.weight.data[5:8] = soft_type
else:
template.soft_embedding.weight.data[2:5] = soft_type
elif "rdfs5" in save_name:
if premise_mode[0] == '2' and premise_mode[1] == '2':
template.soft_embedding.weight.data[1:4] = soft_subprop
template.soft_embedding.weight.data[5:8] = soft_subprop
template.soft_embedding.weight.data[9:12] = soft_subprop
elif premise_mode[0] == '2' and premise_mode[1] != '2':
template.soft_embedding.weight.data[1:4] = soft_subprop
template.soft_embedding.weight.data[5:8] = soft_subprop
else:
template.soft_embedding.weight.data[2:5] = soft_subprop
elif "rdfs7" in save_name:
if premise_mode[0] == '2':
template.soft_embedding.weight.data[1:4] = soft_subprop
elif "rdfs9" in save_name:
if premise_mode[0] == '2' and premise_mode[1] == '2':
template.soft_embedding.weight.data[1:4] = soft_subclass
template.soft_embedding.weight.data[5:8] = soft_type
template.soft_embedding.weight.data[9:12] = soft_type
elif premise_mode[0] == '2' and premise_mode[1] != '2':
template.soft_embedding.weight.data[1:4] = soft_subclass
template.soft_embedding.weight.data[5:8] = soft_type
elif premise_mode[0] != '2' and premise_mode[1] == '2':
template.soft_embedding.weight.data[1:4] = soft_type
template.soft_embedding.weight.data[5:8] = soft_type
else:
template.soft_embedding.weight.data[2:5] = soft_type
elif "rdfs11" in save_name:
if premise_mode[0] == '2' and premise_mode[1] == '2':
template.soft_embedding.weight.data[1:4] = soft_subclass
template.soft_embedding.weight.data[5:8] = soft_subclass
template.soft_embedding.weight.data[9:12] = soft_subclass
elif premise_mode[0] == '2' and premise_mode[1] != '2':
template.soft_embedding.weight.data[1:4] = soft_subclass
template.soft_embedding.weight.data[5:8] = soft_subclass
else:
template.soft_embedding.weight.data[2:5] = soft_subclass
return template