E - Type of tokens in the lattice.public class ForwardBackwardTagLattice<E> extends TagLattice<E>
ForwardBackwardTagLattice provides an implementation of
a tag lattice based on forward, backward, transition and
normalizing values.
The forward and backward values are available through logBackward(int,int) and logForward(int,int); see the
method doc for details on the indexing. Transition values are
available through logTransition(int,int,int). The
normalizing term is returned by logZ().
Typically, this class is used only as a return object, not as a
return type. For instance, the marginal tagging interface for HMMs
and CRFs specifies the return type only as implementing TagLattice. The class is public here so that there is some
public way available for creating tag lattices from their component
pieces.
| Constructor and Description |
|---|
ForwardBackwardTagLattice(List<E> tokens,
List<String> tags,
double[][] logForwards,
double[][] logBackwards,
double[][][] logTransitions,
double logZ)
Construct a log tag lattice from the specified list of tokens,
list of tags in order of symbol identifier along with log
forward, backward, transition and normalizing values on a log
probability scale.
|
| Modifier and Type | Method and Description |
|---|---|
double |
logBackward(int token,
int tag)
Returns the log of the backward probability to the specified
token and tag.
|
double |
logForward(int token,
int tag)
Return the log of the forward probability of the specified tag
at the specified position.
|
double |
logProbability(int token,
int tag)
Return the log of the conditional probability that the
specified token has the specified tag, given the complete list
of input tokens.
|
double |
logProbability(int tokenFrom,
int[] tags)
Return the log conditional probability that the tokens starting
with the specified token position have the specified tags given
the complete sequence of input tokens.
|
double |
logProbability(int tokenTo,
int tagFrom,
int tagTo)
Convenience method returning the log of the conditional
probability that the specified two tokens have the specified
tag given the complete list of input tokens.
|
double |
logTransition(int tokenFrom,
int tagFrom,
int tagTo)
Returns the log of the transition probability from the specified
input token position with the specified previous tag to the
specified target tag.
|
double |
logZ()
Return the log of the normalizing constant for the lattice.
|
int |
numTags()
Return the number of tags in this tag lattice.
|
int |
numTokens()
Returns the length of this tag lattice as measured
by number of tokens.
|
String |
tag(int id)
Return the tag with the specified symbol identifier.
|
List<String> |
tagList()
Returns an unmodifiable view of the list of tags
used in this lattice, indexed by identifier.
|
SymbolTable |
tagSymbolTable()
Returns a symbol table which converts tags to identifiers and
vice-versa.
|
E |
token(int n)
Return the token at the specified position in the input.
|
List<E> |
tokenList()
Return an unmodifiable view of the underlying tokens for this
tag lattice.
|
String |
toString()
Return a string-based representation of this tag lattice.
|
tokenClassificationpublic ForwardBackwardTagLattice(List<E> tokens, List<String> tags, double[][] logForwards, double[][] logBackwards, double[][][] logTransitions, double logZ)
The lists of tokens and tags are copied so that changes to the supplied list will not affect the constructed lattice.
The probabilities returned are all relative the normalizing
term logZ, which might not even be negative. True
probabilities are computed as described in the class
documentation above.
See the class documentation above for information on how these arrays are used to compute probabilities.
Warning: No check is made to ensure the log probabilities are coherent, only that the arrays are the right size and are filled with non-positive numbers.
tokens - Underlying tokens in order.tags - List of tags in symbol order.logForwards - Log forward probabilities.logBackwards - Log backward probabilities.logTransitions - Log transition probabilities.logZ - Log normalizing probability.IllegalArgumentException - If the various arrays are not
properly sized, meaning for tokens of length N and tags of
length K, logForwards[N][K], logBackward[N][K],
logTransitions[N-1][K][K], where N is the size of the tokens
list and K the length of the tags array, or if any of the log
probabilities is not finite.public List<E> tokenList()
TagLatticetokenList in class TagLattice<E>public List<String> tagList()
TagLatticetagList in class TagLattice<E>public String tag(int id)
TagLatticetag in class TagLattice<E>id - Identifer for tag.public int numTags()
TagLatticenumTags in class TagLattice<E>public E token(int n)
TagLatticetoken in class TagLattice<E>n - Input position.public int numTokens()
TagLatticenumTokens in class TagLattice<E>public SymbolTable tagSymbolTable()
TagLatticeA new symbol table is constructed for each call, so it should be saved and reused if possible. Changing the returned symbol table will not affect this lattice.
tagSymbolTable in class TagLattice<E>public double logProbability(int token,
int tag)
logProbability in class TagLattice<E>token - Position of input token.tag - Identifier of tag.ArrayIndexOutOfBoundsException - If the token or tag
identifiers are not in range.public double logProbability(int tokenTo,
int tagFrom,
int tagTo)
TagLatticeThis method returns results defined by
logProbability(nTo,tagFrom,tagTo)
== logProbability(n-1,new int[] { tagFrom, tagTo })logProbability in class TagLattice<E>tokenTo - Position of second token.tagFrom - First Tag from which transition is made.tagTo - Second Tag to which transition is made.public double logProbability(int tokenFrom,
int[] tags)
logProbability in class TagLattice<E>tokenFrom - Starting position of sequence.tags - Tag identifiers for sequence.IllegalArgumentException - If the token is out of range or
the token plus the length of the tag sequence is out of range of
tokens, or if any of the tags is not a known identifier.public double logForward(int token,
int tag)
TagLatticelogForward in class TagLattice<E>token - Token position.tag - Tag identifier.public double logBackward(int token,
int tag)
TagLatticelogBackward in class TagLattice<E>token - Input token position.tag - Tag identifier.public double logTransition(int tokenFrom,
int tagFrom,
int tagTo)
TagLatticelogTransition in class TagLattice<E>tokenFrom - Token position from which the transition is
made.tagFrom - Identifier for the previous tag from which the
transition is made.tagTo - Tag identifier for the target tag to which the
the transition is made.public double logZ()
logZ in class TagLattice<E>Copyright © 2016 Alias-i, Inc.. All rights reserved.