SVMrank

Support Vector Machine for Ranking

Overview

SVMrank is an instance of SVMstruct for
efficiently training Ranking SVMs
as defined in [Joachims, 2002c]. SVMrank solves the same optimization problem
as SVMlight
with the '-z p' option, but it is much
faster. On the LETOR 3.0 dataset it takes about a second to train on any of the
folds and datasets. The algorithm for solving the quadratic program is a
straightforward extension of the
ROC-area optimization algorithm described in [Joachims, 2006]
for multiple rankings using the one-slack formulation of SVMstruct.
However, since I did not want to spend more than an afternoon on coding SVMrank,
I only implemented a simple separation oracle that is quadratic in the number of
items in each ranking (not the O[k*log k] separation oracle described in
[Joachims, 2006]). While this makes the implementation
not very suitable for the special case of ordinal regression [Herbrich et al,
1999], it means that it is nevertheless fast for small rankings (i.e. k<1000)
and scales linearly in the number of rankings (i.e. queries).

Source Code

The program is free for scientific use. Please contact me, if you are planning to use the software for commercial purposes. The software must not be further distributed without prior permission of the author.
If you use SVMrank in your scientific work, please cite as

The implementation was developed on
Linux with gcc, but compiles also on Solaris, Cygwin, Windows (using MinGW) and
Mac (after small modifications, see FAQ).
The source code is available at the following location:

This expands the archive into the current directory, which now contains all relevant files. You can compile SVMrank using the command:

make

This will produce the executables svm_rank_learn and svm_rank_classify. If the system does not compile properly, check this FAQ.

How to Use

SVMrank consists of a learning module (svm_rank_learn) and a module
for making predictions (svm_rank_classify). SVMrank uses the same input and output file formats as SVM-light,
and its usage is identical to SVMlight with the '-z p'
option. You call it like

svm_rank_learn -c 20.0 train.dat model.dat

which trains a Ranking SVM on the training set train.dat and outputs the learned rule to model.dat using the regularization parameter C set to
20.0. However, the interpretation of the parameter C in SVMrank
is different from SVMlight. In particular, Clight = Crank/n,
where n is the number of training queries (i.e. number of different
qid's in the training set). Most of the other options come from SVMstruct and
SVMlight and are described there.
Only the "application-specific options" listed below are particular to
SVMrank.

SVMrank learns an unbiased linear classification rule (i.e.
a rule w*x without explicit threshold). The loss function to be
optimized is selected using the '-l' option. Loss function '1' is identical to
the one used in the ranking mode of SVMlight, and it optimizes
the total number of swapped pairs. Loss function '2' is a normalized version of
'1'. For each query, it divides the number of swapped pairs by the maximum
number of possibly swapped pairs for that query.

You can in principle use kernels in SVMrank using the '-t'
option just like in SVMlight, but it is painfully slow and you
are probably better off using SVMlight.

The file format of the training and test files is the same as for SVMlight
(see here for further details), with the exception that
the lines in the input files have to be sorted by increasing qid. The first lines may contain comments and are ignored if they start with #. Each of the following lines represents one training example and is of the following format:

The target value and each of the feature/value pairs are separated by a space
character. Feature/value pairs MUST be ordered by increasing feature number.
Features with value zero can be skipped. The target value defines the order of
the examples for each query. Implicitly,
the target values are used to generated pairwise preference constraints as
described in
[Joachims, 2002c].
A preference constraint is included for all pairs of examples in theexample_file,
for which the target value differs. The special feature "qid" can be used to
restrict the generation of constraints. Two examples are considered for a
pairwise preference constraint only if the value of "qid" is the same. For
example, given theexample_file

The result of svm_rank_learn is the model that is learned from the training data in
train.dat. The model is written to model.dat. To make predictions on test examples, svm_rank_classify reads this file. svm_rank_classify is called as follows:

svm_rank_classify test.dat model.dat predictions

For each line in test.dat, the predicted ranking score is written to
the file predictions. There is one line per test example in predictions in the same order as in
test.dat.
From these scores, the ranking can be recovered via sorting.

The output in the predictions file can be used to rank the test examples. If
you do so, you will see that it predicts the correct ranking. The values in the
predictions file do not have a meaning in an absolute sense - they are only used
for ordering. The equivalent call for SVM-light is

svm_learn -z p -c 1 example3/train.dat example3/model

Note the different value for c, since we have 3 training rankings.

It can also be interesting to look at the "training error" of the ranking SVM.
The equivalent of training error for a ranking SVM is the number of training
pairs that are misordered by the learned model. To find those pairs, one can
apply the model to the training file:

Again, the predictions file shows the ordering implied by the model. The
model ranks all training examples correctly.

Note that ranks are comparable only between examples with the same qid. Note
also that the target value (first value in each line of the data files) is only
used to define the order of the examples. Its absolute value does not matter, as
long as the ordering relative to the other examples with the same qid remains
the same.

Disclaimer

This software is free only for non-commercial use. It must not be distributed without prior permission of the author. The author is not responsible for implications from the use of this software.