# Use custom model for mask filling using pipeline

**URL:** </static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fuse-custom-model-for-mask-filling-using-pipeline%2F56641%3E%5C
**Category:** 🤗Transformers\
**Created:** [September 27, 2023, 10:30pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fuse-custom-model-for-mask-filling-using-pipeline%2F56641 "2023-09-27T22:30:54Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![bk073](https://avatars.discourse-cdn.com/v4/letter/b/8491ac/32.png) [@bk073](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fbk073)%5C
**Post date:** [September 27, 2023, 10:30pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fuse-custom-model-for-mask-filling-using-pipeline%2F56641%2F1 "2023-09-27T22:30:54Z")

</div>

I was able to use `pipeline` to **fill-mask task**.  
Example:

```auto
bert_unmask = pipeline('fill-mask', model='bert-base-cased')
bert_unmask("a [MASK] black [MASK] runs along a fence in the grass", top_k=2)

```

Now I wanted to finetune `bert-base-cased` in my dataset and use it in the similar manner like above to fill the mask.

```auto
tokenizer = AutoTokenizer.from_pretrained("bert-base-uncased)
model = AutoModelForSequenceClassification.from_pretrained("bert-base-uncased", num_labels=2)

progress_bar = tqdm(range(num_training_steps))

model.train()
for epoch in range(num_epochs):
  for batch in train_dataloader:
    batch = {k: v.to(device) for k, v in batch.items()}
    outputs = model(**batch)
    loss = outputs.loss
    loss.backward()

    optimizer.step()
    lr_scheduler.step()
    optimizer.zero_grad()
    progress_bar.update(1)

```

Here, I have processed data and make a simple finetuning of the pretrained bert. Now I want to use this finetuned model with `pipeline` to `fill-mask` task.  
I did the following to use this pretrained model:

```auto
pipeline('fill-mask', model=model)

```

but here the fine-tuned model is finetuned for `SequenceClassification` task and now I want to use it for `mask filling` task.

Is it possible to use the model fine-tuned for `Sequence classification` on `masked token filling` using huggingface? Or how can I finetuned pretrained bert based model for masked token filling task?
