Returns the most possible answers on a given question for QA models (BERT, Albert, etc.).
The API expects a Bert based TFLite model with metadata containing the following information:
- input_process_units for Wordpiece/Sentencepiece Tokenizer - Wordpiece Tokenizer can be used for a MobileBert model, Sentencepiece Tokenizer Tokenizer can be used for an Albert model.
- 3 input tensors with names "ids", "mask" and "segment_ids".
- 2 output tensors with names "end_logits" and "start_logits".
Nested Classes
class | BertQuestionAnswerer.BertQuestionAnswererOptions | Options for setting up a BertQuestionAnswerer . |
Public Methods
Inherited Methods
Public Methods
public static BertQuestionAnswerer createAlbertQuestionAnswererFromFile (Context context, String modelPath, String sentencePieceModelPath)
Creates a BertQuestionAnswerer
instance with an Albert model and a sentence piece model
file.
One suitable model is: https://tfhub.dev/tensorflow/lite-model/albert_lite_base/squadv1/1
Parameters
context | android context |
---|---|
modelPath | file path to the Albert model. Note: The model should not be compressed |
sentencePieceModelPath | file path to the sentence piece model file. Note: The model should not be compressed |
Returns
- a
BertQuestionAnswerer
instance
Throws
IOException | If model file fails to load |
---|---|
IllegalArgumentException | if an argument is invalid |
IllegalStateException | if there is an internal error |
RuntimeException | if there is an otherwise unspecified error |
public static BertQuestionAnswerer createBertQuestionAnswererFromFile (Context context, String modelPath, String vocabPath)
Creates a BertQuestionAnswerer
instance with a Bert model and a vocabulary file.
One suitable model is: https://tfhub.dev/tensorflow/lite-model/mobilebert/1/default/1
Parameters
context | android context |
---|---|
modelPath | file path to the Bert model. Note: The model should not be compressed |
vocabPath | file path to the vocabulary file. Note: The file should not be compressed |
Returns
- a
BertQuestionAnswerer
instance
Throws
IOException | If model file fails to load |
---|---|
IllegalArgumentException | if an argument is invalid |
IllegalStateException | if there is an internal error |
RuntimeException | if there is an otherwise unspecified error |
public static BertQuestionAnswerer createFromFile (Context context, String modelPath)
Creates a BertQuestionAnswerer
instance from the default BertQuestionAnswerer.BertQuestionAnswererOptions
.
Parameters
context | android context |
---|---|
modelPath | file path to the model with metadata. Note: The model should not be compressed |
Returns
- a
BertQuestionAnswerer
instance
Throws
IOException | if model file fails to load |
---|---|
IllegalArgumentException | if an argument is invalid |
IllegalStateException | if there is an internal error |
RuntimeException | if there is an otherwise unspecified error |
public static BertQuestionAnswerer createFromFile (File modelFile)
Creates a BertQuestionAnswerer
instance from the default BertQuestionAnswerer.BertQuestionAnswererOptions
.
Parameters
modelFile | a File object of the model |
---|
Returns
- a
BertQuestionAnswerer
instance
Throws
IOException | if model file fails to load |
---|---|
IllegalArgumentException | if an argument is invalid |
IllegalStateException | if there is an internal error |
RuntimeException | if there is an otherwise unspecified error |
public static BertQuestionAnswerer createFromFileAndOptions (File modelFile, BertQuestionAnswerer.BertQuestionAnswererOptions options)
Creates a BertQuestionAnswerer
instance from BertQuestionAnswerer.BertQuestionAnswererOptions
.
Parameters
modelFile | a File object of the model |
---|---|
options |
Returns
- a
BertQuestionAnswerer
instance
Throws
IOException | if model file fails to load |
---|---|
IllegalArgumentException | if an argument is invalid |
IllegalStateException | if there is an internal error |
RuntimeException | if there is an otherwise unspecified error |
public static BertQuestionAnswerer createFromFileAndOptions (Context context, String modelPath, BertQuestionAnswerer.BertQuestionAnswererOptions options)
Creates a BertQuestionAnswerer
instance from BertQuestionAnswerer.BertQuestionAnswererOptions
.
Parameters
context | android context |
---|---|
modelPath | file path to the model with metadata. Note: The model should not be compressed |
options |
Returns
- a
BertQuestionAnswerer
instance
Throws
IOException | if model file fails to load |
---|---|
IllegalArgumentException | if an argument is invalid |
IllegalStateException | if there is an internal error |
RuntimeException | if there is an otherwise unspecified error |