hf_fill_mask: Fill Mask

View source: R/generate.R

hf_fill_maskR Documentation

Fill Mask

Description

Fill in a [MASK] token in text with predicted words. Commonly used with BERT-style models.

Usage

hf_fill_mask(
  text,
  model = hf_default_model("fill_mask"),
  mask_token = "[MASK]",
  top_k = 5,
  token = NULL,
  endpoint_url = NULL,
  ...
)

Arguments

text

Character vector of text(s) containing [MASK] token.

model

Character string. Model ID from Hugging Face Hub. Default: "google-bert/bert-base-uncased".

mask_token

Character string. The mask token to use. Default: "[MASK]". Some models use different tokens like "<mask>".

top_k

Integer. Number of top predictions to return. Default: 5.

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: text, token, score, filled (the complete text)

Examples

## Not run: 
# Fill in the blank
hf_fill_mask("The capital of France is [MASK].")

# Get top predictions
hf_fill_mask("Paris is the [MASK] of France.", top_k = 3)

# Use with different mask token
hf_fill_mask("The capital of France is <mask>.", mask_token = "<mask>")

## End(Not run)

huggingfaceR documentation built on Aug. 30, 2026, 1:06 a.m.