Classifier API for natural language classification tasks, categorizes string into different classes.
The API expects a TFLite model with the following input/output tensor:
By default the API tries to find the input/output tensors with default configurations in
NLClassifier.NLClassifierOptions
, with tensor name prioritized over tensor index. The option is
configurable for different TFLite models.
class | NLClassifier.NLClassifierOptions | Options to identify input and output tensors of the model. |
List<Category> | |
static NLClassifier | |
static NLClassifier |
createFromFile(Context context, String modelPath)
Creates
NLClassifier from default NLClassifier.NLClassifierOptions . |
static NLClassifier | |
static NLClassifier |
createFromFileAndOptions(File modelFile, NLClassifier.NLClassifierOptions options)
Creates
NLClassifier from NLClassifier.NLClassifierOptions . |
static NLClassifier |
createFromFileAndOptions(Context context, String modelPath, NLClassifier.NLClassifierOptions options)
Creates
NLClassifier from NLClassifier.NLClassifierOptions . |
Performs classification on a string input, returns classified Category
s.
text | input text to the model |
---|
Creates NLClassifier
with a model ByteBuffer
and NLClassifier.NLClassifierOptions
.
modelBuffer | a direct ByteBuffer or a MappedByteBuffer of the
classification model |
---|---|
options | configurations for the model |
NLClassifier
instanceIllegalStateException | if there is an internal error |
---|---|
RuntimeException | if there is an otherwise unspecified error |
IllegalArgumentException | if the model buffer is not a direct ByteBuffer or a
MappedByteBuffer
|
Creates NLClassifier
from default NLClassifier.NLClassifierOptions
.
context | Android context |
---|---|
modelPath | path to the classification model relative to asset dir |
NLClassifier
instanceIOException | if model file fails to load |
---|---|
IllegalArgumentException | if an argument is invalid |
IllegalStateException | if there is an internal error |
RuntimeException | if there is an otherwise unspecified error |
Creates NLClassifier
from default NLClassifier.NLClassifierOptions
.
modelFile | the classification model File instance |
---|
NLClassifier
instanceIOException | if model file fails to load |
---|---|
IllegalArgumentException | if an argument is invalid |
IllegalStateException | if there is an internal error |
RuntimeException | if there is an otherwise unspecified error |
Creates NLClassifier
from NLClassifier.NLClassifierOptions
.
modelFile | the classification model File instance |
---|---|
options | configurations for the model |
NLClassifier
instanceIOException | if model file fails to load |
---|---|
IllegalArgumentException | if an argument is invalid |
IllegalStateException | if there is an internal error |
RuntimeException | if there is an otherwise unspecified error |
Creates NLClassifier
from NLClassifier.NLClassifierOptions
.
context | Android context |
---|---|
modelPath | path to the classification model relative to asset dir |
options | configurations for the model. |
NLClassifier
instanceIOException | if model file fails to load |
---|---|
IllegalArgumentException | if an argument is invalid |
IllegalStateException | if there is an internal error |
RuntimeException | if there is an otherwise unspecified error |