chromium/third_party/mediapipe/src/mediapipe/tasks/cc/text/tokenizers/bert_tokenizer.h

/* Copyright 2022 The MediaPipe Authors.

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 MEDIAPIPE_TASKS_CC_TEXT_TOKENIZERS_BERT_TOKENIZER_H_
#define MEDIAPIPE_TASKS_CC_TEXT_TOKENIZERS_BERT_TOKENIZER_H_

#include <cstddef>
#include <fstream>
#include <string>
#include <vector>

#include "absl/container/flat_hash_map.h"
#include "absl/strings/string_view.h"
#include "mediapipe/tasks/cc/text/tokenizers/tokenizer.h"
#include "mediapipe/tasks/cc/text/utils/vocab_utils.h"
#include "re2/re2.h"
#include "tensorflow_text/core/kernels/wordpiece_tokenizer.h"

namespace mediapipe {
namespace tasks {
namespace text {
namespace tokenizers {

constexpr char kDefaultDelimRe[] =;
constexpr char kDefaultIncludeDelimRe[] =;
constexpr int kDefaultMaxBytesPerToken =;
constexpr int kDefaultMaxCharsPerSubToken =;
constexpr char kDefaultSuffixIndicator[] =;
constexpr bool kDefaultUseUnknownToken =;
constexpr char kDefaultUnknownToken[] =;
constexpr bool kDefaultSplitUnknownChars =;

// Result of wordpiece tokenization including subwords and offsets.
// Example:
// input:                tokenize     me  please
// subwords:             token ##ize  me  plea ##se
// wp_begin_offset:     [0,      5,   9,  12,    16]
// wp_end_offset:       [     5,    8,  11,   16,  18]
// row_lengths:         [2,          1,  1]
struct WordpieceTokenizerResult : TokenizerResult {};
// Options to create a BertTokenizer.
struct BertTokenizerOptions {};

// A flat-hash-map based implementation of WordpieceVocab, used in
// BertTokenizer to invoke tensorflow::text::WordpieceTokenize within.
class FlatHashMapBackedWordpiece : public tensorflow::text::WordpieceVocab {};

// Wordpiece tokenizer for bert models. Initialized with a vocab file or vector.
class BertTokenizer : public mediapipe::tasks::text::tokenizers::Tokenizer {};

}  // namespace tokenizers
}  // namespace text
}  // namespace tasks
}  // namespace mediapipe

#endif  // MEDIAPIPE_TASKS_CC_TEXT_TOKENIZERS_BERT_TOKENIZER_H_