learning-to-rank icon indicating copy to clipboard operation
learning-to-rank copied to clipboard

Try to solve some problems about "virtual environmet" , "predict", "save and load model"

Open xdn-github opened this issue 1 year ago • 0 comments

Thanks fullflu for create this repo, which helps me a lot in my project.

Here are some notes, whick may help you use this repo better!

How to create Virtual Environment in windows?

At first, I try create Virtual Environment following the Requirements in the README. But I failed.

So I try to create Virtual Environment using below code in cmd:

conda create -n ltr_env python=2.7.6

conda activate ltr_env

conda install six=1.10.0

conda install numpy=1.11.1

conda install pandas=0.17.1

conda install chainer=1.24.0

   # notice chainer is 1.24.0, different from README

AttributeError: 'DataFrame' object has no attribute 'score'

When I use:

python listnet.py -trvf "datasets.csv" -tesf "datasets_test.csv" -tenf "datasets_test_noscore.csv" -vr 0.5

AttributeError comes out. I find that progarm try to read ‘score‘ column of datasets_test_noscore.csv file. That’s impossilble as datasets_test_noscore.csv don’t have this column as README defined.

TO SOLVE IT,  just make row 68 and row 69 in listnet.py become the comment, just like below 图片

AttributeError: 'ListNet' object has no attribute 'test_T'

I only want to predict noscore, so I use:

python listnet.py -trvf "datasets.csv" -tenf "datasets_test_noscore.csv" -vr 0.5

But I get AttributeError as below.


        Traceback (most recent call last):

          File "listnet.py", line 244, in <module>

            agent.test(filename = test_noscore_filename, noscore = True)

          File "listnet.py", line 185, in test

            for j in range(self.test_T):

        AttributeError: 'ListNet' object has no attribute 'test_T'

I find that -tesf "datasets_test.csv" will give the 'test_T'. But I only use  -tenf "datasets_test_noscore.csv" which leads this error.

TO SOLVE IT, One simple way is to copy a new file from "datasets_test_noscore.csv" and  named as "datasets_test.csv", and add a new column named “score“ in the new file. Just a empty ‘score‘ column is OK. Finally use cmd below, and you can only make prediction!

python listnet.py -trvf "datasets.csv" -tesf "datasets_test.csv" -tenf "datasets_test_noscore.csv" -vr 0.5

NOTICE number of data in “datasets_test.csv” will influence number of data in “new_results.csv”!!. Logically, number of data in “new_results.csv” should be the same as "datasets_test_noscore.csv". BUT here, number of data in “new_results.csv” is the same as "datasets_test.csv". That’s why I suggust make a copy of  "datasets_test_noscore.csv" and name it as “datasets_test.csv”. This will  keep  number of data in “new_results.csv” correct !

Prediction is sorted, how to solve?

this problem is solved , you can refer [Prediction is sorted, how to solve? · Issue #5 · fullflu/learning-to-rank (github.com)](https://github.com/fullflu/learning-to-rank/issues/5)

How can I save or load model?

This repo didn’t make function to achieve this.  I change a bit code to make it. I wouldn’t  make a Pull Requests as it just can run, I am not completely read all codes and make a good function to achieve it.

If you just want to save and load model, you can try it in my fork version [xdn-github/learning-to-rank: learning to rank repository](https://github.com/xdn-github/learning-to-rank/tree/master)

TO USE IT

in training, add --save_name config to save model

in predicting, add --load_name config to load model for predcition

SAMPLE

below will training model and save model as “ltr_model.model“

python listnet.py -trvf "datasets.csv" -tesf "datasets_test.csv" -tenf "datasets_test_noscore.csv" -vr 0.5 --save_name "ltr_model.model"

below will load model “ltr_model.model“ and make predction. NOTICE please keep -trvf  "datasets.csv" config. Although cmd below will not need to train, drop  -trvf  "datasets.csv" will triger error I am unable to handle. So just keep it, or you can try to solve the problem.

python listnet.py -trvf "datasets.csv" -tesf "datasets_test.csv" -tenf "datasets_test_noscore.csv" -vr 0.5 --load_name "ltr_model.model"

xdn-github avatar Mar 10 '24 08:03 xdn-github