class MyDataset(torch.utils.data.Dataset):
    def __init__(self, img2txt):
        """
        img2text :mapping that maps an image file to text file, 
        containing path to your image and text file as a tuple
        """
        self.img2txt = img2txt
    
    def __getitem__(self, idx):
        img_path, txt_path = img2txt[idx]
        # Load image
        # img = ...
        
        # Open text file
        # txt = ...
        
        # Return them as a tuple
        return img, txt
    
dataset = MyDataset(img2txt)
data = torch.utils.data.DataLoader(dataset)

img, txt = next(iter(data))
# You get your img and text