shoelace icon indicating copy to clipboard operation
shoelace copied to clipboard

How do I use shoelace for prediction?

Open hedgy123 opened this issue 6 years ago • 0 comments

Hi,

Thank you for making your code available!

I was wondering if you could give me some directions for how to actually use the trained neural network for predicting query scores. That is, supose I have a training file where each line looks like this:

  1 qid:25662 1:5.0 2:1.0 3:1.0

and I trained your model on it following your example code in README:

from shoelace.dataset import LtrDataset
from shoelace.iterator import LtrIterator
from shoelace.loss.listwise import listnet
from chainer import training, optimizers, links, Chain
from chainer.training import extensions

# Load data and set up iterator
with open('./path/to/ranksvm.txt', 'r') as f:
    training_set = LtrDataset.load_txt(f)
training_iterator = LtrIterator(training_set, repeat=True, shuffle=True)

# Create neural network with chainer and apply loss function
predictor = links.Linear(None, 1)
class Ranker(Chain):
    def __call__(self, x, t):
        return listnet(self.predictor(x), t)
loss = Ranker(predictor=predictor)

# Build optimizer, updater and trainer
optimizer = optimizers.Adam()
optimizer.setup(loss)
updater = training.StandardUpdater(training_iterator, optimizer)
trainer = training.Trainer(updater, (40, 'epoch'))
trainer.extend(extensions.ProgressBar())

# Train neural network
trainer.run()

Now I have a test file where each line looks like this:

  qid:34562 1:2.0 2:3.0 3:5.0  

How do I use the trainer above to predict the query score?

Thanks very much!

hedgy123 avatar Apr 18 '18 16:04 hedgy123