Using huggingface fill-mask pipeline to get more than 5 suggestions

Viewed 4142

The below lets me get 5 suggestions for the masked token, but i'd like to get 10 suggestions - does anyone know if this is possible with hugging face?

!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 <mask> in this sentence")
2 Answers

I would like to add that the parameter was changed to top_k. It can be passed to each individual call of nlp_fill as well as the pipeline method.

Again this is an unfortunate shortcoming of the "under construction" documentation.

If you look closely at the parameters of the FillMaskPipeline (which is what pipeline('fill-mask') constructs, see here), then you will find that it has a topk=5 parameter, which you can simply set to a value of your liking by specifying it in the pipeline constructor:

from transformers import pipeline

nlp_fill = pipeline('fill-mask', topk=10)
Related