Skip to content

Commit

Permalink
OPENNLP-1618 - AbstractDL does not release Ort Resources
Browse files Browse the repository at this point in the history
  • Loading branch information
rzo1 committed Oct 10, 2024
1 parent eb777d2 commit e15a618
Show file tree
Hide file tree
Showing 4 changed files with 228 additions and 197 deletions.
18 changes: 16 additions & 2 deletions opennlp-dl/src/main/java/opennlp/dl/AbstractDL.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
/**
* Base class for OpenNLP deep-learning classes using ONNX Runtime.
*/
public abstract class AbstractDL {
public abstract class AbstractDL implements AutoCloseable {

public static final String INPUT_IDS = "input_ids";
public static final String ATTENTION_MASK = "attention_mask";
Expand All @@ -50,7 +50,6 @@ public abstract class AbstractDL {
*
* @param vocabFile The vocabulary file.
* @return A map of vocabulary words to integer IDs.
*
* @throws IOException Thrown if the vocabulary file cannot be opened or read.
*/
public Map<String, Integer> loadVocab(final File vocabFile) throws IOException {
Expand All @@ -66,4 +65,19 @@ public Map<String, Integer> loadVocab(final File vocabFile) throws IOException {
return vocab;
}

/**
* Closes this resource, relinquishing any underlying resources.
*
* @throws Exception If it failed to close.
*/
@Override
public void close() throws Exception {
if (session != null) {
session.close();
}
if (env != null) {
env.close();
}
}

}
Loading

0 comments on commit e15a618

Please sign in to comment.