Error in Question answering comput_metrics

i tried to provide a compute_metrics for Trainer, but an error occurred during training

IndexError                                Traceback (most recent call last)
<ipython-input-59-73000f671fc2> in <cell line: 12>()
     10 )
     11 
---> 12 trainer.train()

12 frames
/usr/local/lib/python3.10/dist-packages/datasets/utils/py_utils.py in <genexpr>(.0)
    324     for key in unique_values(itertools.chain(*dicts)):  # set merge all keys
    325         # Will raise KeyError if the dict don't have the same keys
--> 326         yield key, tuple(d[key] for d in dicts)
    327 
    328 

IndexError: only integers, slices (`:`), ellipsis (`...`), numpy.newaxis (`None`) and integer or boolean arrays are valid indices
from transformers import EvalPrediction
def compute_metrics(p: EvalPrediction):
    metric = evaluate.load( "squad_v2" )
    return metric.compute(predictions=p.predictions, references=p.label_ids)
1 Like