shiba24 / learning2rank

Learning to rank with neuralnet - RankNet and ListNet
481 stars 141 forks source link

listwise_cost #1

Closed mhidy closed 7 years ago

mhidy commented 8 years ago

I want to train ListNet to re-rank retrieved document so I got this error Traceback (most recent call last): File "ranking/rank/train.py", line 88, in model.fit(X_train, y_train, X_test, y_test, Query, Query2, batchsize, n_epoch, n_hidden1, n_hidden2) File "/home/ama/mhidy/nn_ranking/RankNet_chainer/ranking/rank/ListNet.py", line 193, in fit self.trainModel(train_X, train_y, validate_X, validate_y, query, query_validate, n_epoch, batchsize) File "/home/ama/mhidy/nn_ranking/RankNet_chainer/ranking/rank/ListNet.py", line 160, in trainModel self.optimizer.update(self.model, x, t) File "/home/ama/mhidy/.local/lib/python2.7/site-packages/chainer/optimizer.py", line 392, in update loss = lossfun(*args, *kwds) File "/home/ama/mhidy/nn_ranking/RankNet_chainer/ranking/rank/ListNet.py", line 61, in call self.loss = self.listwise_cost(y, t) File "/home/ama/mhidy/nn_ranking/RankNet_chainer/ranking/rank/ListNet.py", line 91, in listwise_cost return - np.sum(self.topkprob(list_ans) np.log(self.topkprob(list_pred))) File "/home/ama/mhidy/nn_ranking/RankNet_chainer/ranking/rank/ListNet.py", line 85, in topkprob vec_sort = np.sort(vec)[-1::-1] File "/home/ama/mhidy/.local/lib/python2.7/site-packages/numpy/core/fromnumeric.py", line 824, in sort a = asanyarray(a).copy(order="K") File "/home/ama/mhidy/.local/lib/python2.7/site-packages/numpy/core/numeric.py", line 533, in asanyarray return array(a, dtype, copy=False, order=order, subok=True) File "/home/ama/mhidy/.local/lib/python2.7/site-packages/chainer/functions/array/get_item.py", line 71, in get_item return GetItem(slices)(x) File "/home/ama/mhidy/.local/lib/python2.7/site-packages/chainer/function.py", line 189, in call self._check_data_type_forward(in_data) File "/home/ama/mhidy/.local/lib/python2.7/site-packages/chainer/function.py", line 271, in _check_data_type_forward six.raise_from( AttributeError: 'module' object has no attribute 'raise_from'

shiba24 commented 8 years ago

Hi @mhidy thank you for the report. Actually listwise_cost seems to be not implemented properly yet, although the functions are inside the file. In the current version, the cost function is only jensen-shannon divergence. (please see https://github.com/shiba24/learning2rank/blob/master/rank/ListNet.py#L29 )

In order to make listwise_cost available, we need to impement listwise_cost function with not numpy, but chainer standard functions ( http://docs.chainer.org/en/stable/reference/functions.html ). I will implement it later on, however, i will appreciate it if you commit this repo!

mhidy commented 8 years ago

Hi @shiba24 many thanks for your response.

fullflu commented 7 years ago

Hi @shiba24 and @mhidy I uploaded a chainer implementation of ListNet with listwise cost based on top-1 probability. FYI: https://github.com/fullflu/learning-to-rank

shiba24 commented 7 years ago

Thank you @fullflu I will modify my own code so that the both (js divergence and top k probability) are compatible and selectable in this repo!