chromium/third_party/tflite_support/src/tensorflow_lite_support/cc/task/text/text_embedder.cc

/* Copyright 2022 The TensorFlow Authors. All Rights Reserved.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/

#include "tensorflow_lite_support/cc/task/text/text_embedder.h"

#include "absl/status/status.h"  // from @com_google_absl
#include "tensorflow_lite_support/cc/common.h"
#include "tensorflow_lite_support/cc/port/status_macros.h"
#include "tensorflow_lite_support/cc/port/statusor.h"
#include "tensorflow_lite_support/cc/task/core/task_api_factory.h"
#include "tensorflow_lite_support/cc/task/processor/bert_preprocessor.h"
#include "tensorflow_lite_support/cc/task/processor/regex_preprocessor.h"
#include "tensorflow_lite_support/cc/task/processor/text_preprocessor.h"
#include "tensorflow_lite_support/cc/task/processor/universal_sentence_encoder_preprocessor.h"
#include "tensorflow_lite_support/cc/task/text/utils/bert_utils.h"
#include "tensorflow_lite_support/cc/task/text/utils/universal_sentence_encoder_utils.h"

namespace tflite {
namespace task {
namespace text {

namespace {

StatusCode;
CreateStatusWithPayload;
StatusOr;
TfLiteSupportStatus;
TaskAPIFactory;
EmbeddingResult;
FeatureVector;

// Expected index of the response encoding output tensor in Universal Sentence
// Encoder models, as returned by GetUniversalSentenceEncoderOutputIndices().
constexpr int kUSEResponseEncodingIndex =;

absl::Status SanityCheckOptions(const TextEmbedderOptions& options) {}

}  // namespace

/* static */
tflite::support::StatusOr<double> TextEmbedder::CosineSimilarity(
    const FeatureVector& u, const FeatureVector& v) {}

/* static */
tflite::support::StatusOr<std::unique_ptr<TextEmbedder>>
TextEmbedder::CreateFromOptions(const TextEmbedderOptions& options,
                                std::unique_ptr<tflite::OpResolver> resolver) {}

absl::Status TextEmbedder::Init(std::unique_ptr<TextEmbedderOptions> options) {}

tflite::support::StatusOr<EmbeddingResult> TextEmbedder::Embed(
    const std::string& text) {}

absl::Status TextEmbedder::Preprocess(
    const std::vector<TfLiteTensor*>& input_tensors, const std::string& input) {}

// TODO(b/215239176): Creates base Embedder class to share Postprocess /
// GetEmbeddingDimension / GetNumberOfOutputLayers / CosineSimilarity /
// Init (how it creates postprocessors) funcrions between
// Image/Text/AudioEmbedder.
tflite::support::StatusOr<EmbeddingResult> TextEmbedder::Postprocess(
    const std::vector<const TfLiteTensor*>& output_tensors,
    const std::string& input) {}

int TextEmbedder::GetEmbeddingDimension(int output_index) const {}

int TextEmbedder::GetNumberOfOutputLayers() const {}

}  // namespace text
}  // namespace task
}  // namespace tflite