how to show pre-labeled relation data?

Hi,

I have some sentences with pre-labeled relations (triples). I was wondering how to show these pre-labeled relations.

I found the expected format in "https://prodi.gy/docs/dependencies-relations" as follows:

{
  "text": "I like cute cats",
  "tokens": [
    {"text": "I", "start": 0, "end": 1, "id": 0},
    {"text": "like", "start": 2, "end": 6, "id": 1},
    {"text": "cute", "start": 7, "end": 11, "id": 2},
    {"text": "cats", "start": 12, "end": 16, "id": 3}
  ],
  "relations": [
    {"child": 0, "head": 1, "label": "nsubj"},
    {"child": 1, "head": 1, "label": "ROOT"},
    {"child": 2, "head": 3, "label": "amod"},
    {"child": 3, "head": 1, "label": "dobj"}
  ]
}

I generated a data structure as follows, which is the same as the expected format.

{"text": "there is no focal scalp swelling or hematoma. ", 
 "tokens": [
    {"text": "there", "start": 0, "end": 5, "id": 1}, 
    {"text": "is", "start": 6, "end": 8, "id": 2}, 
    {"text": "no", "start": 9, "end": 11, "id": 3}, 
    {"text": "focal", "start": 12, "end": 17, "id": 4}, 
    {"text": "scalp", "start": 18, "end": 23, "id": 5}, 
    {"text": "swelling", "start": 24, "end": 32, "id": 6}, 
    {"text": "or", "start": 33, "end": 35, "id": 7}, 
    {"text": "hematoma", "start": 36, "end": 44, "id": 8}, 
    {"text": ".", "start": 44, "end": 45, "id": 9}
 ], 
 "relations": [
    {"child": 1, "head": 2, "label": "dependency"}, 
    {"child": 2, "head": 0, "label": "dependency"}, 
    {"child": 3, "head": 6, "label": "dependency"}, 
    {"child": 4, "head": 6, "label": "dependency"}, 
    {"child": 5, "head": 6, "label": "dependency"}, 
    {"child": 6, "head": 2, "label": "dependency"}, 
    {"child": 7, "head": 8, "label": "dependency"}, 
    {"child": 8, "head": 6, "label": "dependency"}, 
    {"child": 9, "head": 2, "label": "dependency"}
 ]
}

I used the following codes to generate jsonl files

with open(path2, 'w') as outfile:
json.dump(result, outfile)

I loaded the data as follows:

prodigy rel.manual relation_data_v2 en_core_web_sm ./sentence_12.jsonl --label AAA,BBB --wrap

and got errors as follows:

Oops, something went wrong :frowning:
You might have come across a bug in Prodigy's web app – sorry about that. We'd love to fix this, so feel free to open an issue on the Prodigy Support Forum and include the steps that led to this message.

Could you please give me some suggestions?

Thanks.

Best

Hi @gwd!

Can you double-check the ids and their references in child and head ? They seem to refer to "head": 0 , but it doesn't exist in any of the ids (the count started from 1 ).

By the way, I went ahead and edited the file, this sample works:

{"text": "there is no focal scalp swelling or hematoma. ", 
 "tokens": [
    {"text": "there", "start": 0, "end": 5, "id": 0}, 
    {"text": "is", "start": 6, "end": 8, "id": 1}, 
    {"text": "no", "start": 9, "end": 11, "id": 2}, 
    {"text": "focal", "start": 12, "end": 17, "id": 3}, 
    {"text": "scalp", "start": 18, "end": 23, "id": 4}, 
    {"text": "swelling", "start": 24, "end": 32, "id": 5}, 
    {"text": "or", "start": 33, "end": 35, "id": 6}, 
    {"text": "hematoma", "start": 36, "end": 44, "id": 7}, 
    {"text": ".", "start": 44, "end": 45, "id": 8}
 ], 
 "relations": [
    {"child": 0, "head": 2, "label": "dependency"}, 
    {"child": 1, "head": 0, "label": "dependency"}, 
    {"child": 2, "head": 6, "label": "dependency"}, 
    {"child": 3, "head": 6, "label": "dependency"}, 
    {"child": 4, "head": 6, "label": "dependency"}, 
    {"child": 5, "head": 2, "label": "dependency"}, 
    {"child": 6, "head": 8, "label": "dependency"}, 
    {"child": 7, "head": 6, "label": "dependency"}, 
    {"child": 8, "head": 2, "label": "dependency"}
 ]
}

Notice how I replaced the ids from 0 to 9, same with the child values. Of course, this depends on what your use-case would be, but just be careful on referencing non-existent indices :slight_smile:

1 Like