com.aliasi.hmm
Class AbstractHmmEstimator

java.lang.Object
  extended by com.aliasi.hmm.AbstractHmm
      extended by com.aliasi.hmm.AbstractHmmEstimator
All Implemented Interfaces:
Handler, ObjectHandler<Tagging<String>>, TagHandler, HiddenMarkovModel, Compilable
Direct Known Subclasses:
HmmCharLmEstimator

public abstract class AbstractHmmEstimator
extends AbstractHmm
implements TagHandler, ObjectHandler<Tagging<String>>, Compilable

An HmmEstimator may be used to train a hidden Markov model (HMM). Training events are supplied through the TagHandler interface method handle(Tagging). The estimator implements an HMM, so is suitable for use in a tag-a-little, learn-a-little environment or elswhere when an adaptive HMM is required. At any point, the estimator may be compiled to an object output stream using compileTo(ObjectOutput).

Since:
LingPipe2.1
Version:
3.9.1
Author:
Bob Carpenter

Constructor Summary
AbstractHmmEstimator(SymbolTable table)
          Construct an HMM estimator with the specified tag symbol table.
 
Method Summary
abstract  void compileTo(ObjectOutput objOut)
          Compiles a copy of this estimated HMM to the specified object output.
 void handle(String[] toks, String[] whitespaces, String[] tags)
          Deprecated. use handle(Tagging) instead.
 void handle(Tagging<String> tagging)
          Train the estimator with the specified tokens, whitespaces and states.
 long numTrainingCases()
          Return the number of taggings handled.
 long numTrainingTokens()
          Returns the number of tokens handled for training.
abstract  void trainEmit(String state, CharSequence emission)
          Train the emission estimator with the specified training instance consisting of a state and emission.
abstract  void trainEnd(String state)
          Train the end state estimator with the specified end state.
abstract  void trainStart(String state)
          Train the start state estimator with the specified start state.
abstract  void trainTransit(String sourceState, String targetState)
          Trains the transition estimator from the specified transition from the specified source state to the specified target state.
 
Methods inherited from class com.aliasi.hmm.AbstractHmm
addState, emitLog2Prob, emitLog2Prob, emitProb, emitProb, endLog2Prob, endLog2Prob, endProb, endProb, startLog2Prob, startLog2Prob, startProb, startProb, stateSymbolTable, transitLog2Prob, transitLog2Prob, transitProb, transitProb
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractHmmEstimator

public AbstractHmmEstimator(SymbolTable table)
Construct an HMM estimator with the specified tag symbol table.

Parameters:
table - Symbol table for tags.
Method Detail

trainStart

public abstract void trainStart(String state)
Train the start state estimator with the specified start state. This increases the likelihood that the specified state will be the state of the first token.

Parameters:
state - State being trained.

trainEnd

public abstract void trainEnd(String state)
Train the end state estimator with the specified end state. This increases the likelihood that the specified state will be the state of the last token.

Parameters:
state - State being trained.

trainTransit

public abstract void trainTransit(String sourceState,
                                  String targetState)
Trains the transition estimator from the specified transition from the specified source state to the specified target state.

Parameters:
sourceState - State from which the transition is made.
targetState - State to which the transition is made.

trainEmit

public abstract void trainEmit(String state,
                               CharSequence emission)
Train the emission estimator with the specified training instance consisting of a state and emission. This method may be used for dictionary-based training for a particular state.

Parameters:
state - State being trained.
emission - Emission from state being trained.

compileTo

public abstract void compileTo(ObjectOutput objOut)
                        throws IOException
Compiles a copy of this estimated HMM to the specified object output. Reading in the resulting bytes with an object input will produce an instance of HiddenMarkovModel, but will most likely not be an instance of the same class as the object being compiled.

Specified by:
compileTo in interface Compilable
Parameters:
objOut - Object output to which this estimator is compiled.
Throws:
IOException - If there is an I/O exception compiling this object.

numTrainingCases

public long numTrainingCases()
Return the number of taggings handled. This is simply the number of times handle(Tagging) has been called.

Returns:
The number of taggings handled for training.

numTrainingTokens

public long numTrainingTokens()
Returns the number of tokens handled for training. This is the sum of the length of token arrays in all calls to the handle(String[],String[],String[]) method.

Returns:
The number of tokens handled for training.

handle

@Deprecated
public void handle(String[] toks,
                              String[] whitespaces,
                              String[] tags)
Deprecated. use handle(Tagging) instead.

Train the estimator with the specified tokens, whitespaces and states. The whitespaces are ignored.

For a specified set of tags and tokens, this method calls:

Specified by:
handle in interface TagHandler
Parameters:
toks - Tokens making up the emissions of the HMM states.
whitespaces - Whitespaces between tokens; ignored.
tags - Tags making up the states of the HMM.

handle

public void handle(Tagging<String> tagging)
Train the estimator with the specified tokens, whitespaces and states. The whitespaces are ignored.

For a specified tagging made up of parallel sequences of tags and tokens, this method calls:

Specified by:
handle in interface ObjectHandler<Tagging<String>>
Parameters:
tagging - Tagging from which tokens and tags are derived.