wildltr / ptranking

Learning to Rank in PyTorch

Home Page:https://wildltr.github.io/ptranking/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

fm-chen opened this issue · comments

Hi there, I was trying to run the "testing/ltr_adhoc/testing_ltr_adhoc.py" but got the following error. I tried to use inds.long() but it does not work. Any idea?
Many thanks!

Traceback (most recent call last):
File "F:/PythonCodes/ptranking/testing/ltr_adhoc/testing_ltr_adhoc.py", line 132, in
evaluator.run(debug=debug, model_id=model_id, sf_id=sf_id, grid_search=grid_search,
File "F:\PythonCodes\ptranking\ptranking\ltr_adhoc\eval\ltr.py", line 582, in run
self.point_run(debug=debug, model_id=model_id, sf_id=sf_id,
File "F:\PythonCodes\ptranking\ptranking\ltr_adhoc\eval\ltr.py", line 517, in point_run
self.kfold_cv_eval(data_dict=data_dict, eval_dict=eval_dict, model_para_dict=model_para_dict,
File "F:\PythonCodes\ptranking\ptranking\ltr_adhoc\eval\ltr.py", line 366, in kfold_cv_eval
cv_tape.fold_evaluation(model_id=model_id, ranker=ranker, test_data=test_data, max_label=max_label, fold_k=fold_k)
File "F:\PythonCodes\ptranking\ptranking\ltr_adhoc\eval\parameter.py", line 725, in fold_evaluation
ranker.adhoc_performance_at_ks(test_data=test_data, ks=self.cutoffs, device='cpu', max_label=max_label)
File "F:\PythonCodes\ptranking\ptranking\base\ranker.py", line 229, in adhoc_performance_at_ks
batch_ndcg_at_ks = torch_ndcg_at_ks(batch_predict_rankings=batch_predict_rankings,
File "F:\PythonCodes\ptranking\ptranking\metric\adhoc\adhoc_metric.py", line 280, in torch_ndcg_at_ks
batch_ideal_dcg_at_ks = batch_ideal_dcgs[:, inds]
IndexError: tensors used as indices must be long, byte or bool tensors

Process finished with exit code 1

@fm-chen hi, sorry for the late reply. Can you show me the type of inds in your case? thanks.

For me using inds.long() solved the problem, but I had to add the ".long()" to other "inds" along the code