Inference Providers documentation
Fill-mask
Get Started
Concepts
Capabilities
Chat CompletionResponses API (beta)Messages APITool CallingStructured OutputsPrompt CachingEmbeddingsText to ImageText to VideoSpeech to Text
Other Tasks
Integrations
Tutorials
Reference
Fill-mask
Mask filling is the task of predicting the right word (token to be precise) in the middle of a sequence.
For more details about the
fill-masktask, check out its dedicated page! You will find examples and related materials.
Recommended models
- FacebookAI/xlm-roberta-base: A multilingual model trained on 100 languages.
Explore all available models and find the one that suits you best here, or from the terminal with the hf CLI:
hf models ls --warm --pipeline-tag fill-mask --sort trending_scoreUsing the API
Language
Client
Provider
Copied
import os
from huggingface_hub import InferenceClient
client = InferenceClient(
provider="hf-inference",
api_key=os.environ["HF_TOKEN"],
)
result = client.fill_mask(
"The answer to the universe is undefined.",
model="google-bert/bert-base-uncased",
)API specification
Request
| Headers | ||
|---|---|---|
| authorization | string | Authentication header in the form 'Bearer: hf_****' when hf_**** is a personal user access token with “Inference Providers” permission. You can generate one from your settings page. |
| Payload | ||
|---|---|---|
| inputs* | string | The text with masked tokens |
| parameters | object | |
| top_k | integer | When passed, overrides the number of predictions to return. |
| targets | string[] | When passed, the model will limit the scores to the passed targets instead of looking up in the whole vocabulary. If the provided targets are not in the model vocab, they will be tokenized and the first resulting token will be used (with a warning, and that might be slower). |
Response
| Body | ||
|---|---|---|
| (array) | object[] | Output is an array of objects. |
| sequence | string | The corresponding input with the mask token prediction. |
| score | number | The corresponding probability |
| token | integer | The predicted token id (to replace the masked one). |
| token_str | string | The predicted token (to replace the masked one). |