Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
chenpangpang
transformers
Commits
529037fd
Unverified
Commit
529037fd
authored
Nov 16, 2022
by
Nicolas Patry
Committed by
GitHub
Nov 16, 2022
Browse files
Adding doctest for `fill-mask` pipeline. (#20241)
parent
5e080c11
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
0 deletions
+16
-0
src/transformers/pipelines/fill_mask.py
src/transformers/pipelines/fill_mask.py
+16
-0
No files found.
src/transformers/pipelines/fill_mask.py
View file @
529037fd
...
@@ -36,6 +36,22 @@ class FillMaskPipeline(Pipeline):
...
@@ -36,6 +36,22 @@ class FillMaskPipeline(Pipeline):
Masked language modeling prediction pipeline using any `ModelWithLMHead`. See the [masked language modeling
Masked language modeling prediction pipeline using any `ModelWithLMHead`. See the [masked language modeling
examples](../task_summary#masked-language-modeling) for more information.
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.'}]
```
[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:
This mask filling pipeline can currently be loaded from [`pipeline`] using the following task identifier:
`"fill-mask"`.
`"fill-mask"`.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment