# BertForNextSentencePrediction with larger batch size

**URL:** </static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fbertfornextsentenceprediction-with-larger-batch-size%2F6219%3E%5C
**Category:** Beginners\
**Created:** [May 17, 2021, 8:33pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fbertfornextsentenceprediction-with-larger-batch-size%2F6219 "2021-05-17T20:33:27Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![DLiebman](https://avatars.discourse-cdn.com/v4/letter/d/e9c0ed/32.png) [@DLiebman](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2FDLiebman)%5C
**Post date:** [May 17, 2021, 8:33pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fbertfornextsentenceprediction-with-larger-batch-size%2F6219%2F1 "2021-05-17T20:33:27Z")

</div>

Is there a way to use BertForNextSentencePrediction in inference mode with a batch size larger than 1? I have some code.

```
encoding = self.tokenizer(prompt1, prompt2, return_tensors='pt', padding=True, truncation=True, add_special_tokens=True)
print(encoding)
outputs = self.model(**encoding, next_sentence_label=torch.LongTensor([1]), target_batch_size=10)
logits = outputs.logits
#print(logits)

```

Here prompt1 and prompt2 are lists of sentences. The list is 10 sentences long. I get an error like this:

> ValueError: Expected input batch\_size (10) to match target batch\_size (1).

---

<div class="post-metadata">

**Author:** ![lewtun](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/lewtun/32/30995_2.png) [@lewtun](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Flewtun)%5C
**Post date:** [May 18, 2021, 1:22pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fbertfornextsentenceprediction-with-larger-batch-size%2F6219%2F2 "2021-05-18T13:22:17Z")

</div>

hey @DLiebman i think the problem is that you’re passing a batch of 10 examples, but only a single label in the `next_sentence_label` argument. changing your code to the following works for me:

```auto
outputs = model(**encoding, next_sentence_label=torch.ones((10,1), dtype=torch.long), target_batch_size=10)

```

---

<div class="post-metadata">

**Author:** ![DLiebman](https://avatars.discourse-cdn.com/v4/letter/d/e9c0ed/32.png) [@DLiebman](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2FDLiebman)%5C
**Post date:** [May 18, 2021, 3:46pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fbertfornextsentenceprediction-with-larger-batch-size%2F6219%2F3 "2021-05-18T15:46:10Z")

</div>

yep. something like that will work. thanks.
