View Source TFLiteElixir.MobileBert (tflite_elixir v1.0.0)

Summary

Functions

Load a MobileBERT question-answering model from model_file.

Answer query from content.

Functions

@spec init(String.t()) ::
  {:ok,
   %TFLiteElixir.MobileBert{
     interpreter: term(),
     tensors: term(),
     vocab_map: term()
   }}

Load a MobileBERT question-answering model from model_file.

The vocabulary comes from the model's own vocab.txt, so a model without one is refused by name rather than failing somewhere inside the tokenizer.

{:ok, bert} = TFLiteElixir.MobileBert.init("mobilebert.tflite")
answers = TFLiteElixir.MobileBert.run(bert, query, content)
Link to this function

run(self, query, content)

View Source
@spec run(
  %TFLiteElixir.MobileBert{
    interpreter: term(),
    tensors: term(),
    vocab_map: term()
  },
  String.t(),
  String.t()
) :: [{float(), String.t()}]

Answer query from content.

Returns up to five {score, excerpt} tuples, best first, where each excerpt is a span of content and the scores are a softmax over the spans considered.