public final class TensorflowNLU extends Object implements NLUService
This component uses a pre-trained TensorFlow Lite model to classify user utterances into intents and extract slot values. Metadata supplied alongside the model is used to determine the types of any slot values detected. Classification is performed on a background thread.
This component supports the following configuration properties:
slotType type. For
example, a custom slot parser used to parse slots listed as user
in the NLU metadata should be provided under the key slot-user.
| Modifier and Type | Class and Description |
|---|---|
static class |
TensorflowNLU.Builder
Fluent builder interface for initializing a TensorFlow NLU model.
|
| Constructor and Description |
|---|
TensorflowNLU(SpeechConfig speechConfig,
NLUContext nluContext)
Public constructor for
NLUManager participation. |
| Modifier and Type | Method and Description |
|---|---|
void |
addListener(TraceListener listener)
Add a new listener to receive trace events from the NLU subsystem.
|
AsyncResult<NLUResult> |
classify(String utterance)
Classify a user utterance, returning a wrapper that can either block
until the classification is complete or call a registered callback when
the result is ready.
|
AsyncResult<NLUResult> |
classify(String utterance,
NLUContext nluContext)
Classifies a user utterance.
|
void |
close() |
void |
removeListener(TraceListener listener)
Remove a trace listener, allowing it to be garbage collected.
|
public TensorflowNLU(SpeechConfig speechConfig, NLUContext nluContext)
NLUManager participation. Uses a WordpieceTextEncoder and a default TensorFlow model loader.
The model and text encoder are loaded on a background thread.
speechConfig - configuration propertiesnluContext - The context used to register listeners and deliver
trace and error events.public void close()
throws Exception
close in interface AutoCloseableExceptionpublic AsyncResult<NLUResult> classify(String utterance)
utterance - The utterance to classify.public AsyncResult<NLUResult> classify(String utterance, NLUContext nluContext)
NLUServiceAsyncResult allows the
caller to either block while waiting for a result or register a callback
to be executed when the result is available.classify in interface NLUServiceutterance - The user utterance to be classified.nluContext - The current NLU context, containing request metadata and
the ability to fire trace events.AsyncResult representing the result of the
classification task.AsyncResult.registerCallback(io.spokestack.spokestack.util.Callback)public void addListener(TraceListener listener)
listener - The listener to add.public void removeListener(TraceListener listener)
listener - The listener to remove.Copyright © 2021. All rights reserved.