16
16
from torchhd import embeddings , HRRTensor
17
17
import torchhd .tensors
18
18
from scipy .sparse import vstack , lil_matrix
19
+ import numpy as np
19
20
20
21
21
22
device = torch .device ("cuda" if torch .cuda .is_available () else "cpu" )
@@ -36,7 +37,7 @@ def sparse_batch_collate(batch:list):
36
37
data_batch , targets_batch = zip (* batch )
37
38
38
39
data_batch = vstack (data_batch ).tocoo ()
39
- data_batch = torch .sparse_coo_tensor (data_batch .nonzero (), data_batch .data , data_batch .shape )
40
+ data_batch = torch .sparse_coo_tensor (np . array ( data_batch .nonzero () ), data_batch .data , data_batch .shape )
40
41
41
42
targets_batch = torch .stack (targets_batch )
42
43
@@ -67,7 +68,7 @@ def __getitem__(self, idx):
67
68
if DATASET_NAME == "Wiki10-31K" : # Because of this issue https://github.com/mwydmuch/napkinXC/issues/18
68
69
X_train = lil_matrix (X_train [:,:- 1 ])
69
70
70
- N_freatures = X_train .shape [1 ]
71
+ N_features = X_train .shape [1 ]
71
72
N_classes = max (max (classes ) for classes in Y_train if classes != []) + 1
72
73
73
74
train_dataset = multilabel_dataset (X_train ,Y_train ,N_classes )
@@ -77,7 +78,7 @@ def __getitem__(self, idx):
77
78
78
79
79
80
print ("Traning on \033 [1m {} \033 [0m. It has {} features, and {} classes."
80
- .format (DATASET_NAME ,N_freatures ,N_classes ))
81
+ .format (DATASET_NAME ,N_features ,N_classes ))
81
82
82
83
83
84
# Fully Connected model for the baseline comparision
@@ -168,10 +169,10 @@ def loss(self,out,target):
168
169
169
170
170
171
171
- hrr_model = FCHRR (N_freatures ,N_classes ,DIMENSIONS )
172
+ hrr_model = FCHRR (N_features ,N_classes ,DIMENSIONS )
172
173
hrr_model = hrr_model .to (device )
173
174
174
- baseline_model = FC (N_freatures ,N_classes )
175
+ baseline_model = FC (N_features ,N_classes )
175
176
baseline_model = baseline_model .to (device )
176
177
177
178
0 commit comments