General Conditional Random Field (CRF) Toolbox for Matlab

General Conditional Random Field (CRF) Toolbox for Matlab

Written by Kevin Murphy, 2004.
Last updated 20 January 2006.

This toolbox supports inference and learning for CRFs, with the following topologies: chains, 2D lattices, arbitrary graphs. It assumes all potentials are pairwise. Inference is done using belief propagation (my BPMRF2 and BPlattice code). For chains and trees, this is exact, otherwise it is approximate.

Download

Click here Unziping creates a directory called CRFall, which contains several subdirectories.

This code contains netlab 3.3 bundled in.

Installation

Assuming you unzip it to C:/CRFall...
>> addpath(genpath('C:/CRFall'))
>> testCRF
This will run various simple 1D and 2D demos. Look at the source code for more details...

Documentation

The code is modelled on netlab.

Represenation

Several kinds of CRF structures are supported:

All models have potentials defined as follows:

Inference

crfchain always uses crfchaininfer (forwards-backwards) for inference. For general CRFs, crfinfer can call several possible inference engines: To use an inference engine, you have to call its constructor. For the 2D case, you can proceed as follows. To specify an infernece engine, do the following
net.infEngineName = 'lattice2hmmCell'; % exact 
net.infEngineName = 'bp_mrf2_lattice';
net.infEngineName = 'bploopy';
Then call crf2DdemoInfEngine, which will call one of
lattice2hmmCellEngine
bp_mrf2_lattice2Engine
bploopyEngine.
(Unfortunately these constructors have different arguments.)
Once these structures are initialized, crfErrAndGrad will call
lattice2hmmCellInfer
bp_mrf2_latticeInfer
bploopyInfer
as appropriate.

Learning

Currently we support the following max likelihood parameter learning engines. crfchaintrain has a limited number of gradient-based methods. crf2DdemoTrain has several more gradient-based methods.

The gradient methods use the following pieces: