krickert commented on code in PR #1106:
URL: https://github.com/apache/opennlp/pull/1106#discussion_r3541327885


##########
opennlp-docs/src/docbkx/namefinder.xml:
##########
@@ -155,13 +155,81 @@ Span[] nameSpans = nameFinder.find(sentence);]]>
                                        <programlisting language="java">
 <![CDATA[File model = new File("/path/to/model.onnx");
 File vocab = new File("/path/to/vocab.txt");
-Map<Integer, String> categories = new HashMap<>();
-String[] tokens = new String[]{"George", "Washington", "was", "president", 
"of", "the", "United", "States", "."};
-NameFinderDL nameFinderDL = new NameFinderDL(model, vocab, false, 
getIds2Labels());
-Span[] spans = nameFinderDL.find(tokens);]]>
+// Maps every model output index to its BIO label. This must be exhaustive 
over the model's
+// output indices; an unmapped predicted index raises IllegalStateException 
during find().
+Map<Integer, String> ids2Labels = new HashMap<>();
+ids2Labels.put(0, "O");
+ids2Labels.put(1, "B-PER");
+ids2Labels.put(2, "I-PER");
+ids2Labels.put(3, "B-ORG");
+ids2Labels.put(4, "I-ORG");
+ids2Labels.put(5, "B-LOC");
+ids2Labels.put(6, "I-LOC");
+ids2Labels.put(7, "B-MISC");
+ids2Labels.put(8, "I-MISC");
+SentenceDetector sentenceDetector =
+    new SentenceDetectorME(new SentenceModel(new 
File("/path/to/en-sent.bin")));

Review Comment:
   Yep!  Done.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to