Package cc.mallet.fst
Class Transducer
- java.lang.Object
-
- cc.mallet.fst.Transducer
-
- All Implemented Interfaces:
java.io.Serializable
- Direct Known Subclasses:
CRF,FeatureTransducer,HMM,PRAuxiliaryModel
public abstract class Transducer extends java.lang.Object implements java.io.SerializableA base class for all sequence models, analogous toclassify.Classifier.- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceTransducer.IncrementorMethods to be called by inference methods to indicate partial counts of sufficient statistics.static classTransducer.StateAn abstract class used to represent the states of the transducer.static classTransducer.TransitionIteratorAn abstract class to iterate over the states of the transducer.
-
Field Summary
Fields Modifier and Type Field Description static doubleCERTAIN_WEIGHTstatic doubleIMPOSSIBLE_WEIGHTprotected PipeinputPipeA pipe that should produce a Sequence in the "data" slot, (and possibly one in the "target" slot alsoprotected PipeoutputPipeA pipe that should expect the Transducer's output sequence in the "target" slot, and should produce something printable in the "source" slot that indicates the results of transduction.
-
Constructor Summary
Constructors Constructor Description Transducer()Initializes default sum-product and max-product inference engines.Transducer(Pipe inputPipe, Pipe outputPipe)
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description doubleaverageTokenAccuracy(InstanceList ilist)Runs inference across all the instances and returns the average token accuracy.booleancanIterateAllTransitions()Some transducers are "generative", meaning that you can get a sequence out of them without giving them an input sequence.SequencePairAlignmentgeneratePath()PipegetInputPipe()MaxLatticeFactorygetMaxLatticeFactory()PipegetOutputPipe()abstract Transducer.StategetState(int index)SumLatticeFactorygetSumLatticeFactory()abstract java.util.IteratorinitialStateIterator()booleanisGenerative()If true, this is a "generative transducer".Instancelabel(Instance instance)Take input sequence from instance.data and put the output sequence in instance.target.static doubleless_efficient_sumLogProb(double a, double b)static doubleno_longer_needed_sumNegLogProb(double a, double b)abstract intnumStates()voidprint()voidsetMaxLatticeFactory(MaxLatticeFactory vf)voidsetSumLatticeFactory(SumLatticeFactory fbf)intstateIndexOfString(java.lang.String s)Returns the index of the input state name, returns -1 if name not found.static doublesumLogProb(double a, double b)Returns Math.log(Math.exp(a) + Math.exp(b)).Instancetransduce(Instance instance)Take input sequence from instance.data and put the output sequence in instance.data.Sequencetransduce(Sequence input)Converts the given sequence into another sequence according to this transducer.
-
-
-
Field Detail
-
CERTAIN_WEIGHT
public static final double CERTAIN_WEIGHT
- See Also:
- Constant Field Values
-
IMPOSSIBLE_WEIGHT
public static final double IMPOSSIBLE_WEIGHT
- See Also:
- Constant Field Values
-
inputPipe
protected Pipe inputPipe
A pipe that should produce a Sequence in the "data" slot, (and possibly one in the "target" slot also
-
outputPipe
protected Pipe outputPipe
A pipe that should expect the Transducer's output sequence in the "target" slot, and should produce something printable in the "source" slot that indicates the results of transduction.
-
-
Method Detail
-
getInputPipe
public Pipe getInputPipe()
-
getOutputPipe
public Pipe getOutputPipe()
-
setSumLatticeFactory
public void setSumLatticeFactory(SumLatticeFactory fbf)
-
setMaxLatticeFactory
public void setMaxLatticeFactory(MaxLatticeFactory vf)
-
getSumLatticeFactory
public SumLatticeFactory getSumLatticeFactory()
-
getMaxLatticeFactory
public MaxLatticeFactory getMaxLatticeFactory()
-
label
public Instance label(Instance instance)
Take input sequence from instance.data and put the output sequence in instance.target. Like transduce(Instance), but put best output sequence into instance.target rather than instance.data.
-
transduce
public Instance transduce(Instance instance)
Take input sequence from instance.data and put the output sequence in instance.data.
-
transduce
public Sequence transduce(Sequence input)
Converts the given sequence into another sequence according to this transducer. For exmaple, probabilistic transducer may do something like Viterbi here. Subclasses of transducer may specify that they only accept special kinds of sequence.- Parameters:
input- Input sequence- Returns:
- Sequence output by this transudcer
-
numStates
public abstract int numStates()
-
getState
public abstract Transducer.State getState(int index)
-
initialStateIterator
public abstract java.util.Iterator initialStateIterator()
-
canIterateAllTransitions
public boolean canIterateAllTransitions()
Some transducers are "generative", meaning that you can get a sequence out of them without giving them an input sequence. In this case State.transitionIterator() should return all available transitions, but attempts to obtain the input and weight fields may throw an exception.
-
isGenerative
public boolean isGenerative()
If true, this is a "generative transducer". In this case State.transitionIterator() should return transitions that have valid input and cost fields. True returned here should imply that canIterateAllTransitions() is true.
-
averageTokenAccuracy
public double averageTokenAccuracy(InstanceList ilist)
Runs inference across all the instances and returns the average token accuracy.
-
generatePath
public SequencePairAlignment generatePath()
-
stateIndexOfString
public int stateIndexOfString(java.lang.String s)
Returns the index of the input state name, returns -1 if name not found.
-
print
public void print()
-
no_longer_needed_sumNegLogProb
public static double no_longer_needed_sumNegLogProb(double a, double b)
-
sumLogProb
public static double sumLogProb(double a, double b)Returns Math.log(Math.exp(a) + Math.exp(b)).a, b represent weights.
-
less_efficient_sumLogProb
public static double less_efficient_sumLogProb(double a, double b)
-
-