Skip to contents

Answer a question from a supplied context passage using an extractive question-answering model via the Hugging Face Inference Providers API. The answer is a span extracted verbatim from the context. `question` and `context` are recycled to a common length (each may be length 1).

Usage

hf_question_answer(
  question,
  context,
  model = hf_default_model("question_answer"),
  token = NULL,
  endpoint_url = NULL,
  ...
)

Arguments

question

Character vector of question(s).

context

Character vector of context passage(s) to answer from.

model

Character string. Model ID from the Hugging Face Hub. Append `":provider"` to select an inference provider. Default: "deepset/roberta-base-squad2".

token

Character string or NULL. API token for authentication.

endpoint_url

Character string or NULL. A custom Inference Endpoint URL.

...

Additional arguments (currently unused).

Value

A tibble with columns: question, answer, score, start, end.

Examples

if (FALSE) { # \dontrun{
hf_question_answer(
  question = "Where was Obama born?",
  context = "Barack Obama was born in Honolulu, Hawaii."
)

# One context, several questions
hf_question_answer(
  question = c("Who?", "Where?"),
  context = "Ada Lovelace worked in London."
)
} # }