MPPTextEmbedder
@interface MPPTextEmbedder : NSObject@brief Performs embedding extraction on text.
This API expects a TFLite model with (optional) TFLite Model Metadata.
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 tensors:
- Three input tensors
kTfLiteInt32of shape[batch_size x bert_max_seq_len]representing the input ids, mask ids, and segment ids. This input signature requires a Bert Tokenizer process unit in the model metadata. - Or one input tensor
kTfLiteInt32of shape[batch_size x max_seq_len]representing the input ids. This input signature requires a Regex Tokenizer process unit in the model metadata. - Or one input tensor (
kTfLiteString) that is shapeless or has shape[1]containing the input string.
At least one output tensor (kTfLiteFloat32/kTfLiteUint8) with shape [1 x N] where N is
the number of dimensions in the produced embeddings.
-
Creates a new instance of
MPPTextEmbedderfrom an absolute path to a TensorFlow Lite model file stored locally on the device and the defaultMPPTextEmbedderOptions.Declaration
Objective-C
- (nullable instancetype)initWithModelPath:(nonnull NSString *)modelPath error:(NSError *_Nullable *_Nullable)error;Parameters
modelPathAn absolute path to a TensorFlow Lite model file stored locally on the device.
errorAn optional error parameter populated when there is an error in initializing the text embedder.
Return Value
A new instance of
MPPTextEmbedderwith the given model path.nilif there is an error in initializing the text embedder. -
Creates a new instance of
MPPTextEmbedderfrom the givenMPPTextEmbedderOptions.Declaration
Objective-C
- (nullable instancetype)initWithOptions: (nonnull MPPTextEmbedderOptions *)options error:(NSError *_Nullable *_Nullable)error;Parameters
optionsThe options of type
MPPTextEmbedderOptionsto use for configuring theMPPTextEmbedder.errorAn optional error parameter populated when there is an error in initializing the text embedder.
Return Value
A new instance of
MPPTextEmbedderwith the given options.nilif there is an error in initializing the text embedder. -
Performs embedding extraction on the input text.
Declaration
Objective-C
- (nullable MPPTextEmbedderResult *)embedText:(nonnull NSString *)text error:(NSError *_Nullable *_Nullable) error;Parameters
textThe
NSStringon which embedding extraction is to be performed.errorAn optional error parameter populated when there is an error in performing embedding extraction on the input text.
Return Value
A
MPPTextEmbedderResultobject that contains a list of embeddings. -
Undocumented
Declaration
Objective-C
- (instancetype)init NS_UNAVAILABLE; -
Utility function to computecosine similarity between two
MPPEmbeddingobjects.Declaration
Objective-C
+ (nullable NSNumber *) cosineSimilarityBetweenEmbedding1:(nonnull MPPEmbedding *)embedding1 andEmbedding2:(nonnull MPPEmbedding *)embedding2 error:(NSError *_Nullable *_Nullable)error;Parameters
embedding1One of the two
MPPEmbeddings between whom cosine similarity is to be computed.embedding2One of the two
MPPEmbeddings between whom cosine similarity is to be computed.errorAn optional error parameter populated when there is an error in calculating cosine similarity between two embeddings.
Return Value
An
NSNumberwhich holds the cosine similarity of typedouble. -
Undocumented
Declaration
Objective-C
+ (instancetype)new NS_UNAVAILABLE;