Why do we need the custom dataset class and use of _getitem_ method in NLP, BERT fine tuning etc
I am a newbie in NLP and has been studying the usage of BERT for NLP tasks. In many notebooks, I See that a custom dataset class is defined and getitem method is defined (along with len).
Tweetdataset class in this notebook - https://www.kaggle.com/abhishek/roberta-inference-5-folds
and text_Dataset class in this notebook - https://engineering.wootric.com/when-bert-meets-pytorch
Can some one please explain the reason, need for defining the custom dataset class and the getitem (and len) method. thank you

It is a recommended abstraction in pytorch to define datasets by inheriting torch.utils.data.Dataset. Those objects define how many elements are there (__len__ method) and how to get a single item via specified index (__getitem__(index)).
Its source code:
class Dataset(object):   
    def __getitem__(self, index):
        raise NotImplementedError

    def __add__(self, other):
        return ConcatDataset([self, other])

So it's basically a thin wrapper which adds possibility to concatenate two Dataset objects. For readability and API compatibility you should inherit from it (unlike the one provided in kaggle).
You can read more about PyTorch's data functionality here
