create static method

BertQuestionAnswerer create(
  1. String modelPath
)

Generic API to create the QuestionAnswerer for bert models with metadata populated. 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".

Creates BertQuestionAnswerer from modelPath.

modelPath is the path of the .tflite model loaded on device.

throws FileSystemException If model file fails to load.

Implementation

static BertQuestionAnswerer create(String modelPath) {
  final nativePtr = BertQuestionAnswererFromFile(modelPath.toNativeUtf8());
  if (nativePtr == nullptr) {
    throw FileSystemException(
        "Failed to create BertQuestionAnswerer.", modelPath);
  }
  return BertQuestionAnswerer._(nativePtr);
}