NLUTensorflow
@objc
public class NLUTensorflow : NSObject, NLUService
This is the client entry point for the Spokestack BERT NLU implementation. This class provides a classification interface for deriving intents and slots from a natural language utterance. When initialized, the TTS system communicates with the client via either a delegate that receive events or the publisher-subscriber pattern.
// assume that self implements the `SpokestackDelegate` protocol
let nlu = try! NLUTensorflow(self, configuration: configuration)
nlu.classify(utterance: "I can't turn that light in the room on for you, Dave", context: [:])
Using the NLUTensorflow class requires the providing a number of `SpeechConfiguration` variables, all prefixed with `nlu`. The most important are the `nluVocabularyPath`, `nluModelPath`, and the `nluModelMetadataPath`.
-
Configuration parameters for the NLU.
Declaration
Swift
@objc public var configuration: SpeechConfiguration
-
An implementation of NLUDelegate to receive NLU events.
Declaration
Swift
@objc public var delegates: [SpokestackDelegate]
-
Initializes an NLU instance.
Note
An instance initialized this way is expected to use the pub/sub Combine interface, not the delegate interface, when callingclassify
.Declaration
Swift
@objc public init(configuration: SpeechConfiguration) throws
Parameters
configuration
Configuration parameters for the NLU.
-
Initializes an NLU instance.
Declaration
Swift
@objc required public init(_ delegates: [SpokestackDelegate], configuration: SpeechConfiguration) throws
Parameters
delegate
Delegate that receives NLU events.
configuration
Configuration parameters for the NLU.
-
Classifies the provided input. The classification results are sent to the instance’s configured NLUDelegate.
Declaration
Swift
@objc public func classify(utterance: String, context: [String : Any] = [:])
Parameters
utterance
The provided utterance to classify.
context
Context for NLU operations
-
Classifies the provided input. NLUResult is sent to all subscribers.
Warning
classify
is resource-intensive and should be used withsubscribe(on:)
to ensure it is not blocking the UI thread.Declaration
Swift
@available(iOS 13.0, *) public func classify(utterances: [String], context: [String : Any] = [:]) -> Publishers.Sequence<[Result<NLUResult, Error>], Never>
Parameters
utterances
A list of utterances to classify
context
Context for NLU operations
Return Value
AnyPublisher<[NLUResult], Error>