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
convenienceinit(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.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-05-08 UTC."],[],[],null,["# MediaPipeTasksText Framework Reference\n\nLanguageDetector\n================\n\n class LanguageDetector : NSObject\n\n@brief Predicts the language of an input text.\n\nThis API expects a TFLite model with [TFLite Model\nMetadata](https://www.tensorflow.org/lite/convert/metadata%22)that contains the mandatory\n(described below) input tensor, output tensor, and the language codes in an AssociatedFile.\n\nMetadata is required for models with int32 input tensors because it contains the input\nprocess unit for the model's Tokenizer. No metadata is required for models with string\ninput tensors.\n\nInput tensor\n\n- One input tensor (`kTfLiteString`) of shape `[1]` containing the input string.\n\nOutput tensor\n\n- One output tensor (`kTfLiteFloat32`) of shape `[1 x N]` where `N` is the number of languages.\n- `\n ``\n ``\n `\n\n ### [init(modelPath:)](#/c:objc(cs)MPPLanguageDetector(im)initWithModelPath:error:)\n\n `\n ` \n Creates a new instance of `LanguageDetector` from an absolute path to a TensorFlow Lite\n model file stored locally on the device and the default [LanguageDetectorOptions](../Classes/LanguageDetectorOptions.html). \n\n #### Declaration\n\n Swift \n\n convenience init(modelPath: String) throws\n\n #### Parameters\n\n |-------------------|-----------------------------------------------------------------------------------------------------|\n | ` `*modelPath*` ` | An absolute path to a TensorFlow Lite model file stored locally on the device. |\n | ` `*error*` ` | An optional error parameter populated when there is an error in initializing the language detector. |\n\n #### Return Value\n\n A new instance of `LanguageDetector` with the given model path. `nil` if there is an\n error in initializing the language detector.\n- `\n ``\n ``\n `\n\n ### [init(options:)](#/c:objc(cs)MPPLanguageDetector(im)initWithOptions:error:)\n\n `\n ` \n Creates a new instance of `LanguageDetector` from the given [LanguageDetectorOptions](../Classes/LanguageDetectorOptions.html). \n\n #### Declaration\n\n Swift \n\n init(options: ../Classes/LanguageDetectorOptions.html) throws\n\n #### Parameters\n\n |-----------------|---------------------------------------------------------------------------------------------------------------------------------------|\n | ` `*options*` ` | The options of type [LanguageDetectorOptions](../Classes/LanguageDetectorOptions.html) to use for configuring the `LanguageDetector`. |\n | ` `*error*` ` | An optional error parameter populated when there is an error in initializing the language detector. |\n\n #### Return Value\n\n A new instance of `LanguageDetector` with the given options. `nil` if there is an\n error in initializing the language detector.\n- `\n ``\n ``\n `\n\n ### [detect(text:)](#/c:objc(cs)MPPLanguageDetector(im)detectText:error:)\n\n `\n ` \n Predicts the language of the input text. \n\n #### Declaration\n\n Swift \n\n func detect(text: String) throws -\u003e ../Classes/LanguageDetectorResult.html\n\n #### Parameters\n\n |---------------|-------------------------------------------------------------------------------------------------------------------|\n | ` `*text*` ` | The `NSString` for which language is to be predicted. |\n | ` `*error*` ` | An optional error parameter populated when there is an error in performing language prediction on the input text. |\n\n #### Return Value\n\n A [LanguageDetectorResult](../Classes/LanguageDetectorResult.html) object that contains a list of language predictions.\n- `\n ``\n ``\n `\n\n ### [-init](#/c:objc(cs)MPPLanguageDetector(im)init)\n\n `\n ` \n Undocumented\n- `\n ``\n ``\n `\n\n ### [+new](#/c:objc(cs)MPPLanguageDetector(cm)new)\n\n `\n ` \n Undocumented"]]