# KeyError:664 with Seq2Seq trainer()

**URL:** </static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fkeyerror-664-with-seq2seq-trainer%2F46463%3E%5C
**Category:** Beginners\
**Created:** [July 11, 2023, 5:01pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fkeyerror-664-with-seq2seq-trainer%2F46463 "2023-07-11T17:01:49Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Meltoneous](https://avatars.discourse-cdn.com/v4/letter/m/ea666f/32.png) [@Meltoneous](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2FMeltoneous)%5C
**Post date:** [July 11, 2023, 5:01pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fkeyerror-664-with-seq2seq-trainer%2F46463%2F1 "2023-07-11T17:01:49Z")

</div>

Hello all, I have two columns of data which I have loaded as a df and then dfs for training\_set, testing\_set, and a val\_set. I keep getting the error posted below. I’ve tried resetting indexes, reindexing… Any ideas? Thank you very much!

The code block is:  
training\_args = Seq2SeqTrainingArguments(  
output\_dir=“TESTING”,  
evaluation\_strategy=“epoch”,  
learning\_rate=2e-5,  
per\_device\_train\_batch\_size=16,  
per\_device\_eval\_batch\_size=4,  
weight\_decay=0.01,  
save\_total\_limit=3,  
num\_train\_epochs=2,  
fp16=True,  
predict\_with\_generate=True,

)

trainer = Seq2SeqTrainer(  
model=model,  
args=training\_args,  
train\_dataset=train\_set,  
eval\_dataset=val\_set,  
tokenizer=tokenizer,  
data\_collator=data\_collator,  
compute\_metrics=compute\_metrics  
)

trainer.train()

The error is:

╭─────────────────────────────── 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: 664

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

╭─────────────────────────────── Traceback (most recent call last) ────────────────────────────────╮  
│ in \<cell line: 25\>:25 │  
│ │  
│ /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: 664
