yuzhimanhua / Multi-BioNER

Cross-type Biomedical Named Entity Recognition with Deep Multi-task Learning (Bioinformatics'19)
https://arxiv.org/abs/1801.09851
Apache License 2.0
131 stars 28 forks source link

A bug in your code #1

Closed QingkaiZeng closed 5 years ago

QingkaiZeng commented 5 years ago

Hi, I run your code by shell, but it does not work. The Traceback result is as follow.

Traceback (most recent call last): File "train_wc.py", line 263, in loss = crit_ner(scores, tg_v, mask_v) File "/afs/crc.nd.edu/user/q/qzeng/.local/lib/python3.6/site-packages/torch/nn/modules/module.py", line 477, in call result = self.forward(*input, **kwargs) File "/afs/crc.nd.edu/user/q/qzeng/Multi-BioNER/model/crf.py", line 309, in forward mask[idx].contiguous().view(bat_size, 1).expand(bat_size, self.tagset_size)).contiguous().view(bat_size, -1) File "/afs/crc.nd.edu/user/q/qzeng/Multi-BioNER/model/utils.py", line 66, in switch catvec = torch.cat([vec1.view(-1, 1), vec2.view(-1, 1)], dim=1) RuntimeError: invalid argument 2: view size is not compatible with input tensor's size and stride (at least one dimension spans across two contiguous subspaces). Call .contiguous() before .view(). at /pytorch/aten/src/TH/generic/THTensor.cpp:237

yuzhimanhua commented 5 years ago

Hi, thanks for raising this issue.

The errors include one line in crf.py "File "/afs/crc.nd.edu/user/q/qzeng/Multi-BioNER/model/crf.py", line 309, in forward mask[idx].contiguous().view(bat_size, 1).expand(bat_size, self.tagset_size)).contiguous().view(bat_size, -1)"

Could you try to replace Line 308-309 with the following code?

mask_idx = mask[idx, :].view(bat_size, 1).expand(bat_size, self.tagset_size) partition.maskedscatter(mask_idx, cur_partition.masked_select(mask_idx))

QingkaiZeng commented 5 years ago

Thanks for your replying. But here is still some bug as follow.

Traceback (most recent call last): File "train_wc.py", line 286, in dev_f1, dev_pre, dev_rec, dev_acc = evaluator.calc_score(ner_model, dev_dataset_loader[file_no], file_no) File "/afs/crc.nd.edu/user/q/qzeng/Multi-BioNER/model/evaluator.py", line 210, in calc_score decoded = self.decoder.decode(scores.data, mask_v.data) File "/afs/crc.nd.edu/user/q/qzeng/Multi-BioNER/model/crf.py", line 387, in decode decode_idx[idx] = pointer RuntimeError: expand(torch.LongTensor{[50, 1]}, size=[50]): the number of sizes provided (1) must be greater or equal to the number of dimensions in the tensor (2)

yuzhimanhua commented 5 years ago

It seems that you are using pytorch 0.4? Sorry that this repo only supports pytorch 0.3.x or lower.

yuzhimanhua commented 5 years ago

Please also try to use the following line to replace 308-309: partition = utils.switch(partition, cur_partition, mask[idx].view(bat_size, 1).expand(bat_size, self.tagset_size)).view(bat_size, -1)