DeepGraphLearning / KnowledgeGraphEmbedding

MIT License
1.24k stars 264 forks source link

train error #28

Closed as3896001 closed 4 years ago

as3896001 commented 4 years ago

I used the training instructions you provided, but there are some problems, I don’t know how to solve them

File "codes/run.py", line 361, in main(parse_args()) File "codes/run.py", line 305, in main log = kge_model.train_step(kge_model, optimizer, train_iterator, args) File "codes\model.py", line 267, in train_step negative_score = model((positive_sample, negative_sample), mode=mode) File "C:\Users\Kano_Hayashi.conda\envs\rota\lib\site-packages\torch\nn\modules\module.py", line 550, in _call _ result = self.forward(*input, **kwargs) File "codes\model.py", line 144, in forward index=tail_part.view(-1) RuntimeError: Expected object of scalar type Long but got scalar type Int for argument #3 'index' in call to _th_index_select

Edward-Sun commented 4 years ago

Hi, Yi-Rong, what's your PyTorch version?

as3896001 commented 4 years ago

My PyTorch version is 1.15.0,Is it too new?

as3896001 commented 4 years ago

I made its version into 1.3.0 and 1.0.2, but the problem still there RuntimeError: Expected object of scalar type Long but got scalar type Int for argument #3 'index'

ToneLi commented 4 years ago

@as3897001, I have the same issue, this is not the version problem, the place which occurs error is in model.py: tail = torch.index_select( self.entity_embedding, dim=0, index=tail_part.view(-1) ).view(batch_size, negative_sample_size, -1)

Solution: You just modify "negative_sample = torch.from_numpy(negative_sample) " [this is in dataloader.py] to "negative_sample = torch.LongTensor(negative_sample)"

Edward-Sun commented 4 years ago

Hi @ToneLi ,

Thanks for the correction. The code is updated.

Hi @as3896001 , does this solve your problem?

as3896001 commented 4 years ago

Thank you,I'll give it a try.