Class that performs classification on text.
mp
.
tasks
.
text
.
TextClassifier
(
graph_config
:
mp
.
calculators
.
core
.
constant_side_packet_calculator_pb2
.
mediapipe_dot_framework_dot_calculator__pb2
.
CalculatorGraphConfig
)
->
None
This API expects a TFLite model with (optional) TFLite Model Metadata that contains the mandatory (described below) input tensors, output tensor, and the optional (but recommended) category labels as AssociatedFiles with type TENSOR_AXIS_LABELS per output classification tensor. Metadata is required for models with int32 input tensors because it contains the input process unit for the model's Tokenizer. No metadata is required for models with string input tensors.
Input tensors
- 3 input tensors of size
[batch_size x bert_max_seq_len]representing the input ids, segment ids, and mask ids - or 1 input tensor of size
[batch_size x max_seq_len]representing the input ids or (kTfLiteString) - 1 input tensor that is shapeless or has shape [1] containing the input string
At least one output tensor with: (kTfLiteFloat32/kBool)
-
[1 x N]array withNrepresents the number of categories. - optional (but recommended) category labels as AssociatedFiles with type
TENSOR_AXIS_LABELS, containing one label per line. The first such
AssociatedFile (if any) is used to fill the
category_namefield of the results. Thedisplay_namefield is filled from the AssociatedFile (if any) whose locale matches thedisplay_names_localefield of theTextClassifierOptionsused at creation time ("en" by default, i.e. English). If none of these are available, only theindexfield of the results will be filled.
Methods
classify
classify
(
text
:
str
)
->
mp
.
tasks
.
audio
.
AudioClassifierResult
Performs classification on the input text
.
TextClassifierResult
object that contains a list of text
classifications.
ValueError
RuntimeError
close
close
()
->
None
Shuts down the mediapipe text task instance.
RuntimeError
create_from_model_path
@classmethodcreate_from_model_path ( model_path : str ) -> 'TextClassifier'
Creates an TextClassifier
object from a TensorFlow Lite model and the default TextClassifierOptions
.
model_path
TextClassifier
object that's created from the model file and the
default TextClassifierOptions
.
ValueError
TextClassifier
object from the provided
file such as invalid file path.RuntimeError
create_from_options
@classmethodcreate_from_options ( options :mp . tasks . text . TextClassifierOptions) -> 'TextClassifier'
Creates the TextClassifier
object from text classifier options.
options
TextClassifier
object that's created from options
.
ValueError
TextClassifier
object from TextClassifierOptions
such as missing the model.RuntimeError
__enter__
__enter__
()
Returns self
upon entering the runtime context.
__exit__
__exit__
(
unused_exc_type
,
unused_exc_value
,
unused_traceback
)
Shuts down the mediapipe text task instance on exit of the context manager.
RuntimeError


