utahnlp / layer_augmentation

Implementation of the NLI model in our ACL 2019 paper: Augmenting Neural Networks with First-order Logic.
Apache License 2.0
42 stars 6 forks source link

error when run train.py #1

Open zhenwwang opened 5 years ago

zhenwwang commented 5 years ago

[ERROR 01] File "./classifier\local_classifier.py", line 10, in from backward_hooks import * ModuleNotFoundError: No module named 'backward_hooks'

I just comment this line,then the second error occured

[ERROR 02] File "C:\Users\Wang\Desktop\8_12\layer_augmentation-master\data.py", line 251, in getitem char1 = self.char_idx[all_source.contiguous()].view(batch_l, source_l, token_l) IndexError: tensors used as indices must be long, byte or bool tensors

I fixed this,by add .type(torch.uint8) like this "char1=self.char_idx[all_source.contiguous().view(-1).type(torch.uint8)].view(batch_l, source_l, token_l)"

but errors continued:

[ERROR 03] File "C:\Users\Wang\Desktop\8_12\layer_augmentation-master\data.py", line 252, in getitem char1 = self.char_idx[all_source.contiguous().view(-1).type(torch.uint8)].view(batch_l, source_l, token_l) IndexError: The shape of the mask [320] at index 0 does not match the shape of the indexed tensor [34292, 16] at index 0

What should I do?

t-li commented 5 years ago

Hi,

Thanks for reporting the issues.

I have just pushed a commit that fixed some minor issues occurred on my end. Pleased give it a shot. The [ERROR 1] will be gone now.

[ERROR 2] did not happen on my end. I cleaned up all preprocessed data and restarted it over from scratch. Still got no such error. It seems when saving the variable [all_source] in preprocess.py, the format is already np.int (at line 152 preprocess.py). So when loading in data.py, it should stick to int as default. Maybe you are using a newer version of pytorch that changed the default behavior? I am using pytorch 1.0.1.post2.

You might want to try something like this in line 29-33 in data.py self.all_source = torch.from_numpy(self.all_source.astype(np.int32)) self.all_target = torch.from_numpy(self.all_target.astype(np.int32)) self.source = torch.from_numpy(self.source.astype(np.int32)) self.target = torch.from_numpy(self.target.astype(np.int32)) self.label = torch.from_numpy(self.label.astype(np.int32))

In your solution, I suggest you to avoid torch.uint8 which is insufficient for token indices.

t-li commented 5 years ago

Just made another push that forces indices to be long format.

My hypothesis is that my numpy int is by default int64, so it worked on my end. Sometimes np.int can be defaulted to int32. And pytorch wants indices to be int64/long.

Please pull again and give it a shot.

zhenwwang commented 5 years ago

@t-li Thanks for your reply.

I just pulled again and solved these problems.

It works well now.

Thanks.

rndn123 commented 4 years ago

I got this error in your program. I didn't understand please HELP thanks in advance !! Traceback (most recent call last): File "train.py", line 305, in sys.exit(main(sys.argv[1:])) File "train.py", line 300, in main train(opt, shared, m, optim, ema, train_data, val_data) File "train.py", line 178, in train train_perf, extra_train_perf, loss, num_ex = train_epoch(opt, shared, m, optim, ema, train_data, i, train_idx) File "train.py", line 113, in train_epoch output = m.forward(wv_idx1, wv_idx2, cv_idx1, cv_idx2) File "/content/drive/My Drive/layer_augmentation-master/layer_augmentation-master/pipeline.py", line 104, in forward att1, att2 = self.attention(input_enc1, input_enc2) File "/usr/local/lib/python3.6/dist-packages/torch/nn/modules/module.py", line 550, in call result = self.forward(*input, kwargs) File "./attention/local_attention.py", line 36, in forward self.shared.att_soft1, self.shared.att_soft2) File "/usr/local/lib/python3.6/dist-packages/torch/nn/modules/module.py", line 550, in call result = self.forward(*input, *kwargs) File "/content/drive/My Drive/layer_augmentation-master/layer_augmentation-master/within_layer.py", line 86, in forward datt1_ls.append(layer(att1.transpose(1,2)).transpose(1,2).contiguous().view(1, batch_l, sent_l1, sent_l2)) File "/usr/local/lib/python3.6/dist-packages/torch/nn/modules/module.py", line 550, in call result = self.forward(input, kwargs) File "./constraint/n1.py", line 57, in forward d = self.logic(att) File "./constraint/n1.py", line 37, in logic p_content_selector = get_p_selector(self.opt, self.shared, 'content_word', with_nul=False).view(self.shared.batch_l, 1, self.shared.sent_l1) File "./constraint/constr_utils.py", line 58, in get_p_selector mask[ex][p_contents] = 1.0 IndexError: index 15 is out of bounds for dimension 0 with size 14