human
1.2 Text library
TextLibrary class: text library for training, encoding, batch generation,
and formatted source display. It read some books from Project Gutenberg
and supports creation of training batches. The output functions support
highlighting to allow to compare generated texts with the actual sources
to help to identify identical (memorized) parts of a given length.

Write me a Python program to compare generated texts with the actual sources?
assistant
#Here is Python program to compare generated texts with the actual sources
.
td = Text_Dataset(book_list)

class TextLibraryDataset(torch.utils.data.Dataset):
    def __init__(self, text_dataset, sample_length, torch_device, text_stepping=10):
        self.device=torch_device
        self.text_length=0
        full_text=""
        for text in text_dataset.text_list:
            if 'text' in text:
                full_text += text['text']
        text_encode = text_dataset.encode(full_text)
        self.text_length = len(text_encode)
        self.vocab_size = len(text_dataset.i2c)
        self.text_stepping=text_stepping
        self.sample_length=sample_length
        self.records=int((self.text_length-sample_length-1)/text_stepping)
        self.data=torch.LongTensor(text_encode).to(self.device)
        del text_encode
        del full_text
        
    def __len__(self):
        return self.records

    def __getitem__(self, idx):
        if torch.is_tensor(idx):
            idx = idx.tolist()
        if idx>=self.records:
            return None
        X=self.data[idx*self.text_stepping:idx*self.text_stepping+self.sample_length].to(self.device)
        y=self.data[idx*self.text_stepping+1:idx*self.text_stepping+self.sample_length+1].to(self.device)
        return X,y