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.
Input tensors
- 1 input tensor that is scalar or has shape [1] containing the input string.
Output tensor
- 1 output tensor of shape
[1 x N]whereNis the number of languages.
Methods
close
close
()
->
None
Shuts down the mediapipe text task instance.
RuntimeError
create_from_model_path
@classmethodcreate_from_model_path ( model_path : str ) -> 'LanguageDetector'
Creates an LanguageDetector
object from a TensorFlow Lite model and the default LanguageDetectorOptions
.
model_path
LanguageDetector
object that's created from the model file and the
default LanguageDetectorOptions
.
ValueError
LanguageDetector
object from the
provided
file such as invalid file path.RuntimeError
create_from_options
@classmethodcreate_from_options ( options :mp . tasks . text . LanguageDetectorOptions) -> 'LanguageDetector'
Creates the LanguageDetector
object from language detector options.
options
LanguageDetector
object that's created from options
.
ValueError
LanguageDetector
object from LanguageDetectorOptions
such as missing the model.RuntimeError
detect
detect
(
text
:
str
)
->
mp
.
tasks
.
text
.
LanguageDetectorResult
Predicts the language of the input text
.
LanguageDetectorResult
object that contains a list of languages and
scores.
ValueError
RuntimeError
__enter__
__enter__
()
Returns self
upon entering the runtime context.
__exit__
__exit__
(
unused_exc_type
,
unused_exc_value
,
unused_traceback
)
Shuts down the mediapipe text task instance on exit of the context manager.
RuntimeError


