Tree Kernels

In this example, we see how to instantiate a Partial Tree Kernel, and use it on a Question Classification dataset. The PTK function will compute a similarity measure diretly on a Tree Representation of an example. For example, the second representation in the next code snippet is a representation of a tree with round brackets. Note that, the boundaries for a Tree Representation is |BT| |ET|.
The :tree (and :bow on the vector representation) are used in KeLP to assign a label to each representation. During the kernel definition phase, these labels are used to indicate which representation must be used during the kernel computation.

The following code, reads a dataset compliant with these representations, instantiate a Partial Tree Kernel with some parameters (refers to the documentation for details).

In this example, the learning algorithm used is a SVM implementaion based on the C-SVM implementation of LibSVM.

Here, we introduce also the concept of multi-classification. A One-vs-All classifier is instantiated. It must know what is the base algorithm to be applied, and what are the labels to be learned.
The OneVsAllLearning class will be responsible to “copy” the base algorithms, and to perform the learning according to the One-Vs-All strategy.

Then, a PredictionFunction can be obtained, in particular a OneVsAllClassifier object.