WindyLee0822 / TREA

Source code of “TREA: Tree-structure Reasoning Schema for Conversational Recommendation (ACL 2023)”
4 stars 1 forks source link

IndexError: tensors used as indices must be long, byte or bool tensors #3

Open lhy1214 opened 1 year ago

lhy1214 commented 1 year ago

Hello, I like this work very much, I encountered the following problem when reproducing, tried the solution, still reported the error, I want to ask you if there is a better solution. The error is in this line: concept_emb = con_nodes_features[concept_mask] IndexError: tensors used as indices must be long, byte or bool tensors I changed this line to : concept_emb = con_nodes_features[concept_mask].type(torch.long) The mistake is still the same mistake.I really need everyone's help, thank you very much.

WindyLee0822 commented 1 year ago

You may try to change this line to "concept_emb = con_nodes_features[concept_mask.long()]" I think "[concept_mask].type(torch.long)" should be "[concept_mask.type(torch.long)]" I hope the above solution works.

lhy1214 commented 1 year ago

That's great! I have solved the previous problem according to the method you said, and then faced the following problem, I very much hope you can help me solve the following again. Traceback (most recent call last): File "D:\TERA\new\TREA-main\run_publish.py", line 1088, in loop.train() File "D:\TERA\new\TREA-main\run_publish.py", line 238, in train scores, preds, rec_scores, rec_loss, score_loss, gen_loss, mask_loss, info_dbloss, = self.model( File "C:\Users\24595\anaconda3\lib\site-packages\torch\nn\modules\module.py", line 1194, in _call_impl return forward_call(*input, *kwargs) File "D:\TERA\new\TREA-main\model.py", line 1096, in forward recloss = self.criterion2(entity_scores.unsqueeze(1).repeat(1, 32, 1).view(-1, entity_scores.shape[1]), File "C:\Users\24595\anaconda3\lib\site-packages\torch\nn\modules\module.py", line 1194, in _call_impl return forward_call(input, **kwargs) File "C:\Users\24595\anaconda3\lib\site-packages\torch\nn\modules\loss.py", line 1174, in forward return F.cross_entropy(input, target, weight=self.weight, File "C:\Users\24595\anaconda3\lib\site-packages\torch\nn\functional.py", line 3026, in cross_entropy return torch._C._nn.cross_entropy_loss(input, target, weight, _Reduction.get_enum(reduction), ignore_index, label_smoothing) RuntimeError: "nll_loss_forward_no_reduce_cuda_kernel_index" not implemented for 'Int'

WindyLee0822 commented 1 year ago

Try to transform the labels to long type: recloss = self.criterion2(entity_scores.unsqueeze(1).repeat(1, 32, 1).view(-1, entity_scores.shape[1]), ent_rec.view(-1).long())

lhy1214 commented 1 year ago

Thank you very much, according to your help I have solved, I wish you all the best in your future work, thank you again.