Class NameFinderME
- All Implemented Interfaces:
Probabilistic,TokenNameFinder
name finder implementation.
A name finder instance is thread-safe. One instance can be shared across multiple threads to save memory.
Note: In container environments with classloader isolation (e.g. Jakarta EE), ensure instances do
not outlive the application's lifecycle, as underlying components use ThreadLocal state that may
pin the classloader.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final AdditionalContextFeatureGeneratorOne shared additional-context feature generator perNameFinderMEinstance.protected final NameContextGeneratorstatic final Stringstatic final intprivate static final String[][]private final LastResultOwnerOrThreadLocal<Sequence> protected final SequenceClassificationModelstatic final Stringprivate final SequenceCodec<String> private final SequenceValidator<String> static final String -
Constructor Summary
ConstructorsConstructorDescriptionNameFinderME(TokenNameFinderModel model) Initializes aNameFinderMEwith aTokenNameFinderModel. -
Method Summary
Modifier and TypeMethodDescriptionvoidForgets all adaptive data which was collected during previous calls to one of the find methods.voidReleases the calling thread's per-thread state for thisNameFinderME(the last decoded sequence stashed forprobs()access, plus the additional-context slot held byAdditionalContextFeatureGenerator).static Span[]dropOverlappingSpans(Span[] spans) Removesspanswith are intersecting or crossing in any way.Span[]Generates name tags for the given sequence, typically a sentence, returningtoken spansfor any identified names.Span[]Generates name tags for the given sequence, typically a sentence, returningtoken spansfor any identified names.double[]probs()Retrieves the probabilities of the last decoded sequence.voidprobs(double[] probs) Populates the specified array with the probabilities of the last decoded sequence.double[]Retrieves an array of probabilities for each of the specified spans which is the arithmetic mean of the probabilities for each of the outcomes which make up the span.private Span[]Sets probabilities for the spans.static TokenNameFinderModeltrain(String languageCode, String type, ObjectStream<NameSample> samples, TrainingParameters params, TokenNameFinderFactory factory) Starts a training of aTokenNameFinderModelwith the given parameters.
-
Field Details
-
EMPTY
-
DEFAULT_BEAM_SIZE
public static final int DEFAULT_BEAM_SIZE- See Also:
-
START
- See Also:
-
CONTINUE
- See Also:
-
OTHER
- See Also:
-
seqCodec
-
model
-
contextGenerator
-
lastBestSequence
Per-threadbestSequenceforprobs()/probs(double[])access. Uses the owner-fast-path helper so single-threaded short-lived instances don't allocate aThreadLocalmap entry; once a second thread touches the same instance, non-owner threads transition toThreadLocalstorage. Same pattern used byPOSTaggerMEet al. -
additionalContextFeatureGenerator
One shared additional-context feature generator perNameFinderMEinstance. The generator itself is@ThreadSafeand keeps the per-thread additional-context array via its ownThreadLocal, so we don't need a per-thread wrapper here (which would have been a redundant nestedThreadLocal). -
sequenceValidator
-
-
Constructor Details
-
NameFinderME
Initializes aNameFinderMEwith aTokenNameFinderModel.- Parameters:
model- TheTokenNameFinderModelto initialize with.
-
-
Method Details
-
find
Description copied from interface:TokenNameFinderGenerates name tags for the given sequence, typically a sentence, returningtoken spansfor any identified names.- Specified by:
findin interfaceTokenNameFinder- Parameters:
tokens- An array of the tokens or words of the sequence, typically a sentence.- Returns:
- An array of
spansfor each of the names identified.
-
find
Generates name tags for the given sequence, typically a sentence, returningtoken spansfor any identified names.- Parameters:
tokens- An array of the tokens or words of a sequence, typically a sentence.additionalContext- Features based on context outside of the sentence but which should also be used.- Returns:
- An array of
token spansfor each of the names identified.
-
clearAdaptiveData
public void clearAdaptiveData()Description copied from interface:TokenNameFinderForgets all adaptive data which was collected during previous calls to one of the find methods.Note: This method should typically be called at the end of the processing of a document.
- Specified by:
clearAdaptiveDatain interfaceTokenNameFinder
-
probs
public void probs(double[] probs) Populates the specified array with the probabilities of the last decoded sequence. The sequence was determined based on the previous call tofind(String[]). The specified array should be at least as large as the number of tokens in the previous call tofind(String[]).- Parameters:
probs- An array with the probabilities of the last decoded sequence.
-
probs
public double[] probs()Retrieves the probabilities of the last decoded sequence. The sequence was determined based on the previous call tofind(String[]).- Specified by:
probsin interfaceProbabilistic- Returns:
- an array with the same number of probabilities as tokens were sent to
find(String[])when it was last called
-
setProbs
Sets probabilities for the spans. -
probs
Retrieves an array of probabilities for each of the specified spans which is the arithmetic mean of the probabilities for each of the outcomes which make up the span.- Parameters:
spans- Thespansof the names for which probabilities are requested.- Returns:
- An array of probabilities for each of the specified spans.
-
clearThreadLocalState
public void clearThreadLocalState()Releases the calling thread's per-thread state for thisNameFinderME(the last decoded sequence stashed forprobs()access, plus the additional-context slot held byAdditionalContextFeatureGenerator).This is intentionally a per-thread, not a per-instance, operation: a single
NameFinderMEis typically shared across many pool threads, and each one owns an independent slot. Call this when a worker thread is being returned to a pool, or when the name finder is being disposed in a container with classloader isolation.Note that this does not release per-thread state inside the underlying
BeamSearchcache or other feature generators in the pipeline; those live for the duration of the owning thread. -
train
public static TokenNameFinderModel train(String languageCode, String type, ObjectStream<NameSample> samples, TrainingParameters params, TokenNameFinderFactory factory) throws IOException Starts a training of aTokenNameFinderModelwith the given parameters.- Parameters:
languageCode- The ISO conform language code.type- The type to use.samples- TheObjectStreamofNameSampleused as input for training.params- TheTrainingParametersfor the context of the training.factory- TheTokenNameFinderFactoryfor creating related objects defined viaparams.- Returns:
- A valid, trained
TokenNameFinderModelinstance. - Throws:
IOException- Thrown if IO errors occurred during training.
-
dropOverlappingSpans
Removesspanswith are intersecting or crossing in any way.The following rules are used to remove the spans:
Identical spans: The first span in the array after sorting it remains.
Intersecting spans: The first span after sorting remains.
Contained spans: All spans which are contained by another are removed.
-