allenai / SciREX

Data/Code Repository for https://api.semanticscholar.org/CorpusID:218470122
Apache License 2.0
129 stars 30 forks source link

KeyError in Predicting End-to-End relations file #17

Open Laxmaan opened 4 years ago

Laxmaan commented 4 years ago

I'm running the prediction script and I'm getting a "metadata" KeyError as shown below

Traceback (most recent call last):  
  File "scirex/predictors/predict_n_ary_relations.py", line 109, in <module>
    predict(argv[1], argv[2], argv[3], argv[4], int(argv[5]))
  File "scirex/predictors/predict_n_ary_relations.py", line 77, in predict  
    output_res = model.decode_relations(batch)   
  File ".../SciREX/scirex/models/scirex_model.py", line 385, in decode_relations   
    res["n_ary_relation"] = self._cluster_n_ary_relation.decode(output_n_ary_relation)  
  File ".../SciREX/scirex/models/relations/entity_relation.py", line 211, in decode  
    "metadata" : output_dict['metadata']  
KeyError: 'metadata'

I went up to the decode function in entity_relation.py, where I replaced output_dict['metadata'] with output_dict.get('metadata',[]) For the batches that do not have any spans.

That led to this error occuring:

Traceback (most recent call last):
  File "scirex/predictors/predict_n_ary_relations.py", line 109, in <module>
    predict(argv[1], argv[2], argv[3], argv[4], int(argv[5]))
  File "scirex/predictors/predict_n_ary_relations.py", line 82, in predict
    metadata = output_res['n_ary_relation']['metadata'][0]
IndexError: list index out of range

Returning a default value of [] did not seem to do the trick. How can I fix it?

successar commented 4 years ago

Hi

Since it it possible after modifications that the output_res['n_ary_relation']['metadata'] is a empty list so you cannot index into it of course. Please try wrapping this portion in try ... except .... block .

jeremyadamsfisher commented 3 years ago

Could you replace metadata = output_res['n_ary_relation']['metadata'][0] with metadata = batch['metadata'][0] to solve this?

successar commented 3 years ago

It is possible although I would suggest making the change in your fork. Right now I am not sure if the change will break anything else so I won't to leave it as it is.

Let me know if it still doesn't work