edu.stanford.nlp.ie.crf
Class CRFCliqueTree

java.lang.Object
  extended by edu.stanford.nlp.ie.crf.CRFCliqueTree
All Implemented Interfaces:
SequenceListener, SequenceModel

public class CRFCliqueTree
extends Object
implements SequenceModel, SequenceListener

Builds a CliqueTree (an array of FactorTable) and does message passing inference along it.

Author:
Jenny Finkel

Method Summary
 int backgroundIndex()
           
 String backgroundSymbol()
           
 Index classIndex()
           
 double condLogProbGivenNext(int position, int label, int[] nextLabels)
           
 double condLogProbGivenNext(int position, Object label, Object[] nextLabels)
           
 double condLogProbGivenPrevious(int position, int label, int[] prevLabels)
          Gives the probability of a tag at a single position conditioned on a sequence of previous labels.
 double condLogProbGivenPrevious(int position, Object label, Object[] prevLabels)
           
 ClassicCounter condLogProbsGivenNext(int position, int[] nextlabels)
           
 ClassicCounter condLogProbsGivenNext(int position, Object[] nextlabels)
           
 ClassicCounter condLogProbsGivenPrevious(int position, int[] prevlabels)
           
 ClassicCounter condLogProbsGivenPrevious(int position, Object[] prevlabels)
           
 double condProbGivenNext(int position, int label, int[] nextLabels)
           
 double condProbGivenNext(int position, Object label, Object[] nextLabels)
           
 double condProbGivenPrevious(int position, int label, int[] prevLabels)
           
 double condProbGivenPrevious(int position, Object label, Object[] prevLabels)
           
static CRFCliqueTree getCalibratedCliqueTree(double[][] weights, int[][][] data, Index[] labelIndices, int numClasses, Index classIndex, String backgroundSymbol)
           
static CRFCliqueTree getCalibratedCliqueTree(double[] weights, double wscale, int[][] weightIndices, int[][][] data, Index[] labelIndices, int numClasses, Index classIndex, String backgroundSymbol)
           
 double[] getConditionalDistribution(int[] sequence, int position)
          Computes the distribution over values of the element at position pos in the sequence, conditioned on the values of the elements in all other positions of the provided sequence.
 int getNumClasses()
           
 int getNumValues()
           
 int[] getPossibleValues(int position)
          0...leftWindow-1 etc are null, leftWindow...length+leftWindow-1 are words, length+leftWindow...length+leftWindow+rightWindow-1 are null;
 int leftWindow()
          How many positions to the left a position is dependent on.
 int length()
           
 double logProb(int position, int label)
           
 double logProb(int position, int[] labels)
          returns the log probability for the given labels (indexed using classIndex), where the last label corresponds to the label at the specified position.
 double logProb(int position, Object label)
           
 double logProb(int position, Object[] labels)
          returns the log probability for the given labels, where the last label corresponds to the label at the specified position.
 ClassicCounter logProbs(int position)
           
 GeneralizedCounter logProbs(int position, int window)
           
 double prob(int position, int label)
           
 double prob(int position, int[] labels)
          Returns the probability for the given labels (indexed using classIndex), where the last label corresponds to the label at the specified position.
 double prob(int position, Object label)
           
 double prob(int position, Object[] labels)
          returns the probability for the given labels, where the last label corresponds to the label at the specified position.
 ClassicCounter probs(int position)
           
 GeneralizedCounter probs(int position, int window)
           
 int rightWindow()
          How many positions to the right a position is dependent on.
 double scoreOf(int[] sequence)
          Returns the log probability of this sequence given the CRF.
 double scoreOf(int[] sequence, int pos)
          Computes the unnormalized log conditional distribution over values of the element at position pos in the sequence, conditioned on the values of the elements in all other positions of the provided sequence.
 double[] scoresOf(int[] sequence, int position)
          Computes the unnormalized log conditional distribution over values of the element at position pos in the sequence, conditioned on the values of the elements in all other positions of the provided sequence.
 void setInitialSequence(int[] sequence)
          Informs this sequence model that the value of the whole sequence is initialized to sequence
 double totalMass()
           
 void updateSequenceElement(int[] sequence, int pos, int oldVal)
          Informs this sequence model that the value of the element at position pos has changed.
 int window()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

classIndex

public Index classIndex()

length

public int length()
Specified by:
length in interface SequenceModel
Returns:
the length of the sequences modeled by this SequenceModel

leftWindow

public int leftWindow()
Description copied from interface: SequenceModel
How many positions to the left a position is dependent on.

Specified by:
leftWindow in interface SequenceModel
Returns:
the size of the left window used by this sequence model

rightWindow

public int rightWindow()
Description copied from interface: SequenceModel
How many positions to the right a position is dependent on.

Specified by:
rightWindow in interface SequenceModel
Returns:
the size of the right window used by this sequence model

getPossibleValues

public int[] getPossibleValues(int position)
Description copied from interface: SequenceModel
0...leftWindow-1 etc are null, leftWindow...length+leftWindow-1 are words, length+leftWindow...length+leftWindow+rightWindow-1 are null;

Specified by:
getPossibleValues in interface SequenceModel
Parameters:
position - the position
Returns:
the set of possible int values at this position, as an int array

scoreOf

public double scoreOf(int[] sequence,
                      int pos)
Description copied from interface: SequenceModel
Computes the unnormalized log conditional distribution over values of the element at position pos in the sequence, conditioned on the values of the elements in all other positions of the provided sequence.

Specified by:
scoreOf in interface SequenceModel
Parameters:
sequence - the sequence containing the rest of the values to condition on
pos - the position of the element to give a distribution for
Returns:
the log score of the token at the specified position in the sequence

scoresOf

public double[] scoresOf(int[] sequence,
                         int position)
Computes the unnormalized log conditional distribution over values of the element at position pos in the sequence, conditioned on the values of the elements in all other positions of the provided sequence.

Specified by:
scoresOf in interface SequenceModel
Parameters:
sequence - the sequence containing the rest of the values to condition on
position - the position of the element to give a distribution for
Returns:
an array of type double, representing a probability distribution; sums to 1.0

scoreOf

public double scoreOf(int[] sequence)
Returns the log probability of this sequence given the CRF. Does so by computing the marginal of the first windowSize tags, and then computing the conditional probability for the rest of them, conditioned on the previous tags.

Specified by:
scoreOf in interface SequenceModel
Parameters:
sequence - the sequence to compute a score for
Returns:
the score for the sequence

window

public int window()

getNumClasses

public int getNumClasses()

totalMass

public double totalMass()

backgroundIndex

public int backgroundIndex()

backgroundSymbol

public String backgroundSymbol()

logProb

public double logProb(int position,
                      int label)

prob

public double prob(int position,
                   int label)

logProb

public double logProb(int position,
                      Object label)

prob

public double prob(int position,
                   Object label)

probs

public ClassicCounter probs(int position)

logProbs

public ClassicCounter logProbs(int position)

logProb

public double logProb(int position,
                      int[] labels)
returns the log probability for the given labels (indexed using classIndex), where the last label corresponds to the label at the specified position. For instance if you called logProb(5, {1,2,3}) it will return the marginal log prob that the label at position 3 is 1, the label at position 4 is 2 and the label at position 5 is 3.


prob

public double prob(int position,
                   int[] labels)
Returns the probability for the given labels (indexed using classIndex), where the last label corresponds to the label at the specified position. For instance if you called prob(5, {1,2,3}) it will return the marginal prob that the label at position 3 is 1, the label at position 4 is 2 and the label at position 5 is 3.


logProb

public double logProb(int position,
                      Object[] labels)
returns the log probability for the given labels, where the last label corresponds to the label at the specified position. For instance if you called logProb(5, {"O", "PER", "ORG"}) it will return the marginal log prob that the label at position 3 is "O", the label at position 4 is "PER" and the label at position 5 is "ORG".


prob

public double prob(int position,
                   Object[] labels)
returns the probability for the given labels, where the last label corresponds to the label at the specified position. For instance if you called logProb(5, {"O", "PER", "ORG"}) it will return the marginal prob that the label at position 3 is "O", the label at position 4 is "PER" and the label at position 5 is "ORG".


logProbs

public GeneralizedCounter logProbs(int position,
                                   int window)

probs

public GeneralizedCounter probs(int position,
                                int window)

condLogProbGivenPrevious

public double condLogProbGivenPrevious(int position,
                                       int label,
                                       int[] prevLabels)
Gives the probability of a tag at a single position conditioned on a sequence of previous labels.

Parameters:
position - Index in sequence
label - Label of item at index
prevLabels -
Returns:
conditional log probability

condLogProbGivenPrevious

public double condLogProbGivenPrevious(int position,
                                       Object label,
                                       Object[] prevLabels)

condProbGivenPrevious

public double condProbGivenPrevious(int position,
                                    int label,
                                    int[] prevLabels)

condProbGivenPrevious

public double condProbGivenPrevious(int position,
                                    Object label,
                                    Object[] prevLabels)

condLogProbsGivenPrevious

public ClassicCounter condLogProbsGivenPrevious(int position,
                                                int[] prevlabels)

condLogProbsGivenPrevious

public ClassicCounter condLogProbsGivenPrevious(int position,
                                                Object[] prevlabels)

condLogProbGivenNext

public double condLogProbGivenNext(int position,
                                   int label,
                                   int[] nextLabels)

condLogProbGivenNext

public double condLogProbGivenNext(int position,
                                   Object label,
                                   Object[] nextLabels)

condProbGivenNext

public double condProbGivenNext(int position,
                                int label,
                                int[] nextLabels)

condProbGivenNext

public double condProbGivenNext(int position,
                                Object label,
                                Object[] nextLabels)

condLogProbsGivenNext

public ClassicCounter condLogProbsGivenNext(int position,
                                            int[] nextlabels)

condLogProbsGivenNext

public ClassicCounter condLogProbsGivenNext(int position,
                                            Object[] nextlabels)

getCalibratedCliqueTree

public static CRFCliqueTree getCalibratedCliqueTree(double[][] weights,
                                                    int[][][] data,
                                                    Index[] labelIndices,
                                                    int numClasses,
                                                    Index classIndex,
                                                    String backgroundSymbol)
Returns:
a new CRFCliqueTree for the weights on the data

getCalibratedCliqueTree

public static CRFCliqueTree getCalibratedCliqueTree(double[] weights,
                                                    double wscale,
                                                    int[][] weightIndices,
                                                    int[][][] data,
                                                    Index[] labelIndices,
                                                    int numClasses,
                                                    Index classIndex,
                                                    String backgroundSymbol)
Returns:
a new CRFCliqueTree for the weights on the data

getConditionalDistribution

public double[] getConditionalDistribution(int[] sequence,
                                           int position)
Computes the distribution over values of the element at position pos in the sequence, conditioned on the values of the elements in all other positions of the provided sequence.

Parameters:
sequence - the sequence containing the rest of the values to condition on
position - the position of the element to give a distribution for
Returns:
an array of type double, representing a probability distribution; sums to 1.0

updateSequenceElement

public void updateSequenceElement(int[] sequence,
                                  int pos,
                                  int oldVal)
Informs this sequence model that the value of the element at position pos has changed. This allows this sequence model to update its internal model if desired.

Specified by:
updateSequenceElement in interface SequenceListener

setInitialSequence

public void setInitialSequence(int[] sequence)
Informs this sequence model that the value of the whole sequence is initialized to sequence

Specified by:
setInitialSequence in interface SequenceListener

getNumValues

public int getNumValues()
Returns:
the number of possible values for each element; it is assumed to be the same for the element at each position


Stanford NLP Group