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