BertQuestionAnswerer
Stay organized with collections
Save and categorize content based on your preferences.
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".
Inherited Methods
From class
java.lang.Object
boolean
|
|
final
Class<?>
|
getClass()
|
int
|
hashCode()
|
final
void
|
notify()
|
final
void
|
notifyAll()
|
String
|
toString()
|
final
void
|
wait(long arg0, int arg1)
|
final
void
|
wait(long arg0)
|
final
void
|
wait()
|
From interface
java.io.Closeable
From interface
java.lang.AutoCloseable
Public Methods
Answers question based on context, and returns a list of possible QaAnswer
s. Could be
empty if no answer was found from the given context.
Parameters
context |
context the question bases on |
question |
question to ask |
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 |
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 |
public
static
BertQuestionAnswerer
createFromFile
(Context context, String modelPath)
Parameters
context |
android context |
modelPath |
file path to the model with metadata. Note: The model should not be compressed |
Parameters
modelFile |
a File object of the model |
Parameters
modelFile |
a File object of the model |
options |
|
Parameters
context |
android context |
modelPath |
file path to the model with metadata. Note: The model should not be compressed |
options |
|
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2021-10-08 UTC.
[{
"type": "thumb-down",
"id": "missingTheInformationINeed",
"label":"Missing the information I need"
},{
"type": "thumb-down",
"id": "tooComplicatedTooManySteps",
"label":"Too complicated / too many steps"
},{
"type": "thumb-down",
"id": "outOfDate",
"label":"Out of date"
},{
"type": "thumb-down",
"id": "samplesCodeIssue",
"label":"Samples / code issue"
},{
"type": "thumb-down",
"id": "otherDown",
"label":"Other"
}]
[{
"type": "thumb-up",
"id": "easyToUnderstand",
"label":"Easy to understand"
},{
"type": "thumb-up",
"id": "solvedMyProblem",
"label":"Solved my problem"
},{
"type": "thumb-up",
"id": "otherUp",
"label":"Other"
}]