IndexError: string index out of range on TAPAS fine-tuning

I am trying to fine-tune “google/tapas-base” on ‘google/tapas-base-finetuned-wtq’ config. I get the following error.

  File "C:\Users\Kinjal\.conda\envs\nlp\lib\site- packages\transformers\models\tapas\", line 1668, in <listcomp>
return [(coords[1], coords[0]) for coords in answer_coordinates_question]

IndexError: string index out of range

I think the error is because of the coordinates given in the “answer_coordinates” of the TSV sheet. I tried using (row,col) and (col,row) but in both the cases I get the same error. Also, the answer coordinates are within the range of the table i.e. (0 to nrow-1, 0 to ncol-1)

Is there something I am missing here? Or is the error because of something else.


could it be that you’re providing the answer coordinates in the wrong way? You are probably providing the coordinates as a string, but they should be provided as Python tuples.

Let me know if this helps.


Thanks for the reply. I am providing the coordinates as tuples for every answer [(0,1)] like so. But i guess when it does the swapping of rows to columns in the function:

def _to_coordinates(answer_coordinates_question):
return [(coords[1], coords[0]) for coords in answer_coordinates_question]

The [(0,1)] gets passed as a string such as ‘[(0,1)]’ and that’s where the error comes. I don’t know how to remove the ’ ’ from there.

Oh yeah I had that problem too. A solution is to use ast.literal_eval. It let’s you turn strings into their appropriate Python objects.

See also my notebook here, where I used it to turn strings into tuples before fine-tuning TAPAS on SQA: Transformers-Tutorials/Fine_tuning_TapasForQuestionAnswering_on_SQA.ipynb at master · NielsRogge/Transformers-Tutorials · GitHub

1 Like

Thanks. ast.literal_eval solved the problem. Also, the notebook is helpful.

1 Like