Package opennlp.tools.depparse
Class FeedforwardContext
java.lang.Object
opennlp.tools.depparse.FeedforwardContext
The feature template of the feedforward parser for one sentence: a fixed set of
configuration positions whose words, tags, and arc labels are embedded and
concatenated into the network input, following
Chen and Manning (2014).
Positions: the top three stack and buffer items; the leftmost and rightmost dependents of the top two stack items; and the leftmost dependent of the leftmost dependent and rightmost dependent of the rightmost dependent of the top two stack items, capturing second-order structure. Words and tags are read for all positions, labels only for the dependent positions, whose relations are already assigned.
The tokens and tags are resolved to embedding rows once per instance, so extracting the features of a configuration only indexes. An instance holds scratch state for that purpose and is used by one thread for one sentence.
- Since:
- 3.0.0
-
Field Summary
FieldsModifier and TypeFieldDescription(package private) static final intThe number of features in one parser configuration.private static final intThe index of the first dependent position; the stack and buffer items precede it.(package private) static final intThe number of dependent positions whose arc label is embedded.private final FeedforwardNetworkprivate final int[]Scratch for the token index of every position.(package private) static final intThe number of positions whose word and tag are embedded.private final int[]private final int[] -
Constructor Summary
ConstructorsConstructorDescriptionFeedforwardContext(FeedforwardNetwork network, String[] tokens, String[] tags) Resolves a sentence against the network vocabularies. -
Method Summary
Modifier and TypeMethodDescription(package private) int[]featureIds(ArcStandardState state) Extracts the embedding rows of a configuration into a new array.(package private) voidfeatureIds(ArcStandardState state, int[] features) Extracts the embedding rows of a configuration intofeatures: absent positions take the absent-position row of their vocabulary and the artificial root takes the root row.private static intleftmost(ArcStandardState state, int index) private static intrightmost(ArcStandardState state, int index)
-
Field Details
-
POSITIONS
static final int POSITIONSThe number of positions whose word and tag are embedded.- See Also:
-
LABEL_POSITIONS
static final int LABEL_POSITIONSThe number of dependent positions whose arc label is embedded.- See Also:
-
FEATURE_COUNT
static final int FEATURE_COUNTThe number of features in one parser configuration.- See Also:
-
FIRST_DEPENDENT_POSITION
private static final int FIRST_DEPENDENT_POSITIONThe index of the first dependent position; the stack and buffer items precede it.- See Also:
-
network
-
wordRows
private final int[] wordRows -
tagRows
private final int[] tagRows -
positions
private final int[] positionsScratch for the token index of every position.
-
-
Constructor Details
-
FeedforwardContext
FeedforwardContext(FeedforwardNetwork network, String[] tokens, String[] tags) Resolves a sentence against the network vocabularies.- Parameters:
network- The network whose rows the features index.tokens- The sentence tokens. Must not containnull.tags- The part-of-speech tags aligned withtokens. Must not containnull.
-
-
Method Details
-
featureIds
Extracts the embedding rows of a configuration into a new array.- Parameters:
state- The configuration to describe.- Returns:
POSITIONSword rows, thenPOSITIONStag rows, thenLABEL_POSITIONSlabel rows. Nevernull.
-
featureIds
Extracts the embedding rows of a configuration intofeatures: absent positions take the absent-position row of their vocabulary and the artificial root takes the root row.- Parameters:
state- The configuration to describe.features- Receives the rows in the order offeatureIds(ArcStandardState); overwritten. Must haveFEATURE_COUNTentries.
-
leftmost
- Parameters:
state- The configuration.index- The token index of a position, orArcStandardState.NONE.- Returns:
- The leftmost dependent of the position, or
ArcStandardState.NONEif the position is absent or has no dependent.
-
rightmost
- Parameters:
state- The configuration.index- The token index of a position, orArcStandardState.NONE.- Returns:
- The rightmost dependent of the position, or
ArcStandardState.NONEif the position is absent or has no dependent.
-