I’m trying to reproduce your problem but your code sample fails at
wiki_train = random.sample(wiki_train, len(wiki_train)//2)  # list of strings

for me with
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-3-6b563a558a41> in <module>
     50 
     51 tokenizer = BertTokenizer.from_pretrained('bert-base-uncased')
---> 52 wiki_train = random.sample(wiki_train, len(wiki_train)//2)  # list of strings
     53 train_set = LineByLineBertDataset(wiki_train, tokenizer)
     54 

~/.pyenv/versions/3.7.9/lib/python3.7/random.py in sample(self, population, k)
    315             population = tuple(population)
    316         if not isinstance(population, _Sequence):
--> 317             raise TypeError("Population must be a sequence or set.  For dicts, use list(d).")
    318         randbelow = self._randbelow
    319         n = len(population)

TypeError: Population must be a sequence or set.  For dicts, use list(d).