Package opennlp.tools.depparse
Class FeedforwardDependencyParser
java.lang.Object
opennlp.tools.depparse.FeedforwardDependencyParser
- All Implemented Interfaces:
DependencyParser
The neural
DependencyParser: an arc-standard decoder over the
FeedforwardDependencyModel. By default it decodes with the beam size the
model was refined with, or greedily for a model that was not refined; a beam size
given to the constructor overrides that. It scores configurations with learned dense
representations instead of the sparse feature conjunctions of
DependencyParserME.
Beam decoding retains the highest scoring transition sequences by summed log-probability. Complete arc-standard derivations for a sentence have equal length, so their scores need no length normalization.
The parser does not modify its model and keeps no per-parse state, so one instance can be shared between threads. An optional scoring cache, owned by the parser and bounded in bytes, stores the hidden-layer contribution of each feature position and embedding row it has scored.
- Since:
- 3.0.0
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final intprivate final ContributionCacheprivate static final intThe beam size at which decoding is greedy.private final FeedforwardNetworkprivate static final longThe scoring cache budget at which no cache is created.private final Transition[] -
Constructor Summary
ConstructorsConstructorDescriptionInitializes aFeedforwardDependencyParserwith the beam size of the model and without a scoring cache.FeedforwardDependencyParser(FeedforwardDependencyModel model, int beamSize) Initializes aFeedforwardDependencyParserwith a beam and without a scoring cache.FeedforwardDependencyParser(FeedforwardDependencyModel model, int beamSize, long scoringCacheBytes) Initializes aFeedforwardDependencyParserwith a beam and a scoring cache. -
Method Summary
Modifier and TypeMethodDescriptionprivate DependencyTreebeamParse(FeedforwardContext context, int tokenCount) Decodes with a beam and returns its highest scoring complete sequence.(package private) intbeamSize()Returns the number of transition sequences the parser retains.(package private) ContributionCachecache()private DependencyTreegreedyParse(FeedforwardContext context, int tokenCount) Decodes greedily: the highest scoring applicable transition wins each step.Parses a sentence into aDependencyTree.
-
Field Details
-
GREEDY_BEAM_SIZE
private static final int GREEDY_BEAM_SIZEThe beam size at which decoding is greedy.- See Also:
-
NO_CACHE
private static final long NO_CACHEThe scoring cache budget at which no cache is created.- See Also:
-
network
-
transitions
-
beamSize
private final int beamSize -
cache
-
-
Constructor Details
-
FeedforwardDependencyParser
Initializes aFeedforwardDependencyParserwith the beam size of the model and without a scoring cache.- Parameters:
model- The model to parse with. Must not benull.- Throws:
IllegalArgumentException- Thrown ifmodelisnull.- See Also:
-
FeedforwardDependencyParser
Initializes aFeedforwardDependencyParserwith a beam and without a scoring cache.- Parameters:
model- The model to parse with. Must not benull.beamSize- The number of transition sequences to retain. Must be positive;1decodes greedily.- Throws:
IllegalArgumentException- Thrown ifmodelisnullorbeamSizeis not positive.
-
FeedforwardDependencyParser
public FeedforwardDependencyParser(FeedforwardDependencyModel model, int beamSize, long scoringCacheBytes) Initializes aFeedforwardDependencyParserwith a beam and a scoring cache.- Parameters:
model- The model to parse with. Must not benull.beamSize- The number of transition sequences to retain. Must be positive;1decodes greedily.scoringCacheBytes- The bytes the scoring cache may use, or0for no cache. Must not be negative. The cache needs room for one slot per vocabulary entry and feature position before it stores a contribution.- Throws:
IllegalArgumentException- Thrown ifmodelisnull,beamSizeis not positive,scoringCacheBytesis negative, or a positivescoringCacheBytesis too small for the model's vocabularies.
-
-
Method Details
-
parse
Parses a sentence into aDependencyTree.- Specified by:
parsein interfaceDependencyParser- Parameters:
tokens- The input tokens. Must not benull, must contain at least one token, and must not containnullentries.tags- The part-of-speech tags aligned withtokens. Must not benull, must have the same length astokens, and must not containnullentries.- Returns:
- A
DependencyTreeover the given tokens. Nevernull. - Throws:
IllegalStateException- Thrown if no model outcome is applicable in a configuration or the model produces a non-finite transition score.
-
greedyParse
Decodes greedily: the highest scoring applicable transition wins each step.- Parameters:
context- The sentence features.tokenCount- The sentence length.- Returns:
- The parse. Never
null. - Throws:
IllegalStateException- Thrown if no model outcome is applicable in a configuration or the model produces a non-finite transition score.
-
beamParse
Decodes with a beam and returns its highest scoring complete sequence.- Parameters:
context- The sentence features.tokenCount- The sentence length.- Returns:
- The parse. Never
null. - Throws:
IllegalStateException- Thrown if no beam path can be advanced by a model outcome or the model produces a non-finite transition score.
-
beamSize
int beamSize()Returns the number of transition sequences the parser retains.- Returns:
- The beam size. Always positive;
1decodes greedily.
-
cache
ContributionCache cache()- Returns:
- The scoring cache, or
nullif the parser was created without one.
-