edu.illinois.cs.cogcomp.lbj.coref.decoders
Class ScoredCorefDecoder

java.lang.Object
  extended by edu.illinois.cs.cogcomp.lbj.coref.decoders.DecoderWithOptions<ST>
      extended by edu.illinois.cs.cogcomp.lbj.coref.decoders.ChainSolutionDecoder<ChainSolution<Mention>,Mention,CExample>
          extended by edu.illinois.cs.cogcomp.lbj.coref.decoders.CorefDecoder
              extended by edu.illinois.cs.cogcomp.lbj.coref.decoders.ScoredCorefDecoder
All Implemented Interfaces:
SolutionDecoder<ChainSolution<Mention>>, java.io.Serializable
Direct Known Subclasses:
BestLinkDecoder

public abstract class ScoredCorefDecoder
extends CorefDecoder

Base class for decoders which depend on a score from a learned classifier. For compatibility with code that loads dynamically (such as the GUI) subclasses should provide at least two constructors: A constructor that takes just a LinearThresholdUnit and a constructor that takes a LinearThresholdUnit and a Classifier (in that order).

Author:
Eric Bengtson
See Also:
Serialized Form

Field Summary
private  java.util.List<java.lang.Double> m_allScores
          The collection of all scores
protected  boolean m_cacheScores
          Determines whether scores should be cached.
protected  boolean m_recordAllScores
          Determines whether all uncached (or cache missed) calls of the getTrueScore method record the score.
private  java.util.Map<CExample,java.lang.Double> m_scoreCache
          The scores cache
protected  LBJ2.learn.LinearThresholdUnit m_scorer
          The scoring classifier.
private static long serialVersionUID
           
 
Fields inherited from class edu.illinois.cs.cogcomp.lbj.coref.decoders.CorefDecoder
m_classifier
 
Fields inherited from class edu.illinois.cs.cogcomp.lbj.coref.decoders.DecoderWithOptions
m_options, m_train
 
Constructor Summary
ScoredCorefDecoder(LBJ2.learn.LinearThresholdUnit c)
          Constructs a decoder whose decisions will depend on the scores of a linear threshold unit, which will also be used to make coreference decisions via its discreteValue method.
ScoredCorefDecoder(LBJ2.learn.LinearThresholdUnit scorer, LBJ2.classify.Classifier decider)
          Constructor for use when the scoring classifier is not sufficient to decide whether links should be made, such as when inference is being applied.
 
Method Summary
protected  java.util.List<java.lang.String> getEdgeLabels(CExample ex)
          If the scoring classifier is a SparsePerceptron, generate a list of labels, each indicating the name and weight of an active feature.
protected  java.util.Map<java.lang.String,java.lang.Double> getFeatureWeights(LBJ2.learn.SparsePerceptron c)
          Gets all the known features of the given classifier and their weights.
protected  java.util.Map<java.lang.String,java.lang.Double> getMinimumPartsOfCompounds(java.util.Map<java.lang.String,java.lang.Double> map)
          Gets the smaller feature weight for each conjunction of features in the given feature-weight map.
 LBJ2.learn.LinearThresholdUnit getScorer()
          Gets the scoring classifier.
 java.lang.String getStatsString()
          Get statistics encoded as a string.
protected  java.util.Map<java.lang.String,java.lang.Double> getSumsOfParts(java.util.Map<java.lang.String,java.lang.Double> feats, java.util.Map<java.lang.String,java.lang.Double> mins)
          Gets the total of all the weight each feature contributes.
protected  java.util.Map<java.lang.String,java.lang.Double> getTotalsOfPartsOfCompounds(java.util.Map<java.lang.String,java.lang.Double> map)
          Gets, for each feature, the total of all the weights of each conjunction that feature occurs in.
 double getTrueScore(CExample ex)
          Gets the score for the true prediction of the scoring classifier applied to the example.
protected  boolean predictedCoreferential(CExample ex)
          Determines whether an example is coreferential.
private  void recordScore(double score)
          Record a score for statistics purposes.
 void setScorer(LBJ2.learn.LinearThresholdUnit scorer)
          Sets the scoring classifier.
protected  void setup()
          Initializes members.
 
Methods inherited from class edu.illinois.cs.cogcomp.lbj.coref.decoders.CorefDecoder
getClassifier, setClassifier
 
Methods inherited from class edu.illinois.cs.cogcomp.lbj.coref.decoders.ChainSolutionDecoder
decode
 
Methods inherited from class edu.illinois.cs.cogcomp.lbj.coref.decoders.DecoderWithOptions
getBooleanOption, getOption, getRealOption, processOption, setOption, setOption, setOption, setTrain
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

serialVersionUID

private static final long serialVersionUID
See Also:
Constant Field Values

m_scorer

protected LBJ2.learn.LinearThresholdUnit m_scorer
The scoring classifier.


m_cacheScores

protected boolean m_cacheScores
Determines whether scores should be cached.


m_scoreCache

private java.util.Map<CExample,java.lang.Double> m_scoreCache
The scores cache


m_recordAllScores

protected boolean m_recordAllScores
Determines whether all uncached (or cache missed) calls of the getTrueScore method record the score. To produce statistics, this may be enabled. But the performance may not be scalable for long-running servers.


m_allScores

private java.util.List<java.lang.Double> m_allScores
The collection of all scores

Constructor Detail

ScoredCorefDecoder

public ScoredCorefDecoder(LBJ2.learn.LinearThresholdUnit c)
Constructs a decoder whose decisions will depend on the scores of a linear threshold unit, which will also be used to make coreference decisions via its discreteValue method.

Parameters:
c - A coreference classifier which takes CExamples and indicates coreference by returning "true" or "false", and also produces a score.

ScoredCorefDecoder

public ScoredCorefDecoder(LBJ2.learn.LinearThresholdUnit scorer,
                          LBJ2.classify.Classifier decider)
Constructor for use when the scoring classifier is not sufficient to decide whether links should be made, such as when inference is being applied. Both scorer and decider must return "true" for predictedCoreferential(CExample) to return true.

Parameters:
scorer - Determines the score or confidence. Takes CExamples and returns a score.
decider - Final arbiter of linking decisions. Takes CExamples and returns "true" or "false".
Method Detail

setup

protected void setup()
Initializes members.


getScorer

public LBJ2.learn.LinearThresholdUnit getScorer()
Gets the scoring classifier.

Returns:
The scorer.

setScorer

public void setScorer(LBJ2.learn.LinearThresholdUnit scorer)
Sets the scoring classifier. If the scorer and decider were identical, they will both be changed to the given scorer. Otherwise, only the scorer will be updated.

Parameters:
scorer - The new scoring classifier.

predictedCoreferential

protected boolean predictedCoreferential(CExample ex)
Determines whether an example is coreferential. An example is coreferential if the scorer returns "true" when applied to the example and any non-scoring classifier also returns "true". If there is only a scoring classifier, its decisions will be used.

Overrides:
predictedCoreferential in class CorefDecoder
Parameters:
ex - The example to be classified as coreferential or not.
Returns:
Whether the example is coreferential according to the scoring classifier AND any specified non-scoring classifier.

getTrueScore

public double getTrueScore(CExample ex)
Gets the score for the true prediction of the scoring classifier applied to the example.

Parameters:
ex - The example to score.
Returns:
The scoring classifier's confidence that the example is coreferential.

getStatsString

public java.lang.String getStatsString()
Get statistics encoded as a string. Indicates the range of scores along with the rank of the threshold among all scores generated. Enable recording of scores for this method to return anything.

Overrides:
getStatsString in class ChainSolutionDecoder<ChainSolution<Mention>,Mention,CExample>
Returns:
A statistics string.

recordScore

private void recordScore(double score)
Record a score for statistics purposes.

Parameters:
score - A confidence score.

getEdgeLabels

protected java.util.List<java.lang.String> getEdgeLabels(CExample ex)
If the scoring classifier is a SparsePerceptron, generate a list of labels, each indicating the name and weight of an active feature.

Parameters:
ex - The example to be processed by the scorer.
Returns:
A list of strings, each giving the name and weight of an active feature.

getFeatureWeights

protected java.util.Map<java.lang.String,java.lang.Double> getFeatureWeights(LBJ2.learn.SparsePerceptron c)
Gets all the known features of the given classifier and their weights.

Parameters:
c - The classifier to examine.
Returns:
A map from the known features of c to their weights.

getMinimumPartsOfCompounds

protected java.util.Map<java.lang.String,java.lang.Double> getMinimumPartsOfCompounds(java.util.Map<java.lang.String,java.lang.Double> map)
Gets the smaller feature weight for each conjunction of features in the given feature-weight map.

Parameters:
map - A map from features to weights. Some of the features may be conjunctions of multiple features.
Returns:
A map from each feature f that is part of a conjunction to the smallest weight of the features of which f is part.

getTotalsOfPartsOfCompounds

protected java.util.Map<java.lang.String,java.lang.Double> getTotalsOfPartsOfCompounds(java.util.Map<java.lang.String,java.lang.Double> map)
Gets, for each feature, the total of all the weights of each conjunction that feature occurs in.

Parameters:
map - A map from features to weights.
Returns:
A map from each feature f to the total of all the weights of each conjunction that f occurs in.

getSumsOfParts

protected java.util.Map<java.lang.String,java.lang.Double> getSumsOfParts(java.util.Map<java.lang.String,java.lang.Double> feats,
                                                                          java.util.Map<java.lang.String,java.lang.Double> mins)
Gets the total of all the weight each feature contributes.

Parameters:
feats - A map from features to weights.
mins - A map from features to the minimum weight.
Returns:
A map from each feature f to the total weight f contributes.