# Getting KeyError: 203 when running trainer.train()

**URL:** </static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fgetting-keyerror-203-when-running-trainer-train%2F46980%3E%5C
**Category:** 🤗Transformers\
**Created:** [July 16, 2023, 10:51am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fgetting-keyerror-203-when-running-trainer-train%2F46980 "2023-07-16T10:51:29Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![sba-h9](https://avatars.discourse-cdn.com/v4/letter/s/b77776/32.png) [@sba-h9](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fsba-h9)%5C
**Post date:** [July 16, 2023, 10:51am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fgetting-keyerror-203-when-running-trainer-train%2F46980%2F1 "2023-07-16T10:51:29Z")

</div>

Hello, I am trying to fine-tune a mT5 based model for reading comprehension task in Farsi.  
whenever I run trainer.train() cell in google colab, I get the follong error:

╭─────────────────────────────── Traceback (most recent call last) ────────────────────────────────╮  
│ /usr/local/lib/python3.10/dist-packages/pandas/core/indexes/base.py:3802 in get\_loc │  
│ │  
│ 3799 │ │ │ │ ) │  
│ 3800 │ │ │ casted\_key = self.\_maybe\_cast\_indexer(key) │  
│ 3801 │ │ │ try: │  
│ ❱ 3802 │ │ │ │ return self.\_engine.get\_loc(casted\_key) │  
│ 3803 │ │ │ except KeyError as err: │  
│ 3804 │ │ │ │ raise KeyError(key) from err │  
│ 3805 │ │ │ except TypeError: │  
│ │  
│ in pandas.\_libs.index.IndexEngine.get\_loc:138 │  
│ │  
│ in pandas.\_libs.index.IndexEngine.get\_loc:165 │  
│ │  
│ in pandas.\_libs.hashtable.PyObjectHashTable.get\_item:5745 │  
│ │  
│ in pandas.\_libs.hashtable.PyObjectHashTable.get\_item:5753 │  
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯  
KeyError: 203

The above exception was the direct cause of the following exception:

╭─────────────────────────────── Traceback (most recent call last) ────────────────────────────────╮  
│ in \<cell line: 1\>:1 │  
│ │  
│ /usr/local/lib/python3.10/dist-packages/transformers/trainer.py:1645 in train │  
│ │  
│ 1642 │ │ inner\_training\_loop = find\_executable\_batch\_size( │  
│ 1643 │ │ │ self.\_inner\_training\_loop, self.\_train\_batch\_size, args.auto\_find\_batch\_size │  
│ 1644 │ │ ) │  
│ ❱ 1645 │ │ return inner\_training\_loop( │  
│ 1646 │ │ │ args=args, │  
│ 1647 │ │ │ resume\_from\_checkpoint=resume\_from\_checkpoint, │  
│ 1648 │ │ │ trial=trial, │  
│ │  
│ /usr/local/lib/python3.10/dist-packages/transformers/trainer.py:1916 in \_inner\_training\_loop │  
│ │  
│ 1913 │ │ │ │ rng\_to\_sync = True │  
│ 1914 │ │ │ │  
│ 1915 │ │ │ step = -1 │  
│ ❱ 1916 │ │ │ for step, inputs in enumerate(epoch\_iterator): │  
│ 1917 │ │ │ │ total\_batched\_samples += 1 │  
│ 1918 │ │ │ │ if rng\_to\_sync: │  
│ 1919 │ │ │ │ │ self.\_load\_rng\_state(resume\_from\_checkpoint) │  
│ │  
│ /usr/local/lib/python3.10/dist-packages/torch/utils/data/dataloader.py:633 in **next** │  
│ │  
│ 630 │ │ │ if self.\_sampler\_iter is None: │  
│ 631 │ │ │ │ # TODO([Bug in dataloader iterator found by mypy · Issue #76750 · pytorch/pytorch · GitHub](https://github.com/pytorch/pytorch/issues/76750)) │  
│ 632 │ │ │ │ self.\_reset() # type: ignore[call-arg] │  
│ ❱ 633 │ │ │ data = self.\_next\_data() │  
│ 634 │ │ │ self.\_num\_yielded += 1 │  
│ 635 │ │ │ if self.\_dataset\_kind == \_DatasetKind.Iterable and \ │  
│ 636 │ │ │ │ │ self.\_IterableDataset\_len\_called is not None and \ │  
│ │  
│ /usr/local/lib/python3.10/dist-packages/torch/utils/data/dataloader.py:677 in \_next\_data │  
│ │  
│ 674 │ │  
│ 675 │ def \_next\_data(self): │  
│ 676 │ │ index = self.\_next\_index() # may raise StopIteration │  
│ ❱ 677 │ │ data = self.\_dataset\_fetcher.fetch(index) # may raise StopIteration │  
│ 678 │ │ if self.\_pin\_memory: │  
│ 679 │ │ │ data = \_utils.pin\_memory.pin\_memory(data, self.\_pin\_memory\_device) │  
│ 680 │ │ return data │  
│ │  
│ /usr/local/lib/python3.10/dist-packages/torch/utils/data/\_utils/fetch.py:51 in fetch │  
│ │  
│ 48 │ │ │ if hasattr(self.dataset, “ **getitems** ”) and self.dataset. **getitems** : │  
│ 49 │ │ │ │ data = self.dataset. **getitems** (possibly\_batched\_index) │  
│ 50 │ │ │ else: │  
│ ❱ 51 │ │ │ │ data = [self.dataset[idx] for idx in possibly\_batched\_index] │  
│ 52 │ │ else: │  
│ 53 │ │ │ data = self.dataset[possibly\_batched\_index] │  
│ 54 │ │ return self.collate\_fn(data) │  
│ │  
│ /usr/local/lib/python3.10/dist-packages/torch/utils/data/\_utils/fetch.py:51 in │  
│ │  
│ 48 │ │ │ if hasattr(self.dataset, “ **getitems** ”) and self.dataset. **getitems** : │  
│ 49 │ │ │ │ data = self.dataset. **getitems** (possibly\_batched\_index) │  
│ 50 │ │ │ else: │  
│ ❱ 51 │ │ │ │ data = [self.dataset[idx] for idx in possibly\_batched\_index] │  
│ 52 │ │ else: │  
│ 53 │ │ │ data = self.dataset[possibly\_batched\_index] │  
│ 54 │ │ return self.collate\_fn(data) │  
│ │  
│ /usr/local/lib/python3.10/dist-packages/pandas/core/frame.py:3807 in **getitem** │  
│ │  
│ 3804 │ │ if is\_single\_key: │  
│ 3805 │ │ │ if self.columns.nlevels \> 1: │  
│ 3806 │ │ │ │ return self.\_getitem\_multilevel(key) │  
│ ❱ 3807 │ │ │ indexer = self.columns.get\_loc(key) │  
│ 3808 │ │ │ if is\_integer(indexer): │  
│ 3809 │ │ │ │ indexer = [indexer] │  
│ 3810 │ │ else: │  
│ │  
│ /usr/local/lib/python3.10/dist-packages/pandas/core/indexes/base.py:3804 in get\_loc │  
│ │  
│ 3801 │ │ │ try: │  
│ 3802 │ │ │ │ return self.\_engine.get\_loc(casted\_key) │  
│ 3803 │ │ │ except KeyError as err: │  
│ ❱ 3804 │ │ │ │ raise KeyError(key) from err │  
│ 3805 │ │ │ except TypeError: │  
│ 3806 │ │ │ │ # If we have a listlike key, \_check\_indexing\_error will raise │  
│ 3807 │ │ │ │ # InvalidIndexError. Otherwise we fall through and re-raise │  
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯  
KeyError: 203

Here it is my code:

# Function that returns an untrained model to be trained

def model\_init():  
return AutoModelForSeq2SeqLM.from\_pretrained(model\_dir)

trainer = Seq2SeqTrainer(  
model\_init=model\_init,  
args=args,  
train\_dataset=train\_df,  
eval\_dataset=eval\_df,  
data\_collator=data\_collator,  
tokenizer=tokenizer,  
compute\_metrics=compute\_metrics  
)

---------------------- the Next Cell ---------------------------------

# Start TensorBoard before training to monitor it in progress

%load\_ext tensorboard  
%tensorboard --logdir “/content/gdrive/MyDrive/parsinlu/runs”

---------------------- the Next Cell ---------------------------------

trainer.train()

I would appreciate if anybody could help me.
