The Task Library BertQuestionAnswerer API loads a Bert model and answers
questions based on the content of a given passage. For more information, see the
example for the Question-Answer
model.
Key features of the BertQuestionAnswerer API
Takes two text inputs as question and context and outputs a list of possible answers.
Performs out-of-graph Wordpiece or Sentencepiece tokenizations on input text.
Supported BertQuestionAnswerer models
The following models are compatible with the BertNLClassifier API.
Models created by TensorFlow Lite Model Maker for BERT Question Answer.
Custom models that meet the model compatibility requirements.
Run inference in Java
Step 1: Import Gradle dependency and other settings
Copy the .tflite model file to the assets directory of the Android module
where the model will be run. Specify that the file should not be compressed, and
add the TensorFlow Lite library to the module’s build.gradle file:
android {
// Other settings
// Specify tflite file should not be compressed for the app apk
aaptOptions {
noCompress "tflite"
}
}
dependencies {
// Other dependencies
// Import the Task Text Library dependency
implementation 'org.tensorflow:tensorflow-lite-task-text:0.4.4'
}
Step 2: Run inference using the API
// Initialization
BertQuestionAnswererOptions options =
BertQuestionAnswererOptions.builder()
.setBaseOptions(BaseOptions.builder().setNumThreads(4).build