Class FeedforwardDependencyParser

java.lang.Object
opennlp.tools.depparse.FeedforwardDependencyParser
All Implemented Interfaces:
opennlp.tools.depparse.DependencyParser

@ThreadSafe public class FeedforwardDependencyParser extends Object implements opennlp.tools.depparse.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:
  • Constructor Details

    • FeedforwardDependencyParser

      public FeedforwardDependencyParser(FeedforwardDependencyModel model)
      Initializes a FeedforwardDependencyParser with the beam size of the model and without a scoring cache.
      Parameters:
      model - The model to parse with. Must not be null.
      Throws:
      IllegalArgumentException - Thrown if model is null.
      See Also:
    • FeedforwardDependencyParser

      public FeedforwardDependencyParser(FeedforwardDependencyModel model, int beamSize)
      Initializes a FeedforwardDependencyParser with a beam and without a scoring cache.
      Parameters:
      model - The model to parse with. Must not be null.
      beamSize - The number of transition sequences to retain. Must be positive; 1 decodes greedily.
      Throws:
      IllegalArgumentException - Thrown if model is null or beamSize is not positive.
    • FeedforwardDependencyParser

      public FeedforwardDependencyParser(FeedforwardDependencyModel model, int beamSize, long scoringCacheBytes)
      Initializes a FeedforwardDependencyParser with a beam and a scoring cache.
      Parameters:
      model - The model to parse with. Must not be null.
      beamSize - The number of transition sequences to retain. Must be positive; 1 decodes greedily.
      scoringCacheBytes - The bytes the scoring cache may use, or 0 for 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 if model is null, beamSize is not positive, scoringCacheBytes is negative, or a positive scoringCacheBytes is too small for the model's vocabularies.
  • Method Details

    • parse

      public opennlp.tools.depparse.DependencyTree parse(String[] tokens, String[] tags)
      Specified by:
      parse in interface opennlp.tools.depparse.DependencyParser
      Throws:
      IllegalStateException - Thrown if no model outcome is applicable in a configuration or the model produces a non-finite transition score.