Class that performs embedding extraction on text.
mp
.
tasks
.
text
.
TextEmbedder
(
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 and output tensors. Metadata should contain the input process unit for the model's Tokenizer as well as input / output tensor metadata.
Input tensors
- 3 input tensors of size
[batch_size x bert_max_seq_len]with names "ids", "mask", and "segment_ids" representing the input ids, mask ids, and segment ids respectively. - or 1 input tensor of size
[batch_size x max_seq_len]representing the input ids.
At least one output tensor with: (kTfLiteFloat32)
-
Ncomponents corresponding to theNdimensions of the returned feature vector for this output layer. - Either 2 or 4 dimensions, i.e.
[1 x N]or[1 x 1 x 1 x N].
Methods
close
close
()
->
None
Shuts down the mediapipe text task instance.
RuntimeError
cosine_similarity
@classmethodcosine_similarity ( u :mp . tasks . components . containers . Embedding, v :mp . tasks . components . containers . Embedding) -> float
Utility function to compute cosine similarity between two embedding entries.
May return an InvalidArgumentError if e.g. the feature vectors are of different types (quantized vs. float), have different sizes, or have a an L2-norm of 0.
u
v
ValueError
create_from_model_path
@classmethodcreate_from_model_path ( model_path : str ) -> 'TextEmbedder'
Creates an TextEmbedder
object from a TensorFlow Lite model and the default TextEmbedderOptions
.
model_path
TextEmbedder
object that's created from the model file and the default TextEmbedderOptions
.
ValueError
TextEmbedder
object from the provided
file such as invalid file path.RuntimeError
create_from_options
@classmethodcreate_from_options ( options :mp . tasks . text . TextEmbedderOptions) -> 'TextEmbedder'
Creates the TextEmbedder
object from text embedder options.
options
TextEmbedder
object that's created from options
.
ValueError
TextEmbedder
object from TextEmbedderOptions
such as missing the model.RuntimeError
embed
embed
(
text
:
str
)
->
mp
.
tasks
.
audio
.
AudioEmbedderResult
Performs text embedding extraction on the provided text.
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


