A Python implementation of Tree Kernels


This page contains a set of classes to handle trees and compute kernel functions on them. Python has been chosen as the implementation language since it is portable and it is appropriate for fast prototyping.

 

A Brief Description

Currently there are 2 files:

  • tree.py: a set of classes for reading, writing and computing statistics on trees. A tree can be written in prolog format.
  • tree_kernels.py: a set of classes implementing tree kernel functions. Currently the Subtree Kernel, the Subset Tree Kernel, the Partial Tree Kernel and the Position Aware Kernel have been implemented.

 

Usage

An example of a python script, which prints a kernel matrix to the standard output, is the following:

import tree_kernels
import tree
lambda # kernel parameter
dat = tree.Dataset()
dat.loadFromFilePrologFormat("inputdataset.txt")
k = tree_kernels.KernelST(lambda)
k.printKernelMatrix(dat)
  

 

Download

The software can be downloaded here.

 

Acknowledgment
This work was supported by the Italian Ministry of Education, University, and Research (MIUR) under Project PRIN 2009 2009LNP494_005.