Arr = [self.vocab.stoi[x] for x in arr] KeyError: ' were there any transgender clones?'

I’m following this tutorial: Build Your First Text Classification model using PyTorch. but I’m facing this error

Traceback (most recent call last):
  File "C:/Users/BHAAK/Desktop/ML_PATH/dirty-hands/dirty-hands file 3/project_2.py", line 224, in <module>
valid_loss, valid_acc = evaluate(model, valid_iterator, criterion)
  File "C:/Users/BHAAK/Desktop/ML_PATH/dirty-hands/dirty-hands file 3/project_2.py", line 197, in evaluate
for batch in iterator:
  File "C:\Users\BHAAK\AppData\Local\Programs\Python\Python36\lib\site-packages\torchtext\data\iterator.py", line 156, in __iter__
yield Batch(minibatch, self.dataset, self.device)
  File "C:\Users\BHAAK\AppData\Local\Programs\Python\Python36\lib\site-packages\torchtext\data\batch.py", line 34, in __init__
setattr(self, name, field.process(batch, device=device))
  File "C:\Users\BHAAK\AppData\Local\Programs\Python\Python36\lib\site-packages\torchtext\data\field.py", line 237, in process
tensor = self.numericalize(padded, device=device)
  File "C:\Users\BHAAK\AppData\Local\Programs\Python\Python36\lib\site-packages\torchtext\data\field.py", line 338, in numericalize
arr = [self.vocab.stoi[x] for x in arr]
  File "C:\Users\BHAAK\AppData\Local\Programs\Python\Python36\lib\site-packages\torchtext\data\field.py", line 338, in <listcomp>
arr = [self.vocab.stoi[x] for x in arr]
KeyError: ' were there any transgender clones?'

is there any opinions ?

notice that I didn’t change any thing of the tutorial code

the problem was solved by building the vocabulary using the train and val sets

© Copyright 2013-2020 Analytics Vidhya