This API expects a TFLite model with TFLite Model Metadata that contains the
mandatory (described below) input tensors, output tensor, and the language
codes in an AssociatedFile.
Input tensors
(kTfLiteString)
1 input tensor that is scalar or has shape [1] containing the input
string.
Output tensor
(kTfLiteFloat32)
1 output tensor of shape[1 x N] where N is the number of languages.
[[["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-01 UTC."],[],[],null,["# mp.tasks.text.LanguageDetector\n\n\u003cbr /\u003e\n\n|-------------------------------------------------------------------------------------------------------------------------------------|\n| [View source on GitHub](https://github.com/google/mediapipe/blob/master/mediapipe/tasks/python/text/language_detector.py#L130-L220) |\n\nClass that predicts the language of an input text. \n\n mp.tasks.text.LanguageDetector(\n graph_config: ../../../mp/calculators/core/constant_side_packet_calculator_pb2/mediapipe_dot_framework_dot_calculator__pb2/CalculatorGraphConfig\n ) -\u003e None\n\nThis API expects a TFLite model with TFLite Model Metadata that contains the\nmandatory (described below) input tensors, output tensor, and the language\ncodes in an AssociatedFile.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Input tensors ------------- ||\n|---|---|\n| (kTfLiteString) \u003cbr /\u003e - 1 input tensor that is scalar or has shape \\[1\\] containing the input string. ||\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Output tensor ------------- ||\n|---|---|\n| (kTfLiteFloat32) \u003cbr /\u003e - 1 output tensor of shape`[1 x N]` where `N` is the number of languages. ||\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ---- ||\n|----------------|---------------------------------------------|\n| `graph_config` | The mediapipe text task graph config proto. |\n\n\u003cbr /\u003e\n\nMethods\n-------\n\n### `close`\n\n[View source](https://github.com/google/mediapipe/blob/master/mediapipe/tasks/python/text/core/base_text_task_api.py#L36-L42) \n\n close() -\u003e None\n\nShuts down the mediapipe text task instance.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Raises ||\n|----------------|---------------------------------------------|\n| `RuntimeError` | If the mediapipe text task failed to close. |\n\n\u003cbr /\u003e\n\n### `create_from_model_path`\n\n[View source](https://github.com/google/mediapipe/blob/master/mediapipe/tasks/python/text/language_detector.py#L146-L165) \n\n @classmethod\n create_from_model_path(\n model_path: str\n ) -\u003e 'LanguageDetector'\n\nCreates an `LanguageDetector` object from a TensorFlow Lite model and the default `LanguageDetectorOptions`.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ||\n|--------------|--------------------|\n| `model_path` | Path to the model. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ||\n|---|---|\n| `LanguageDetector` object that's created from the model file and the default `LanguageDetectorOptions`. ||\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Raises ||\n|----------------|-------------------------------------------------------------------------------------------------|\n| `ValueError` | If failed to create `LanguageDetector` object from the provided file such as invalid file path. |\n| `RuntimeError` | If other types of error occurred. |\n\n\u003cbr /\u003e\n\n### `create_from_options`\n\n[View source](https://github.com/google/mediapipe/blob/master/mediapipe/tasks/python/text/language_detector.py#L167-L192) \n\n @classmethod\n create_from_options(\n options: ../../../mp/tasks/text/LanguageDetectorOptions\n ) -\u003e 'LanguageDetector'\n\nCreates the `LanguageDetector` object from language detector options.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ||\n|-----------|-----------------------------------------|\n| `options` | Options for the language detector task. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ||\n|---|---|\n| `LanguageDetector` object that's created from `options`. ||\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Raises ||\n|----------------|---------------------------------------------------------------------------------------------------------|\n| `ValueError` | If failed to create `LanguageDetector` object from `LanguageDetectorOptions` such as missing the model. |\n| `RuntimeError` | If other types of error occurred. |\n\n\u003cbr /\u003e\n\n### `detect`\n\n[View source](https://github.com/google/mediapipe/blob/master/mediapipe/tasks/python/text/language_detector.py#L194-L220) \n\n detect(\n text: str\n ) -\u003e ../../../mp/tasks/text/LanguageDetectorResult\n\nPredicts the language of the input [`text`](https://www.tensorflow.org/text/api_docs/python/text).\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ||\n|----------------------------------------------------------------|-----------------|\n| [`text`](https://www.tensorflow.org/text/api_docs/python/text) | The input text. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ||\n|---|---|\n| A `LanguageDetectorResult` object that contains a list of languages and scores. ||\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Raises ||\n|----------------|-------------------------------------------|\n| `ValueError` | If any of the input arguments is invalid. |\n| `RuntimeError` | If language detection failed to run. |\n\n\u003cbr /\u003e\n\n### `__enter__`\n\n[View source](https://github.com/google/mediapipe/blob/master/mediapipe/tasks/python/text/core/base_text_task_api.py#L44-L46) \n\n __enter__()\n\nReturns `self` upon entering the runtime context.\n\n### `__exit__`\n\n[View source](https://github.com/google/mediapipe/blob/master/mediapipe/tasks/python/text/core/base_text_task_api.py#L48-L54) \n\n __exit__(\n unused_exc_type, unused_exc_value, unused_traceback\n )\n\nShuts down the mediapipe text task instance on exit of the context manager.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Raises ||\n|----------------|---------------------------------------------|\n| `RuntimeError` | If the mediapipe text task failed to close. |\n\n\u003cbr /\u003e"]]