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.
|  | 
|---|
| (kTfLiteInt32) 
3 input tensors of size [batch_size x bert_max_seq_len]representing
the input ids, segment ids, and mask idsor 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 with- Nrepresents 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.
| Args | 
|---|
| graph_config | The mediapipe text task graph config proto. | 
Methods
classify
View source
classify(
    text: str
) -> mp.tasks.audio.AudioClassifierResult
Performs classification on the input text.
| Args | 
|---|
| text | The input text. | 
| Returns | 
|---|
| A TextClassifierResultobject that contains a list of text
classifications. | 
| Raises | 
|---|
| ValueError | If any of the input arguments is invalid. | 
| RuntimeError | If text classification failed to run. | 
close
View source
close() -> None
Shuts down the mediapipe text task instance.
| Raises | 
|---|
| RuntimeError | If the mediapipe text task failed to close. | 
create_from_model_path
View source
@classmethod
create_from_model_path(
    model_path: str
) -> 'TextClassifier'
Creates an TextClassifier object from a TensorFlow Lite model and the default TextClassifierOptions.
| Args | 
|---|
| model_path | Path to the model. | 
| Returns | 
|---|
| TextClassifierobject that's created from the model file and the
defaultTextClassifierOptions. | 
| Raises | 
|---|
| ValueError | If failed to create TextClassifierobject from the provided
file such as invalid file path. | 
| RuntimeError | If other types of error occurred. | 
create_from_options
View source
@classmethod
create_from_options(
    options: mp.tasks.text.TextClassifierOptions
) -> 'TextClassifier'
Creates the TextClassifier object from text classifier options.
| Args | 
|---|
| options | Options for the text classifier task. | 
| Returns | 
|---|
| TextClassifierobject that's created fromoptions. | 
| Raises | 
|---|
| ValueError | If failed to create TextClassifierobject fromTextClassifierOptionssuch as missing the model. | 
| RuntimeError | If other types of error occurred. | 
__enter__
View source
__enter__()
Returns self upon entering the runtime context.
__exit__
View source
__exit__(
    unused_exc_type, unused_exc_value, unused_traceback
)
Shuts down the mediapipe text task instance on exit of the context manager.
| Raises | 
|---|
| RuntimeError | If the mediapipe text task failed to close. |