<p dir="auto">At the moment you can use hugging face's mask filling pipeline to predict 1 masked token in a sentence using the below:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="!pip install -q transformers
from __future__ import print_function
import ipywidgets as widgets
from transformers import pipeline

nlp_fill = pipeline('fill-mask')
nlp_fill(&quot;I am going to guess &lt;mask&gt; in this sentence&quot;)"><pre class="notranslate"><code class="notranslate">!pip install -q transformers
from __future__ import print_function
import ipywidgets as widgets
from transformers import pipeline

nlp_fill = pipeline('fill-mask')
nlp_fill("I am going to guess &lt;mask&gt; in this sentence")
</code></pre></div>
<p dir="auto">The request is that you also add the ability to predict N masked tokens rather than only 1 masked token.  So that for example if the sentence is <code class="notranslate">"I am going to make &lt;mask&gt; &lt;mask&gt; for breakfast"</code> then the model might predict "fried eggs" for the 2 masked tokens</p>
<p dir="auto">I am able to use hugging face's mask filling pipeline to predict 1 masked token in a sentence using the below:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="!pip install -q transformers
from __future__ import print_function
import ipywidgets as widgets
from transformers import pipeline

nlp_fill = pipeline('fill-mask')
nlp_fill(&quot;I am going to guess &lt;mask&gt; in this sentence&quot;)"><pre class="notranslate"><code class="notranslate">!pip install -q transformers
from __future__ import print_function
import ipywidgets as widgets
from transformers import pipeline

nlp_fill = pipeline('fill-mask')
nlp_fill("I am going to guess &lt;mask&gt; in this sentence")
</code></pre></div>
<p dir="auto">But does anyone have an opinion on what is the best way to do this if I want to predict 2 masked tokens? e.g. if the sentence is instead <code class="notranslate">"I am going to &lt;mask&gt; &lt;mask&gt; in this sentence"</code>?</p>
<p dir="auto">If i try and put this exact sentence into nlp_fill I get the error "ValueError: only one element tensors can be converted to Python scalars" so it doesn't work automatically.</p>
<p dir="auto">Any help would be much appreciated!</p>
<p dir="auto">Stack overflow question <a href="https://stackoverflow.com/questions/60990897/best-way-of-using-hugging-faces-mask-filling-for-more-than-1-masked-token-at-a" rel="nofollow">link</a></p>