chromium/third_party/tflite_support/src/tensorflow_lite_support/cc/task/text/bert_nl_classifier.h

/* Copyright 2020 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.
==============================================================================*/

#ifndef TENSORFLOW_LITE_SUPPORT_CC_TASK_NLCLASSIFIER_BERT_NL_CLASSIFIER_H_
#define TENSORFLOW_LITE_SUPPORT_CC_TASK_NLCLASSIFIER_BERT_NL_CLASSIFIER_H_

#include <stddef.h>

#include <memory>
#include <string>
#include <vector>

#include "absl/base/macros.h"  // from @com_google_absl
#include "absl/status/status.h"  // from @com_google_absl
#include "tensorflow/lite/c/common.h"
#include "tensorflow/lite/core/api/op_resolver.h"
#include "tensorflow/lite/kernels/register.h"
#include "tensorflow/lite/string_type.h"
#include "tensorflow_lite_support/cc/task/core/category.h"
#include "tensorflow_lite_support/cc/task/processor/bert_preprocessor.h"
#include "tensorflow_lite_support/cc/task/text/nlclassifier/nl_classifier.h"
#include "tensorflow_lite_support/cc/task/text/proto/bert_nl_classifier_options_proto_inc.h"

namespace tflite {
namespace task {
namespace text {

// Classifier API for NLClassification tasks with Bert models, categorizes
// string into different classes.
//
// The API expects a Bert based TFLite model with metadata populated.
// The metadata should contain the following information:
//   - input_process_units for Wordpiece/Sentencepiece Tokenizer
//   - 3 input tensors with names "ids", "mask" and "segment_ids"
//   - 1 output tensor of type float32[1, 2], with a optionally attached label
//     file. If a label file is attached, the file should be a plain text file
//     with one label per line, the number of labels should match the number of
//     categories the model outputs.

class BertNLClassifier : public tflite::task::text::nlclassifier::NLClassifier {};

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

#endif  // TENSORFLOW_LITE_SUPPORT_CC_TASK_NLCLASSIFIER_BERT_NL_CLASSIFIER_H_