You can convert your custom dataset if its a dataframe into Hugging Face format using this.
from datasets import Dataset, load_metric

train_data = Dataset.from_pandas(train_df)
test_data = Dataset.from_pandas(test_df)

If you are facing memory related problem, set num_proc = 1
It solved my problem.