Skip to contents

Condense longer text into a shorter summary using a summarization model via the Hugging Face Inference Providers API. Accepts a character vector and returns one row per input, composing naturally with dplyr pipelines.

Usage

hf_summarize(
  text,
  model = hf_default_model("summarize"),
  min_length = NULL,
  max_length = NULL,
  token = NULL,
  endpoint_url = NULL,
  ...
)

Arguments

text

Character vector of text(s) to summarize.

model

Character string. Model ID from the Hugging Face Hub. Append `":provider"` to select an inference provider. Default: "facebook/bart-large-cnn".

min_length

Integer or NULL. Minimum length of the summary in tokens. Default: NULL (model default).

max_length

Integer or NULL. Maximum length of the summary in tokens. Default: NULL (model default).

token

Character string or NULL. API token for authentication.

endpoint_url

Character string or NULL. A custom Inference Endpoint URL. When provided, requests are sent to this URL instead of the public Inference API.

...

Additional arguments (currently unused).

Value

A tibble with columns: text, summary.

Examples

if (FALSE) { # \dontrun{
hf_summarize("Long article text goes here ...", max_length = 60)

library(dplyr)
articles |>
  mutate(tldr = hf_summarize(body)$summary)
} # }