Package opennlp.dl
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. Supports both plain text files (one token per line) and simple JSON vocabulary files mapping tokens to integer IDs. JSON support is intentionally limited to the HuggingFace vocabulary shape; it is not a general-purpose JSON parser.- 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.
-
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.
-