• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #import <Foundation/Foundation.h>
16 
17 NS_ASSUME_NONNULL_BEGIN
18 
19 /**
20  * Classifier API for NLClassification tasks with Bert models, categorizes string into different
21  * classes. The API expects a Bert based TFLite model with metadata populated.
22  *
23  * The metadata should contain the following information:
24  *   1 input_process_unit for Wordpiece/Sentencepiece Tokenizer.
25  *   3 input tensors with names "ids", "mask" and "segment_ids".
26  *   1 output tensor of type float32[1, 2], with a optionally attached label file. If a label
27  *     file is attached, the file should be a plain text file with one label per line, the number
28  *     of labels should match the number of categories the model outputs.
29  */
30 @interface TFLBertNLClassifier : NSObject
31 
32 /**
33  * Creates TFLBertNLClassifier from a model file.
34  *
35  * @param modelPath Path to the classification model.
36  * @return A TFLBertNLClassifier instance.
37  */
38 + (instancetype)bertNLClassifierWithModelPath:(NSString *)modelPath
39     NS_SWIFT_NAME(bertNLClassifier(modelPath:));
40 
41 /**
42  * Performs classification on a NSString input, returns <NSString *, NSNumber *>
43  * for categories and socres.
44  *
45  * @param text input text to the model.
46  * @return A NSDictionary of categorization results.
47  */
48 - (NSDictionary<NSString *, NSNumber *> *)classifyWithText:(NSString *)text
49     NS_SWIFT_NAME(classify(text:));
50 @end
51 NS_ASSUME_NONNULL_END
52