Class AbstractDL
java.lang.Object
opennlp.dl.AbstractDL
- All Implemented Interfaces:
AutoCloseable
- Direct Known Subclasses:
DocumentCategorizerDL, NameFinderDL, SentenceVectorsDL
Base class for OpenNLP deep-learning classes using ONNX Runtime.
-
Field Details
-
INPUT_IDS
- See Also:
-
ATTENTION_MASK
- See Also:
-
TOKEN_TYPE_IDS
- See Also:
-
-
Method Details
-
loadVocab
Loads a vocabularyFilefrom disk. A file with an opening brace as its first non-whitespace character is read as JSON, in one of two layouts: one object that maps each token to a non-negative integer ID, as invocab.json, or a Hugging Facetokenizer.jsonof a WordPiece model, whosemodel.vocabobject supplies the tokens and whoseadded_tokensabsent frommodel.vocabare added with their ids. Any other file is read as plain text with one token per line, the line number being the ID, as invocab.txt. An empty line in a plain text file is skipped but still counts toward the IDs of the lines after it; a line that holds only whitespace is a token. A byte order mark at the start of the file is not content in either format.- Parameters:
vocabFile- The vocabulary file.- Returns:
- A map of vocabulary words to IDs.
- Throws:
IOException- Thrown if the vocabulary file cannot be opened or read.opennlp.tools.util.InvalidFormatException- Thrown if a JSON vocabulary is malformed, contains a value that is not a non-negative integer, or is atokenizer.jsonof another model type than WordPiece or with an added token that conflicts with the vocabulary. The message names the file and the offset, the token, or the unsupported member.
-
close
public void close() throws ai.onnxruntime.OrtExceptionCloses the ONNXOrtSessionowned by this instance.The
OrtEnvironmentis deliberately not closed:OrtEnvironment.getEnvironment()returns a process-wide singleton shared by every deep-learning component, so closing it here would tear down the environment other live components still depend on.This method is idempotent: calling
close()more than once, or calling it on a never-used but successfully constructed instance, is a no-op after the first successful close attempt. The underlyingOrtSession.close()is only invoked once.- Specified by:
closein interfaceAutoCloseable- Throws:
ai.onnxruntime.OrtException- Thrown if the close attempt fails in the native layer.
-