1 /* Copyright 2020 The TensorFlow Authors. All Rights Reserved. 2 3 Licensed under the Apache License, Version 2.0 (the "License"); 4 you may not use this file except in compliance with the License. 5 You may obtain a copy of the License at 6 7 http://www.apache.org/licenses/LICENSE-2.0 8 9 Unless required by applicable law or agreed to in writing, software 10 distributed under the License is distributed on an "AS IS" BASIS, 11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 See the License for the specific language governing permissions and 13 limitations under the License. 14 ==============================================================================*/ 15 16 #ifndef TENSORFLOW_LITE_SUPPORT_CUSTOM_OPS_KERNEL_SENTENCEPIECE_MODEL_CONVERTER_H_ 17 #define TENSORFLOW_LITE_SUPPORT_CUSTOM_OPS_KERNEL_SENTENCEPIECE_MODEL_CONVERTER_H_ 18 #include <string> 19 20 #include "tensorflow_lite_support/cc/port/statusor.h" 21 22 namespace tflite { 23 namespace ops { 24 namespace custom { 25 namespace sentencepiece { 26 27 // Converts Sentencepiece configuration to flatbuffer format. 28 // encoding_offset is used by some encoders that combine different encodings. 29 tflite::support::StatusOr<std::string> ConvertSentencepieceModelToFlatBuffer( 30 const std::string& model_config_str, int encoding_offset = 0); 31 32 // Converts Sentencepiece configuration to flatbuffer format for encoder. 33 // encoding_offset is used by some encoders that combine different encodings. 34 tflite::support::StatusOr<std::string> 35 ConvertSentencepieceModelToFlatBufferForDecoder( 36 const std::string& model_config_str, int encoding_offset = 0); 37 38 // The functions that are provided for the Python wrapper. 39 std::string ConvertSentencepieceModel(const std::string& model_string); 40 std::string ConvertSentencepieceModelForDecoder( 41 const std::string& model_string); 42 43 // Returns size of a vocabulary from Sentencepiece configuration in flatbuffer 44 // format. 45 int GetVocabularySize(const std::string& model_string); 46 47 } // namespace sentencepiece 48 } // namespace custom 49 } // namespace ops 50 } // namespace tflite 51 52 #endif // TENSORFLOW_LITE_SUPPORT_CUSTOM_OPS_KERNEL_SENTENCEPIECE_MODEL_CONVERTER_H_ 53