Introducing LiteRT : Google's high-performance runtime for on-device AI, formerly known as TensorFlow Lite.
Learn more
Send feedback
mp.tasks.text.LanguageDetector
Class that predicts the language of an input text.
mp . tasks . text . LanguageDetector (
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 TFLite Model Metadata that contains the
mandatory (described below) input tensors, output tensor, and the language
codes in an AssociatedFile.
(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.
Args
graph_config
The mediapipe text task graph config proto.
Methods
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
) -> 'LanguageDetector'
Creates an LanguageDetector
object from a TensorFlow Lite model and the default LanguageDetectorOptions
.
Args
model_path
Path to the model.
Returns
LanguageDetector
object that's created from the model file and the
default LanguageDetectorOptions
.
Raises
ValueError
If failed to create LanguageDetector
object 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 . LanguageDetectorOptions
) -> 'LanguageDetector'
Creates the LanguageDetector
object from language detector options.
Args
options
Options for the language detector task.
Returns
LanguageDetector
object that's created from options
.
Raises
ValueError
If failed to create LanguageDetector
object from
LanguageDetectorOptions
such as missing the model.
RuntimeError
If other types of error occurred.
detect
View source
detect (
text : str
) -> mp . tasks . text . LanguageDetectorResult
Predicts the language of the input text
.
Args
text
The input text.
Returns
A LanguageDetectorResult
object that contains a list of languages and
scores.
Raises
ValueError
If any of the input arguments is invalid.
RuntimeError
If language detection failed to run.
__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.
Send feedback
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License , and code samples are licensed under the Apache 2.0 License . For details, see the Google Developers Site Policies . Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2024-05-01 UTC.
Need to tell us more?
[[["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."],[],[]]