edu.umass.cs.mallet.base.fst
Class CRF4

java.lang.Object
  extended byedu.umass.cs.mallet.base.fst.Transducer
      extended byedu.umass.cs.mallet.base.fst.CRF4
All Implemented Interfaces:
java.io.Serializable
Direct Known Subclasses:
CRF_PL, MEMM

public class CRF4
extends Transducer
implements java.io.Serializable

See Also:
Serialized Form

Nested Class Summary
 class CRF4.MaximizableCRF
           
static class CRF4.State
           
protected static class CRF4.TransitionIterator
           
 
Nested classes inherited from class edu.umass.cs.mallet.base.fst.Transducer
Transducer.BeamLattice, Transducer.Lattice, Transducer.ViterbiLattice, Transducer.ViterbiPath, Transducer.ViterbiPath_NBest, Transducer.ViterbiPathBeam, Transducer.ViterbiPathBeamB, Transducer.ViterbiPathBeamFB, Transducer.ViterbiPathBeamKL
 
Field Summary
 boolean printGradient
           
protected  boolean someTrainingDone
           
static int VITERBI
           
static int VITERBI_BBEAM
           
static int VITERBI_FBBEAM
           
static int VITERBI_FBEAM
           
static int VITERBI_FBEAMKL
           
 
Fields inherited from class edu.umass.cs.mallet.base.fst.Transducer
INFINITE_COST, inputPipe, outputPipe, ZERO_COST
 
Constructor Summary
CRF4(Alphabet inputAlphabet, Alphabet outputAlphabet)
           
CRF4(CRF4 other)
          Create a CRF whose states and weights are a copy of noes from another CRF.
CRF4(Pipe inputPipe, Pipe outputPipe)
           
 
Method Summary
 void addFullyConnectedStates(java.lang.String[] stateNames)
           
 void addFullyConnectedStatesForBiLabels()
           
 void addFullyConnectedStatesForLabels()
           
 void addFullyConnectedStatesForThreeQuarterLabels(InstanceList trainingSet)
           
 void addFullyConnectedStatesForTriLabels()
           
 java.lang.String addOrderNStates(InstanceList trainingSet, int[] orders, boolean[] defaults, java.lang.String start, java.util.regex.Pattern forbidden, java.util.regex.Pattern allowed, boolean fullyConnected)
          Assumes that the CRF's output alphabet contains Strings.
 void addSelfTransitioningStateForAllLabels(java.lang.String name)
           
 void addStartState()
           
 void addStartState(java.lang.String name)
           
 void addState(java.lang.String name, double initialCost, double finalCost, java.lang.String[] destinationNames, java.lang.String[] labelNames)
           
 void addState(java.lang.String name, double initialCost, double finalCost, java.lang.String[] destinationNames, java.lang.String[] labelNames, java.lang.String[] weightNames)
           
 void addState(java.lang.String name, double initialCost, double finalCost, java.lang.String[] destinationNames, java.lang.String[] labelNames, java.lang.String[][] weightNames)
           
 void addState(java.lang.String name, java.lang.String[] destinationNames)
           
 void addStatesForBiLabelsConnectedAsIn(InstanceList trainingSet)
          Add states to create a second-order Markov model on labels, adding only those transitions the occur in the given trainingSet.
 void addStatesForHalfLabelsConnectedAsIn(InstanceList trainingSet)
          Add as many states as there are labels, but don't create separate weights for each source-destination pair of states.
 void addStatesForLabelsConnectedAsIn(InstanceList trainingSet)
          Add states to create a first-order Markov model on labels, adding only those transitions the occur in the given trainingSet.
 void addStatesForThreeQuarterLabelsConnectedAsIn(InstanceList trainingSet)
          Add as many states as there are labels, but don't create separate observational-test-weights for each source-destination pair of states---instead have all the incoming transitions to a state share the same observational-feature-test weights.
 void estimate()
           
 void evaluate(TransducerEvaluator eval, InstanceList testing)
          This method is deprecated.
 void freezeWeights(int weightsIndex)
          Freezes a set of weights to their current values.
 void freezeWeights(java.lang.String weightsName)
          Freezes a set of weights to their current values.
 double[] getDefaultWeights()
           
 double getGaussianPriorVariance()
           
 Alphabet getInputAlphabet()
           
 CRF4.MaximizableCRF getMaximizableCRF(InstanceList ilist)
           
 Alphabet getOutputAlphabet()
           
 double getParameter(int sourceStateIndex, int destStateIndex, int featureIndex, double value)
          Only gets the parameter from the first group of parameters.
 double getParametersAbsNorm()
           
 Transducer.State getState(int index)
           
 CRF4.State getState(java.lang.String name)
           
 int getTransductionType()
           
 double getUseHyperbolicPriorSharpness()
           
 double getUseHyperbolicPriorSlope()
           
 boolean getUseSparseWeights()
           
 SparseVector[] getWeights()
           
 SparseVector getWeights(int weightIndex)
           
 SparseVector getWeights(java.lang.String weightName)
           
 int getWeightsIndex(java.lang.String weightName)
          Increase the size of the weights[] parameters to match (a new, larger) input Alphabet size
 java.lang.String getWeightsName(int weightIndex)
           
 java.util.Iterator initialStateIterator()
           
 boolean isTrainable()
           
protected  CRF4.State newState(java.lang.String name, int index, double initialCost, double finalCost, java.lang.String[] destinationNames, java.lang.String[] labelNames, java.lang.String[][] weightNames, CRF4 crf)
           
 int numStates()
           
 Sequence[] predict(InstanceList testing)
          This method is deprecated.
 void print()
           
 void print(java.io.PrintWriter out)
           
 void reset()
           
 void setAsStartState(CRF4.State state)
           
 void setDefaultWeight(int widx, double val)
           
 void setDefaultWeights(double[] w)
           
 void setFeatureSelection(int weightIdx, FeatureSelection fs)
           
 void setGaussianPriorVariance(double p)
           
 void setHyperbolicPriorSharpness(double p)
           
 void setHyperbolicPriorSlope(double p)
           
 void setParameter(int sourceStateIndex, int destStateIndex, int featureIndex, double value)
          Only sets the parameter from the first group of parameters.
 void setTrainable(boolean f)
           
 void setTransductionType(int transductionType)
           
 void setUseHyperbolicPrior(boolean f)
           
 void setUseSomeUnsupportedTrick(boolean b)
          Sets whether to use the 'some unsupported trick.' This trick is, if training a CRF where some training has been done and sparse weights are used, to add a few weights for feaures that do not occur in the tainig data.
 void setUseSparseWeights(boolean b)
           
 void setWeights(int weightsIndex, SparseVector transitionWeights)
           
 void setWeights(SparseVector[] m)
           
 void setWeights(java.lang.String weightName, SparseVector transitionWeights)
           
 void setWeightsDimensionAsIn(InstanceList trainingData)
           
 void setWeightsDimensionDensely()
           
 boolean train(InstanceList ilist)
           
 boolean train(InstanceList ilist, InstanceList validation, InstanceList testing)
           
 boolean train(InstanceList ilist, InstanceList validation, InstanceList testing, TransducerEvaluator eval)
           
 boolean train(InstanceList ilist, InstanceList validation, InstanceList testing, TransducerEvaluator eval, int numIterations)
           
 boolean train(InstanceList training, InstanceList validation, InstanceList testing, TransducerEvaluator eval, int numIterations, int numIterationsPerProportion, double[] trainingProportions)
           
 boolean trainWithFeatureInduction(InstanceList trainingData, InstanceList validationData, InstanceList testingData, TransducerEvaluator eval, int numIterations, int numIterationsBetweenFeatureInductions, int numFeatureInductions, int numFeaturesPerFeatureInduction, double trueLabelProbThreshold, boolean clusteredFeatureInduction, double[] trainingProportions)
           
 boolean trainWithFeatureInduction(InstanceList trainingData, InstanceList validationData, InstanceList testingData, TransducerEvaluator eval, int numIterations, int numIterationsBetweenFeatureInductions, int numFeatureInductions, int numFeaturesPerFeatureInduction, double trueLabelProbThreshold, boolean clusteredFeatureInduction, double[] trainingProportions, java.lang.String gainName)
           
 Sequence transduce(java.lang.Object unpipedInput)
           
 Sequence transduce(Sequence input)
          Converts the given sequence into another sequence according to this transducer.
 void unfreezeWeights(java.lang.String weightsName)
          Unfreezes a set of weights.
 Transducer.ViterbiPath viterbiPath(Sequence inputSequence, boolean keepLattice)
           
 void write(java.io.File f)
           
 
Methods inherited from class edu.umass.cs.mallet.base.fst.Transducer
averageTokenAccuracy, averageTokenAccuracy, canIterateAllTransitions, forwardBackward, forwardBackward, forwardBackward, forwardBackward, forwardBackward, forwardBackward, forwardBackward, forwardBackward, forwardBackwardBeam, forwardBackwardBeam, forwardBackwardBeam, forwardBackwardBeam, forwardBackwardBeam, forwardBackwardBeam, forwardBackwardBeam, forwardBackwardBeam, generatePath, getBeamWidth, getInputPipe, getNstatesExpl, getOutputPipe, getViterbiLattice, incIter, isGenerative, pipe, setBeamWidth, setCurIter, setKLeps, setRmin, setUseForwardBackwardBeam, stateIndexOfString, sumNegLogProb, viterbiPath_NBest, viterbiPath_NBest, viterbiPath, viterbiPath, viterbiPath, viterbiPathBeam, viterbiPathBeam, viterbiPathBeam, viterbiPathBeamB, viterbiPathBeamB, viterbiPathBeamB, viterbiPathBeamB, viterbiPathBeamFB, viterbiPathBeamFB, viterbiPathBeamFB, viterbiPathBeamFB, viterbiPathBeamKL, viterbiPathBeamKL, viterbiPathBeamKL
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

someTrainingDone

protected boolean someTrainingDone

printGradient

public boolean printGradient

VITERBI

public static final int VITERBI
See Also:
Constant Field Values

VITERBI_FBEAM

public static final int VITERBI_FBEAM
See Also:
Constant Field Values

VITERBI_BBEAM

public static final int VITERBI_BBEAM
See Also:
Constant Field Values

VITERBI_FBBEAM

public static final int VITERBI_FBBEAM
See Also:
Constant Field Values

VITERBI_FBEAMKL

public static final int VITERBI_FBEAMKL
See Also:
Constant Field Values
Constructor Detail

CRF4

public CRF4(Pipe inputPipe,
            Pipe outputPipe)

CRF4

public CRF4(Alphabet inputAlphabet,
            Alphabet outputAlphabet)

CRF4

public CRF4(CRF4 other)
Create a CRF whose states and weights are a copy of noes from another CRF.

Method Detail

getInputAlphabet

public Alphabet getInputAlphabet()

getOutputAlphabet

public Alphabet getOutputAlphabet()

setUseHyperbolicPrior

public void setUseHyperbolicPrior(boolean f)

setHyperbolicPriorSlope

public void setHyperbolicPriorSlope(double p)

setHyperbolicPriorSharpness

public void setHyperbolicPriorSharpness(double p)

getUseHyperbolicPriorSlope

public double getUseHyperbolicPriorSlope()

getUseHyperbolicPriorSharpness

public double getUseHyperbolicPriorSharpness()

setGaussianPriorVariance

public void setGaussianPriorVariance(double p)

getGaussianPriorVariance

public double getGaussianPriorVariance()

setUseSparseWeights

public void setUseSparseWeights(boolean b)

getUseSparseWeights

public boolean getUseSparseWeights()

setUseSomeUnsupportedTrick

public void setUseSomeUnsupportedTrick(boolean b)
Sets whether to use the 'some unsupported trick.' This trick is, if training a CRF where some training has been done and sparse weights are used, to add a few weights for feaures that do not occur in the tainig data.

This generally leads to better accuracy at only a small memory cost.

Parameters:
b - Whether to use the trick

getTransductionType

public int getTransductionType()

setTransductionType

public void setTransductionType(int transductionType)

newState

protected CRF4.State newState(java.lang.String name,
                              int index,
                              double initialCost,
                              double finalCost,
                              java.lang.String[] destinationNames,
                              java.lang.String[] labelNames,
                              java.lang.String[][] weightNames,
                              CRF4 crf)

addState

public void addState(java.lang.String name,
                     double initialCost,
                     double finalCost,
                     java.lang.String[] destinationNames,
                     java.lang.String[] labelNames,
                     java.lang.String[][] weightNames)

addState

public void addState(java.lang.String name,
                     double initialCost,
                     double finalCost,
                     java.lang.String[] destinationNames,
                     java.lang.String[] labelNames,
                     java.lang.String[] weightNames)

addState

public void addState(java.lang.String name,
                     double initialCost,
                     double finalCost,
                     java.lang.String[] destinationNames,
                     java.lang.String[] labelNames)

addState

public void addState(java.lang.String name,
                     java.lang.String[] destinationNames)

addFullyConnectedStates

public void addFullyConnectedStates(java.lang.String[] stateNames)

addFullyConnectedStatesForLabels

public void addFullyConnectedStatesForLabels()

addStartState

public void addStartState()

addStartState

public void addStartState(java.lang.String name)

setAsStartState

public void setAsStartState(CRF4.State state)

addStatesForLabelsConnectedAsIn

public void addStatesForLabelsConnectedAsIn(InstanceList trainingSet)
Add states to create a first-order Markov model on labels, adding only those transitions the occur in the given trainingSet.


addStatesForHalfLabelsConnectedAsIn

public void addStatesForHalfLabelsConnectedAsIn(InstanceList trainingSet)
Add as many states as there are labels, but don't create separate weights for each source-destination pair of states. Instead have all the incoming transitions to a state share the same weights.


addStatesForThreeQuarterLabelsConnectedAsIn

public void addStatesForThreeQuarterLabelsConnectedAsIn(InstanceList trainingSet)
Add as many states as there are labels, but don't create separate observational-test-weights for each source-destination pair of states---instead have all the incoming transitions to a state share the same observational-feature-test weights. However, do create separate default feature for each transition, (which acts as an HMM-style transition probability).


addFullyConnectedStatesForThreeQuarterLabels

public void addFullyConnectedStatesForThreeQuarterLabels(InstanceList trainingSet)

addFullyConnectedStatesForBiLabels

public void addFullyConnectedStatesForBiLabels()

addStatesForBiLabelsConnectedAsIn

public void addStatesForBiLabelsConnectedAsIn(InstanceList trainingSet)
Add states to create a second-order Markov model on labels, adding only those transitions the occur in the given trainingSet.


addFullyConnectedStatesForTriLabels

public void addFullyConnectedStatesForTriLabels()

addSelfTransitioningStateForAllLabels

public void addSelfTransitioningStateForAllLabels(java.lang.String name)

addOrderNStates

public java.lang.String addOrderNStates(InstanceList trainingSet,
                                        int[] orders,
                                        boolean[] defaults,
                                        java.lang.String start,
                                        java.util.regex.Pattern forbidden,
                                        java.util.regex.Pattern allowed,
                                        boolean fullyConnected)
Assumes that the CRF's output alphabet contains Strings. Creates an order-n CRF with input predicates and output labels given by trainingSet and order, connectivity, and weights given by the remaining arguments.

Parameters:
trainingSet - the training instances
orders - an array of increasing non-negative numbers giving the orders of the features for this CRF. The largest number n is the Markov order of the CRF. States are n-tuples of output labels. Each of the other numbers k in orders represents a weight set shared by all destination states whose last (most recent) k labels agree. If orders is null, an order-0 CRF is built.
defaults - If non-null, it must be the same length as orders, with true positions indicating that the weight set for the corresponding order contains only the weight for a default feature; otherwise, the weight set has weights for all features built from input predicates.
start - The label that represents the context of the start of a sequence. It may be also used for sequence labels. If no label of this name exists, one will be added. Connection wills be added between the start label and all other labels, even if fullyConnected is false. This argument may be null, in which case no special start state is added.
forbidden - If non-null, specifies what pairs of successive labels are not allowed, both for constructing norder states or for transitions. A label pair (u,v) is not allowed if u + "," + v matches forbidden.
allowed - If non-null, specifies what pairs of successive labels are allowed, both for constructing norder states or for transitions. A label pair (u,v) is allowed only if u + "," + v matches allowed.
fullyConnected - Whether to include all allowed transitions, even those not occurring in trainingSet,
Returns:
The name of the start state.

getState

public CRF4.State getState(java.lang.String name)

setWeights

public void setWeights(int weightsIndex,
                       SparseVector transitionWeights)

setWeights

public void setWeights(java.lang.String weightName,
                       SparseVector transitionWeights)

getWeightsName

public java.lang.String getWeightsName(int weightIndex)

getWeights

public SparseVector getWeights(java.lang.String weightName)

getWeights

public SparseVector getWeights(int weightIndex)

getDefaultWeights

public double[] getDefaultWeights()

getWeights

public SparseVector[] getWeights()

setWeights

public void setWeights(SparseVector[] m)

setDefaultWeights

public void setDefaultWeights(double[] w)

setDefaultWeight

public void setDefaultWeight(int widx,
                             double val)

freezeWeights

public void freezeWeights(int weightsIndex)
Freezes a set of weights to their current values. Frozen weights are used for labeling sequences (as in transduce), but are not be modified by the train methods.

Parameters:
weightsIndex - Index of weight set to freeze.

freezeWeights

public void freezeWeights(java.lang.String weightsName)
Freezes a set of weights to their current values. Frozen weights are used for labeling sequences (as in transduce), but are not be modified by the train methods.

Parameters:
weightsName - Name of weight set to freeze.

unfreezeWeights

public void unfreezeWeights(java.lang.String weightsName)
Unfreezes a set of weights. Frozen weights are used for labeling sequences (as in transduce), but are not be modified by the train methods.

Parameters:
weightsName - Name of weight set to unfreeze.

setFeatureSelection

public void setFeatureSelection(int weightIdx,
                                FeatureSelection fs)

setWeightsDimensionAsIn

public void setWeightsDimensionAsIn(InstanceList trainingData)

setWeightsDimensionDensely

public void setWeightsDimensionDensely()

getWeightsIndex

public int getWeightsIndex(java.lang.String weightName)
Increase the size of the weights[] parameters to match (a new, larger) input Alphabet size


numStates

public int numStates()
Specified by:
numStates in class Transducer

getState

public Transducer.State getState(int index)
Specified by:
getState in class Transducer

initialStateIterator

public java.util.Iterator initialStateIterator()
Specified by:
initialStateIterator in class Transducer

isTrainable

public boolean isTrainable()
Overrides:
isTrainable in class Transducer

setTrainable

public void setTrainable(boolean f)
Overrides:
setTrainable in class Transducer

getParametersAbsNorm

public double getParametersAbsNorm()

setParameter

public void setParameter(int sourceStateIndex,
                         int destStateIndex,
                         int featureIndex,
                         double value)
Only sets the parameter from the first group of parameters.


getParameter

public double getParameter(int sourceStateIndex,
                           int destStateIndex,
                           int featureIndex,
                           double value)
Only gets the parameter from the first group of parameters.


reset

public void reset()

estimate

public void estimate()

transduce

public Sequence transduce(java.lang.Object unpipedInput)

transduce

public Sequence transduce(Sequence input)
Description copied from class: Transducer
Converts the given sequence into another sequence according to this transducer. For exmaple, robabilistic transducer may do something like Viterbi here. Subclasses of transducer may specify that they only accept special kinds of sequence.

Overrides:
transduce in class Transducer
Parameters:
input - Input sequence
Returns:
Sequence output by this transudcer

print

public void print()
Overrides:
print in class Transducer

print

public void print(java.io.PrintWriter out)

train

public boolean train(InstanceList ilist)
Overrides:
train in class Transducer

train

public boolean train(InstanceList ilist,
                     InstanceList validation,
                     InstanceList testing)

train

public boolean train(InstanceList ilist,
                     InstanceList validation,
                     InstanceList testing,
                     TransducerEvaluator eval)

train

public boolean train(InstanceList ilist,
                     InstanceList validation,
                     InstanceList testing,
                     TransducerEvaluator eval,
                     int numIterations)

train

public boolean train(InstanceList training,
                     InstanceList validation,
                     InstanceList testing,
                     TransducerEvaluator eval,
                     int numIterations,
                     int numIterationsPerProportion,
                     double[] trainingProportions)

trainWithFeatureInduction

public boolean trainWithFeatureInduction(InstanceList trainingData,
                                         InstanceList validationData,
                                         InstanceList testingData,
                                         TransducerEvaluator eval,
                                         int numIterations,
                                         int numIterationsBetweenFeatureInductions,
                                         int numFeatureInductions,
                                         int numFeaturesPerFeatureInduction,
                                         double trueLabelProbThreshold,
                                         boolean clusteredFeatureInduction,
                                         double[] trainingProportions)

trainWithFeatureInduction

public boolean trainWithFeatureInduction(InstanceList trainingData,
                                         InstanceList validationData,
                                         InstanceList testingData,
                                         TransducerEvaluator eval,
                                         int numIterations,
                                         int numIterationsBetweenFeatureInductions,
                                         int numFeatureInductions,
                                         int numFeaturesPerFeatureInduction,
                                         double trueLabelProbThreshold,
                                         boolean clusteredFeatureInduction,
                                         double[] trainingProportions,
                                         java.lang.String gainName)

predict

public Sequence[] predict(InstanceList testing)
This method is deprecated.


evaluate

public void evaluate(TransducerEvaluator eval,
                     InstanceList testing)
This method is deprecated.


write

public void write(java.io.File f)

getMaximizableCRF

public CRF4.MaximizableCRF getMaximizableCRF(InstanceList ilist)

viterbiPath

public Transducer.ViterbiPath viterbiPath(Sequence inputSequence,
                                          boolean keepLattice)