MultiHopKG icon indicating copy to clipboard operation
MultiHopKG copied to clipboard

tensors used as indices must be long, byte or bool tensors

Open yzj19870824 opened this issue 3 years ago • 5 comments

error occurs when I train model using UMLS dataset

Epoch 2: average training loss = -0.22322563640773296 entropy = 4.2052984714508055 => saving checkpoint to '/content/MultiHopKG-master/model/umls-point.rs.conve-xavier-n/a-200-200-3-0.001-0.1-0.0-0.95-400-0.05/checkpoint-2.tar' 0% 0/11 [00:00<?, ?it/s] Traceback (most recent call last): File "/usr/lib/python3.7/runpy.py", line 193, in _run_module_as_main "main", mod_spec) File "/usr/lib/python3.7/runpy.py", line 85, in _run_code exec(code, run_globals) File "/content/MultiHopKG-master/src/experiments.py", line 765, in run_experiment(args) File "/content/MultiHopKG-master/src/experiments.py", line 746, in run_experiment train(lf) File "/content/MultiHopKG-master/src/experiments.py", line 235, in train lf.run_train(train_data, dev_data) File "/content/MultiHopKG-master/src/learn_framework.py", line 146, in run_train dev_scores = self.forward(dev_data, verbose=False) File "/content/MultiHopKG-master/src/learn_framework.py", line 202, in forward pred_score = self.predict(mini_batch, verbose=verbose) File "/content/MultiHopKG-master/src/rl/graph_search/pg.py", line 226, in predict pn, e1, r, e2, kg, self.num_rollout_steps, self.beam_size) File "/content/MultiHopKG-master/src/rl/graph_search/beam_search.py", line 168, in beam_search pn.update_path(action, kg, offset=action_offset) File "/content/MultiHopKG-master/src/rl/graph_search/pn.py", line 187, in update_path offset_path_history(self.path, offset) File "/content/MultiHopKG-master/src/rl/graph_search/pn.py", line 176, in offset_path_history new_tuple = tuple([_x[:, offset, :] for _x in x]) File "/content/MultiHopKG-master/src/rl/graph_search/pn.py", line 176, in new_tuple = tuple([_x[:, offset, :] for _x in x]) IndexError: tensors used as indices must be long, byte or bool tensors

Does anyone meet that?

yzj19870824 avatar Jun 28 '21 23:06 yzj19870824

The type of elements in offset is float indeed.

yzj19870824 avatar Jul 01 '21 12:07 yzj19870824

search for action_beam_offset = action_ind / action_sapce_size and top_unique_beam_offset = top_unique_idx / action_sapce_size and then modify them to action_beam_offset = action_ind // action_sapce_size and top_unique_beam_offset = top_unique_idx // action_sapce_size This change can works and I see it in DacKGR, but I am not sure if it's right.

seanPudding avatar Nov 06 '21 07:11 seanPudding

搜索action_beam_offset = action_ind / action_sapce_sizetop_unique_beam_offset = top_unique_idx / action_sapce_size然后将它们修改为action_beam_offset = action_ind // action_sapce_sizetop_unique_beam_offset = top_unique_idx // action_sapce_size 此更改可以工作,我在DacKGR中看到它,但我不确定它是否正确。

Which file is this line of code in? Do you mind telling me? I can't find this line of code. action_beam_offset = action_ind / action_sapce_size和top_unique_beam_offset = top_unique_idx / action_sapce_size

wenjian-sc avatar Sep 12 '22 08:09 wenjian-sc

action_beam_offset = action_ind / action_sapce_size (src/rl/graph_search/beam_search.py line:62) top_unique_beam_offset = top_unique_idx / action_sapce_size (src/rl/graph_search/beam_search.py line:105)

seanPudding avatar Sep 12 '22 08:09 seanPudding

action_beam_offset = action_ind / action_sapce_size (src/rl/graph_search/beam_search.py 行:62) top_unique_beam_offset = top_unique_idx / action_sapce_size (src/rl/graph_search/beam_search.py 行:105)

Thank you for your help. I found it. Thank you

wenjian-sc avatar Sep 12 '22 09:09 wenjian-sc