How to use encode_plus to force padding to specific length
I am using the following code in the __getitem__() method of my dataset:

`    

    class MyDataset(Dataset):
        def __init__(self, myargs):

            #other code here
            self.tokenizer = BertTokenizer.from_pretrained('bert-base-cased)
            self.max_len =50

`

__getitem__ method:

`    

        def __getitem__(self, idx):
           #other code here
           text_encoded = self.tokenizer.encode_plus(
              text,
              add_special_tokens=True,
              padding=True,
              truncation=True,
              max_length=self.max_len,
              return_token_type_ids=False,
              pad_to_max_length=True,
              return_attention_mask=True,
              return_tensors='pt',)

        input_ids=text_encoded['input_ids'].flatten()
        attention_mask=text_encoded['attention_mask'].flatten()

    >>input_ids: torch.Size([9]), attention_mask: torch.Size([9])
    >>input_ids: torch.Size([21]), attention_mask: torch.Size([21])

`

Even though I have set padding and truncation to True and set a max_length the returned lengths of the input_ids and attention_mask values in the retured text_encoded dict are variable depending on the input text. Is this normal behaviour? if so how can I ensure that ecery rturned sample is padded out to and truncated at a specific length?
I worked out that if you set padding=False then the text is padded out correctly with input_ids and attention_mask values of 0. This is the opposite setting of what I thought padding to mean but it works.

'''

     >>input_ids: torch.Size([1, 50]), attention_mask: torch.Size([1, 50]) #pre flatten

```