BertQuestionAnswerer

パブリック クラスBertQuestionAnswerer

QA モデル (BERT、Albert など) の特定の質問に対して可能な限り多くの回答を返します。

API は、次の情報を含むメタデータを含む Bert ベースの TFLite モデルを想定しています。

  • ワードピース/センテンスピース トークナイザーの input_process_units - ワードピース トークナイザーはMobileBertモデルに使用でき、センテンスピース トークナイザー トークナイザーはAlbertモデルに使用できます。
  • 「ids」、「mask」、「segment_ids」という名前を持つ 3 つの入力テンソル。
  • 「end_logits」と「start_logits」という名前の 2 つの出力テンソル。

ネストされたクラス

クラスBertQuestionAnswerer.BertQuestionAnswererOptions BertQuestionAnswererを設定するためのオプション。

パブリックメソッド

一覧< QaAnswer >
回答(文字列コンテキスト、文字列質問)
コンテキストに基づいて質問に回答し、可能なQaAnswerのリストを返します。
静的BertQuestionAnswerer
createAlbertQuestionAnswererFromFile (コンテキスト context、文字列モデルパス、文字列文章ピースモデルパス)
Albert モデルと文章モデル ファイルを使用してBertQuestionAnswererインスタンスを作成します。
静的BertQuestionAnswerer
createBertQuestionAnswererFromFile (Context context、 String modelPath、 String vocabPath)
Bert モデルと語彙ファイルを使用してBertQuestionAnswererインスタンスを作成します。
静的BertQuestionAnswerer
createFromFile (コンテキスト context、文字列モデルパス)
デフォルトのBertQuestionAnswerer.BertQuestionAnswererOptionsからBertQuestionAnswererインスタンスを作成します。
静的BertQuestionAnswerer
createFromFile (ファイルモデルファイル)
デフォルトのBertQuestionAnswerer.BertQuestionAnswererOptionsからBertQuestionAnswererインスタンスを作成します。
静的BertQuestionAnswerer
静的BertQuestionAnswerer
createFromFileAndOptions (コンテキスト コンテキスト、文字列モデルパス、 BertQuestionAnswerer.BertQuestionAnswererOptionsオプション)
BertQuestionAnswerer.BertQuestionAnswererOptionsからBertQuestionAnswererインスタンスを作成します。

継承されたメソッド

パブリックメソッド

public List < QaAnswer >回答(文字列コンテキスト、文字列質問)

コンテキストに基づいて質問に回答し、可能なQaAnswerのリストを返します。指定されたコンテキストから回答が見つからなかった場合は空になる可能性があります。

パラメーター
コンテクスト質問の根拠となるコンテキスト
質問尋ねるべき質問
戻り値
  • QaAnswerで考えられる回答のリスト

public static BertQuestionAnswerer createAlbertQuestionAnswererFromFile (コンテキスト context、文字列モデルパス、文字列文ピースモデルパス)

Albert モデルと文章モデル ファイルを使用してBertQuestionAnswererインスタンスを作成します。

適切なモデルの 1 つは次のとおりです: https://tfhub.dev/tensorflow/lite-model/albert_lite_base/squadv1/1

パラメーター
コンテクストアンドロイドコンテキスト
モデルパスAlbert モデルへのファイル パス。注: モデルは圧縮しないでください。
文ピースモデルパスセンテンスピースモデルファイルへのファイルパス。注: モデルは圧縮しないでください。
戻り値
投げる
IO例外モデルファイルの読み込みに失敗した場合
IllegalArgumentException引数が無効な場合
IllegalStateException内部エラーがある場合
ランタイム例外他に特定されていないエラーがある場合

public static BertQuestionAnswerer createBertQuestionAnswererFromFile (Context context、 String modelPath、 String vocabPath)

Bert モデルと語彙ファイルを使用してBertQuestionAnswererインスタンスを作成します。

適切なモデルの 1 つは次のとおりです: https://tfhub.dev/tensorflow/lite-model/mobilebert/1/default/1

パラメーター
コンテクストアンドロイドコンテキスト
モデルパスBert モデルへのファイル パス。注: モデルは圧縮しないでください。
語彙パス語彙ファイルへのファイルパス。注: ファイルは圧縮しないでください。
戻り値
投げる
IO例外モデルファイルの読み込みに失敗した場合
IllegalArgumentException引数が無効な場合
IllegalStateException内部エラーがある場合
ランタイム例外他に特定されていないエラーがある場合

public static BertQuestionAnswerer createFromFile (Context context, String modelPath)

デフォルトのBertQuestionAnswerer.BertQuestionAnswererOptionsからBertQuestionAnswererインスタンスを作成します。

パラメーター
コンテクストアンドロイドコンテキスト
モデルパスメタデータを含むモデルへのファイル パス。注: モデルは圧縮しないでください。
戻り値
投げる
IO例外モデルファイルのロードに失敗した場合
IllegalArgumentException引数が無効な場合
IllegalStateException内部エラーがある場合
ランタイム例外他に特定されていないエラーがある場合

public static BertQuestionAnswerer createFromFile (ファイルモデルファイル)

デフォルトのBertQuestionAnswerer.BertQuestionAnswererOptionsからBertQuestionAnswererインスタンスを作成します。

パラメーター
モデルファイルモデルのFileオブジェクト
戻り値
投げる
IO例外モデルファイルのロードに失敗した場合
IllegalArgumentException引数が無効な場合
IllegalStateException内部エラーがある場合
ランタイム例外他に特定されていないエラーがある場合

public static BertQuestionAnswerer createFromFileAndOptions (ファイルモデルファイル、 BertQuestionAnswerer.BertQuestionAnswererOptionsオプション)

BertQuestionAnswerer.BertQuestionAnswererOptionsからBertQuestionAnswererインスタンスを作成します。

パラメーター
モデルファイルモデルのFileオブジェクト
オプション
戻り値
投げる
IO例外モデルファイルのロードに失敗した場合
IllegalArgumentException引数が無効な場合
IllegalStateException内部エラーがある場合
ランタイム例外他に特定されていないエラーがある場合

public static BertQuestionAnswerer createFromFileAndOptions (コンテキスト コンテキスト、文字列モデルパス、 BertQuestionAnswerer.BertQuestionAnswererOptionsオプション)

BertQuestionAnswerer.BertQuestionAnswererOptionsからBertQuestionAnswererインスタンスを作成します。

パラメーター
コンテクストアンドロイドコンテキスト
モデルパスメタデータを含むモデルへのファイル パス。注: モデルは圧縮しないでください。
オプション
戻り値
投げる
IO例外モデルファイルのロードに失敗した場合
IllegalArgumentException引数が無効な場合
IllegalStateException内部エラーがある場合
ランタイム例外他に特定されていないエラーがある場合