# Fill-mask for BART with variable length

**URL:** <https://discuss.huggingface.co/t/fill-mask-for-bart-with-variable-length/14559>\
**Category:** Models\
**Created:** [February 9, 2022, 6:42pm UTC](https://discuss.huggingface.co/t/fill-mask-for-bart-with-variable-length/14559 "2022-02-09T18:42:24Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![abdallah197](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/abdallah197/32/3973_2.png) [@abdallah197](https://discuss.huggingface.co/u/abdallah197)\
**Post date:** [February 9, 2022, 6:42pm UTC](https://discuss.huggingface.co/t/fill-mask-for-bart-with-variable-length/14559/1 "2022-02-09T18:42:24Z")

</div>

Hey All

i have tried to use BART in the fill-mask pipeline to predict masked tokens, but the output sometimes might be more than one word, and the pipeline does not have an option for that.

In the documentation, I found out this [link](https://huggingface.co/docs/transformers/model_doc/bart#mask-filling) to mask-filling using BART

```auto
from transformers import BartForConditionalGeneration, BartTokenizer

model = BartForConditionalGeneration.from_pretrained("facebook/bart-large", forced_bos_token_id=0)
tok = BartTokenizer.from_pretrained("facebook/bart-large")
example_english_phrase = "UN Chief Says There Is No <mask> in Syria"
batch = tok(example_english_phrase, return_tensors="pt")
generated_ids = model.generate(batch["input_ids"])
assert tok.batch_decode(generated_ids, skip_special_tokens=True) == [
    "UN Chief Says There Is No Plan to Stop Chemical Weapons in Syria"
]

```

My question is, how to use this to obtain the top 5 preditions. in fill-mask pipeline, this would be equivalent to

```auto
unmasker = pipeline("fill-mask", model=model_name, tokenizer=tokenizer, top_k=10)

```

The final output I am hoping to obtain is:

```auto
["plan to stop the war", .. etc another 5 predictions]

```

---

<div class="post-metadata">

**Author:** ![abdallah197](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/abdallah197/32/3973_2.png) [@abdallah197](https://discuss.huggingface.co/u/abdallah197)\
**Post date:** [February 9, 2022, 6:43pm UTC](https://discuss.huggingface.co/t/fill-mask-for-bart-with-variable-length/14559/2 "2022-02-09T18:43:25Z")

</div>

@sgugger would you be able to lend a hand?
