NLClassifier class

Classifier API for natural language classification tasks, categorizes string into different classes.

The API expects a TFLite model with the following input/output tensor:

  • Input tensor (kTfLiteString) input of the model, accepts a string.
  • Output score tensor (kTfLiteUInt8/kTfLiteInt8/kTfLiteInt16/kTfLiteFloat32/kTfLiteFloat64/kTfLiteBool)
      - output scores for each class, if type is one of the Int types, dequantize it, if it
        is Bool type, convert the values to 0.0 and 1.0 respectively.
    
      - can have an optional associated file in metadata for labels, the file should be a
        plain text file with one label per line, the number of labels should match the number
        of categories the model outputs. Output label tensor: optional (kTfLiteString) -
        output classname for each class, should be of the same length with scores. If this
        tensor is not present, the API uses score indices as classnames. - will be ignored if
        output score tensor already has an associated label file.
    
  • Optional Output label tensor (kTfLiteString/kTfLiteInt32) - output classname for each class, should be of the same length with scores. If this tensor is not present, the API uses score indices as classnames. - will be ignored if output score tensor already has an associated labe file.

By default the API tries to find the input/output tensors with default configurations in NLClassifierOptions, with tensor name prioritized over tensor index. The option is configurable for different TFLite models.

Properties

base Pointer<TfLiteNLClassifier>
no setter
hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

classify(String text) List<Category>
Perform classification on a string input text,
delete() → void
Deletes NLClassifier Instance.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited

Static Methods

create(String modelPath, {NLClassifierOptions? options}) NLClassifier
Create NLClassifier from modelPath and optional options.
createFromAsset(String assetPath, {NLClassifierOptions? options}) Future<NLClassifier>
Create NLClassifier directly from assetPath and optional options.
createFromFile(File modelFile) NLClassifier
Create NLClassifier from modelFile.
createFromFileAndOptions(File modelFile, NLClassifierOptions options) NLClassifier
Create NLClassifier from modelFile and options.