OpenKernel Quick Tour
Using the library
In this quick tour, we will focus on the command-line utilities and LIBSVM plugin.
The command-line utilities are available in the
Preparing your data
In order to use the library, you need to represent each point in your dataset as an
, a weighted transducer (or automaton) represented in the binary format used
by the OpenFst library
. The OpenFst quick tour
contains the relevant information for accomplishing this.
A dataset is then represented by a Fst archive
file) or by a text file containing a list of
file (specified using an
absolute path). The i
-th entry in the
archive or in the
list being the
representing the i
in the dataset.
This dataset should contain both your training and testing data.
An example of dataset, a subset of Reuters-21578
, is provided with the library
and can be used to become familiar with its usage.
Creating an n -gram kernel
utility can be used to generate an n-gram kernel. The
specifies the n-gram order and the
option the size of the alphabet (i.e.
the maximum label id). The
specifies the dataset the kernel is operating
on. The output of
file (for kernel archive)
that contains both the kernel function and the dataset it is defined on.
$ klngram -order=3 -sigma=2 data.far > 3-gram.kar
In addition to n-gram kernels, the library provides tools for the creation of gappy n-gram kernels (
mismatch kernels (
) and arbitrary rational kernels (
Kernels can also be combined by taking their sum (
) or product (
can be composed with a polynomial (
), a gaussian (
a sigmoid (
Generating a kernel matrix
The kernel matrix corresponding to the evaluation of the kernel on the specified dataset
can be computed using the
utility as shown here:
$ kleval 3-gram.kar > 3-gram.matrix
Assuming the size of the dataset is n
, the result will be a text file with n
floats on each line. The j
-th value on the i
-th line correspond to the value
of the kernel for the i
-th and j
-th points in the dataset.
The kernel matrix can be partially computed by restricting the
set of values to be evaluated using the
flags. Assuming the lines and columns are indexed from 0 to n
- 1, the following
command can be used to only compute the (i
) value if and only if 10 ≤ i
kleval -xmin=10 -ymin=10 -xmax=20 -ymax=20 3-gram.kar
option will generate a file in the format used by LIBSVM to specify
precomputed kernels. LIBSVM users are however encouraged to use the LIBSVM plugin
as described below.
option allows the kernel matrix to be stored in a kar file in addition to
the kernel function and dataset.
$ kleval 3-gram.kar > 3-gram.matrix.kar
Using the LIBSVM plugin
The OpenKernel library package includes a modified version of
that allows the definition
of arbitrary plugins to handle the kernel computations. This version of LIBSVM is available
sub-directory. A specific plugin to allow the use of the OpenKernel library
with libsvm is provided in the
sub-directory. In order to use this plugin, you
need to add the path to the
sub-directory to your dynamic loader path (
on MacOS X).
The training and test dataset need to be specified in the usual LIBSVM format (if you are not familiar with
LIBSVM check out the official website
file in the
For instance a text file
specifies that the 1st, 2nd and 4th points of the dataset are in the training set with labels 1, -1 and 1.
And a text file
specifies that the 3rd and 5th points of the dataset are in the test set (the labels are optional here and
will only be used for scoring).
utility needs to be called with two additional options. The
specifies the type of kernel and should be
when using the OpenKernel library.
option specifies the
file defining the kernel and dataset to be used.
All the other
options are still available.
$ svm-train -k openkernel -K 3-gram.kar train 3-gram.model
utility does not required any additional options. The kernel information
is included in the
$ svm-predict test 3-gram.model 3-gram.pred
When using the LIBSVM plugin, the kernel values are computed "on the fly" as requested by the LIBSVM utilities.
When performing several experiments using the same kernel (on the same dataset), it is recommended, in order to
avoid unnecessary computations, to
first compute the (partial) kernel matrix using
and use the resulting
file as a parameter
to the LIBSVM utilities.
- 08 Oct 2007