Package opennlp.tools.depparse
Class FeedforwardDependencyModel
java.lang.Object
opennlp.tools.util.model.BaseModel
opennlp.tools.depparse.FeedforwardDependencyModel
- All Implemented Interfaces:
Serializable,ArtifactProvider
The persisted form of a trained
FeedforwardDependencyParser: the network
weights plus the standard model manifest, serialized and loaded through the same
BaseModel machinery as every other tool model.
The weights are not modified after construction or loading. A model can be
shared between threads and between parsers; refine trains a copy and returns a new model.
- Since:
- 3.0.0
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final StringThe component name recorded in the model manifest.private static final intThe beam size of a model that was not refined with beam search.(package private) static final StringThe artifact map entry holding the network.private static final StringThe artifact extension the network serializer is registered under.private static final longFields inherited from class opennlp.tools.util.model.BaseModel
artifactMap, FACTORY_NAME, MANIFEST_ENTRY, toolFactory, TRAINING_CUTOFF_PROPERTY, TRAINING_EVENTHASH_PROPERTY, TRAINING_ITERATIONS_PROPERTY -
Constructor Summary
ConstructorsConstructorDescriptionFeedforwardDependencyModel(File modelFile) Initializes aFeedforwardDependencyModelfrom a serialized model file.Initializes aFeedforwardDependencyModelfrom a serialized model.FeedforwardDependencyModel(String languageCode, FeedforwardNetwork network, Map<String, String> manifestInfoEntries) Initializes aFeedforwardDependencyModelfrom a trained network.FeedforwardDependencyModel(Path modelPath) Initializes aFeedforwardDependencyModelfrom a serialized model file. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidcreateArtifactSerializers(Map<String, ArtifactSerializer<?>> serializers) Registers allArtifactSerializerfor their artifact file name extensions.intReturns the beam size a parser uses when none is given: the beam size the model was refined with, which the manifest records under "BeamSize", or1(greedy) for a model that was not refined.private static booleanisPositiveInteger(String value) Tells whether a manifest value is a positive decimal integer.(package private) FeedforwardNetworknetwork()protected voidValidates the parsed artifacts.Methods inherited from class opennlp.tools.util.model.BaseModel
checkArtifactMap, createArtifactSerializers, deserialize, getArtifact, getArtifactSerializer, getDefaultFactory, getLanguage, getManifestProperty, getVersion, isLoadedFromSerialized, serialize, serialize, serialize, setManifestProperty, skipEntryForSerialization
-
Field Details
-
serialVersionUID
private static final long serialVersionUID- See Also:
-
COMPONENT_NAME
The component name recorded in the model manifest.- See Also:
-
NETWORK_ENTRY_NAME
The artifact map entry holding the network.- See Also:
-
NETWORK_EXTENSION
The artifact extension the network serializer is registered under.- See Also:
-
GREEDY_BEAM_SIZE
private static final int GREEDY_BEAM_SIZEThe beam size of a model that was not refined with beam search.- See Also:
-
-
Constructor Details
-
FeedforwardDependencyModel
FeedforwardDependencyModel(String languageCode, FeedforwardNetwork network, Map<String, String> manifestInfoEntries) Initializes aFeedforwardDependencyModelfrom a trained network.- Parameters:
languageCode- The ISO language code of the training data. Must not benull.network- The trained network. Must not benull.manifestInfoEntries- Additional entries for the manifest, ornull.- Throws:
IllegalArgumentException- Thrown iflanguageCodeornetworkisnull.
-
FeedforwardDependencyModel
Initializes aFeedforwardDependencyModelfrom a serialized model.- Parameters:
in- The stream to read the model from. Must not benull.- Throws:
IOException- Thrown if reading fails or the content is not a valid model.IllegalArgumentException- Thrown ifinisnull, or if it holds the model package of another component; the cause is anInvalidFormatException.
-
FeedforwardDependencyModel
Initializes aFeedforwardDependencyModelfrom a serialized model file.- Parameters:
modelFile- The file to read the model from. Must not benull.- Throws:
IOException- Thrown if reading fails or the content is not a valid model.IllegalArgumentException- Thrown ifmodelFileisnull, or if it holds the model package of another component; the cause is anInvalidFormatException.
-
FeedforwardDependencyModel
Initializes aFeedforwardDependencyModelfrom a serialized model file.- Parameters:
modelPath- The path to read the model from. Must not benull.- Throws:
IOException- Thrown if reading fails or the content is not a valid model.IllegalArgumentException- Thrown ifmodelPathisnull, or if it holds the model package of another component; the cause is anInvalidFormatException.
-
-
Method Details
-
createArtifactSerializers
Registers allArtifactSerializerfor their artifact file name extensions. The registeredserializersare used to create and serialize resources in the model package.Override this method to register custom
serializers.Note: Subclasses should generally invoke
super.createArtifactSerializersat the beginning of this method.This method is called during construction.
Registers the network serializer.
- Overrides:
createArtifactSerializersin classBaseModel- Parameters:
serializers- The key of the map is the file extension used to look up anArtifactSerializer.
-
validateArtifactMap
Validates the parsed artifacts. If something is not valid, subclasses should throw anInvalidFormatException.Note: Subclasses should generally invoke
super.validateArtifactMapat the beginning of this method.- Overrides:
validateArtifactMapin classBaseModel- Throws:
InvalidFormatException- Thrown if the network artifact is missing or not a feedforward network, or the manifest records a beam size that is not a positive integer.
-
getBeamSize
public int getBeamSize()Returns the beam size a parser uses when none is given: the beam size the model was refined with, which the manifest records under "BeamSize", or1(greedy) for a model that was not refined.- Returns:
- The beam size. Always positive.
-
isPositiveInteger
Tells whether a manifest value is a positive decimal integer.- Parameters:
value- The manifest value. Must not benull.- Returns:
trueifvalueparses as anintabove zero.
-
network
FeedforwardNetwork network()- Returns:
- The network. Never
null.
-