Package edu.stanford.nlp.ie
Class EntityCachingAbstractSequencePriorBIO<IN extends CoreMap>
- java.lang.Object
-
- edu.stanford.nlp.ie.EntityCachingAbstractSequencePriorBIO<IN>
-
- All Implemented Interfaces:
ListeningSequenceModel,SequenceListener,SequenceModel
- Direct Known Subclasses:
EmpiricalNERPriorBIO
public abstract class EntityCachingAbstractSequencePriorBIO<IN extends CoreMap> extends Object implements ListeningSequenceModel
This class keeps track of all labeled entities and updates the its list whenever the label at a point gets changed. This allows you to not have to regenerate the list every time, which can be quite inefficient.- Author:
- Mengqiu Wang
-
-
Field Summary
Fields Modifier and Type Field Description protected intbackgroundSymbolprotected Index<String>classIndexprotected intnumClassesprotected int[]possibleValuesprotected int[]sequenceprotected Index<String>tagIndex
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description edu.stanford.nlp.ie.EntityBIOextractEntity(int[] sequence, int position, String tag)extracts the entity starting at the given position and adds it to the entity list.double[]getConditionalDistribution(int[] sequence, int position)intgetNumClasses()get the number of classes in the sequence model.int[]getPossibleValues(int position)Return the valid sequence labels (as integer indices) for a particular position in the sequence.intleftWindow()How many label positions to the left influence the label assignment at a particular position.intlength()booleanmatches(edu.stanford.nlp.ie.EntityBIO entity, int position)int[]otherOccurrences(edu.stanford.nlp.ie.EntityBIO entity)finds other locations in the sequence where the sequence of words in this entity occurs.intrightWindow()How many label positions to the right influence the label assignment at a particular position.doublescoreOf(int[] sequence, int pos)Computes the score of the element at the given position 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 scores of labels for the element at the given position in the sequence, conditioned on the values of the labels at all other positions of the provided sequence.voidsetInitialSequence(int[] initialSequence)Informs this sequence listener that the value of the whole sequence is initialized to sequence.static int[]toArray(List<Integer> list)StringtoString()StringtoString(int pos)voidupdateSequenceElement(int[] sequence, int position, int oldVal)Informs this sequence listener that the value of the element at position pos has changed.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface edu.stanford.nlp.sequences.SequenceModel
scoreOf
-
-
-
-
Method Detail
-
leftWindow
public int leftWindow()
Description copied from interface:SequenceModelHow many label positions to the left influence the label assignment at a particular position.- Specified by:
leftWindowin interfaceSequenceModel- Returns:
- The size of the left window used by this sequence model
-
rightWindow
public int rightWindow()
Description copied from interface:SequenceModelHow many label positions to the right influence the label assignment at a particular position.- Specified by:
rightWindowin interfaceSequenceModel- Returns:
- the size of the right window used by this sequence model
-
getPossibleValues
public int[] getPossibleValues(int position)
Description copied from interface:SequenceModelReturn the valid sequence labels (as integer indices) for a particular position in the sequence. Since the sequence is padded at each end, typically sequence items 0...leftWindow-1 are null, leftWindow...length+leftWindow-1 are words, length+leftWindow...length+leftWindow+rightWindow-1 are null.- Specified by:
getPossibleValuesin interfaceSequenceModel- 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:SequenceModelComputes the score of the element at the given position in the sequence, conditioned on the values of the elements in all other positions of the provided sequence. Typically, this is an unnormalized log conditional probability of the label at the given position in the sequence, given the input data nd the other labels.- Specified by:
scoreOfin interfaceSequenceModel- Parameters:
sequence- The sequence containing the prediction and the rest of the labels to condition onpos- The position of the element to give a score for- Returns:
- The score of the label at the specified position in the sequence
-
length
public int length()
- Specified by:
lengthin interfaceSequenceModel- Returns:
- the length of the sequence
-
getNumClasses
public int getNumClasses()
get the number of classes in the sequence model.
-
getConditionalDistribution
public double[] getConditionalDistribution(int[] sequence, int position)
-
scoresOf
public double[] scoresOf(int[] sequence, int position)Description copied from interface:SequenceModelComputes the scores of labels for the element at the given position in the sequence, conditioned on the values of the labels at all other positions of the provided sequence. The returned array elements correspond index-by-index to the possible values returned by getPossibleValues(int). The label at sequence[position] is ignored in the calculations. The scores are often given as an unnormalized log conditional distribution over possible labels. Otherwise, they may be probabilities. If it is a probability distribution, conceptually, the scores should sum to 1 (perhaps after transforming them). Note that implementations often alter sequence[position] to do their calculations, and so access to the array isn't threadsafe, but should restore its value afterwards.- Specified by:
scoresOfin interfaceSequenceModel- Parameters:
sequence- The sequence containing the rest of the values to condition onposition- The position of the element to give a distribution for- Returns:
- The scores of the possible tokens at the specified position in the sequence
-
setInitialSequence
public void setInitialSequence(int[] initialSequence)
Description copied from interface:SequenceListenerInforms this sequence listener that the value of the whole sequence is initialized to sequence.- Specified by:
setInitialSequencein interfaceSequenceListener
-
extractEntity
public edu.stanford.nlp.ie.EntityBIO extractEntity(int[] sequence, int position, String tag)extracts the entity starting at the given position and adds it to the entity list. returns the index of the last element in the entity (not index+1)
-
otherOccurrences
public int[] otherOccurrences(edu.stanford.nlp.ie.EntityBIO entity)
finds other locations in the sequence where the sequence of words in this entity occurs.
-
matches
public boolean matches(edu.stanford.nlp.ie.EntityBIO entity, int position)
-
updateSequenceElement
public void updateSequenceElement(int[] sequence, int position, int oldVal)Description copied from interface:SequenceListenerInforms this sequence listener 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:
updateSequenceElementin interfaceSequenceListener
-
toString
public String toString(int pos)
-
-