Hey, I am doing a similar task where I need a 3d array of (batch size, no of utterance, tokens).
Since we cannot use 3d array directly, in your case I would do something like-
input_ids = torch.reshape(input_ids, (15, 64))
attention_mask = torch.reshape(attention_mask, (15, 64))

bert_output = model.forward(input_ids=input_ids, attention_mask=attention_mask)
# now you can changethe shape back to original.
bert_output = torch.reshape(bert_output, (3,5,768)) 
#change 768 to 1024 if using bert large model