Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/transformers/pipelines/fill_mask.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,22 @@ class FillMaskPipeline(Pipeline):
Masked language modeling prediction pipeline using any `ModelWithLMHead`. See the [masked language modeling
examples](../task_summary#masked-language-modeling) for more information.

Example:

```python
>>> from transformers import pipeline

>>> fill_masker = pipeline(model="bert-base-uncased")
>>> potential_words = fill_masker("This is a simple [MASK].")

>>> from transformers.testing_utils import nested_simplify

>>> nested_simplify(potential_words) # The scores might vary slightly across pytorch/tensorflow versions.
[{'score': 0.042, 'token': 3291, 'token_str': 'problem', 'sequence': 'this is a simple problem.'}, {'score': 0.031, 'token': 3160, 'token_str': 'question', 'sequence': 'this is a simple question.'}, {'score': 0.03, 'token': 8522, 'token_str': 'equation', 'sequence': 'this is a simple equation.'}, {'score': 0.027, 'token': 2028, 'token_str': 'one', 'sequence': 'this is a simple one.'}, {'score': 0.024, 'token': 3627, 'token_str': 'rule', 'sequence': 'this is a simple rule.'}]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the doctest will still pas if you use new lines instead of spaces for the result (which would make it more readable).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could not make it work here for some reason... The test would fail because spacing was different... ??!!

It might be because I'm not using assert anymore for output, and the doctest checks for newlines...

```

[Using pipelines in a webserver or with a dataset](../pipeline_tutorial)

This mask filling pipeline can currently be loaded from [`pipeline`] using the following task identifier:
`"fill-mask"`.

Expand Down