MediaPipeTasksText Framework Reference

TextClassifier

final class TextClassifier

Performs classification on text using a TensorFlow Lite model with optional metadata.

Supports BERT-tokenized, regex-tokenized, and raw string-input classification models, returning per-head category predictions filtered by the configured TextClassifierOptions.

  • Creates a text classifier from a local model file path using default classifier options.

    Declaration

    Swift

    convenience init(modelPath: String) throws

    Parameters

    modelPath

    File-system path to a TensorFlow Lite model asset.

  • Creates a text classifier and initializes the underlying MediaPipe task graph.

    Declaration

    Swift

    init(options: TextClassifierOptions) throws

    Parameters

    options

    Configuration specifying the model asset and classification filters.

  • Classifies the input string and returns predicted categories per model output head.

    Declaration

    Swift

    final func classify(text: String) throws -> TextClassifierResult

    Parameters

    text

    UTF-8 string to classify.

    Return Value

    Classification predictions across all output heads of the model.