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 #ifndef TENSORFLOW_LITE_SUPPORT_CC_TASK_TEXT_NLCLASSIFIER_BERT_NL_CLASSIFIER_C_API_H_ 16 #define TENSORFLOW_LITE_SUPPORT_CC_TASK_TEXT_NLCLASSIFIER_BERT_NL_CLASSIFIER_C_API_H_ 17 18 #include "tensorflow_lite_support/cc/task/text/nlclassifier/nl_classifier_c_api_common.h" 19 // -------------------------------------------------------------------------- 20 /// C API for BertNLClassifier. 21 /// 22 /// The API leans towards simplicity and uniformity instead of convenience, as 23 /// most usage will be by language-specific wrappers. It provides largely the 24 /// same set of functionality as that of the C++ TensorFlow Lite 25 /// `BertNLClassifier` API, but is useful for shared libraries where having 26 /// a stable ABI boundary is important. 27 /// 28 /// Usage: 29 /// <pre><code> 30 /// // Create the model and interpreter options. 31 /// BertNLClassifier* classifier = 32 /// BertNLClassifierFromFile("/path/to/model.tflite"); 33 /// 34 /// // classification. 35 /// Categories* categories = Classify(classifier, context, question); 36 /// 37 /// // Dispose of the API object. 38 /// BertNLClassifierrDelete(classifier); 39 40 #ifdef __cplusplus 41 extern "C" { 42 #endif // __cplusplus 43 44 typedef struct BertNLClassifier BertNLClassifier; 45 46 // Creates BertNLClassifier from model path, returns nullptr if the file 47 // doesn't exist or is not a well formatted TFLite model path. 48 extern BertNLClassifier* BertNLClassifierFromFile(const char* model_path); 49 50 // Invokes the encapsulated TFLite model and classifies the input text. 51 extern struct Categories* BertNLClassifierClassify( 52 const BertNLClassifier* classifier, const char* text); 53 54 extern void BertNLClassifierDelete(BertNLClassifier* classifier); 55 56 #ifdef __cplusplus 57 } // extern "C" 58 #endif // __cplusplus 59 60 #endif // TENSORFLOW_LITE_SUPPORT_CC_TASK_TEXT_NLCLASSIFIER_BERT_NL_CLASSIFIER_C_API_H_ 61