MediaPipeTasksText Framework Reference

LanguageDetector

class LanguageDetector : NSObject

@brief Predicts the language of an input text.

This API expects a TFLite model with TFLite Model Metadatathat contains the mandatory (described below) input tensor, output tensor, and the language codes in an AssociatedFile.

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 tensor

  • One input tensor (kTfLiteString) of shape [1] containing the input string.

Output tensor

  • One output tensor (kTfLiteFloat32) of shape [1 x N] where N is the number of languages.
  • Creates a new instance of LanguageDetector from an absolute path to a TensorFlow Lite model file stored locally on the device and the default LanguageDetectorOptions.

    Declaration

    Swift

    convenience init(modelPath: String) throws

    Parameters

    modelPath

    An absolute path to a TensorFlow Lite model file stored locally on the device.

    error

    An optional error parameter populated when there is an error in initializing the language detector.

    Return Value

    A new instance of LanguageDetector with the given model path. nil if there is an error in initializing the language detector.

  • Creates a new instance of LanguageDetector from the given LanguageDetectorOptions.

    Declaration

    Swift

    init(options: LanguageDetectorOptions) throws

    Parameters

    options

    The options of type LanguageDetectorOptions to use for configuring the LanguageDetector.

    error

    An optional error parameter populated when there is an error in initializing the language detector.

    Return Value

    A new instance of LanguageDetector with the given options. nil if there is an error in initializing the language detector.

  • Predicts the language of the input text.

    Declaration

    Swift

    func detect(text: String) throws -> LanguageDetectorResult

    Parameters

    text

    The NSString for which language is to be predicted.

    error

    An optional error parameter populated when there is an error in performing language prediction on the input text.

    Return Value

    A LanguageDetectorResult object that contains a list of language predictions.

  • Undocumented

  • Undocumented